NVIDIA/logits-processor-zoo
A collection of LogitsProcessors to customize and enhance LLM behavior for specific tasks.
What it solves
It addresses the difficulty of getting Large Language Models (LLMs) to strictly follow specific formatting or behavioral instructions, moving beyond simple grammar enforcement to provide precise control over what the model generates.
How it works
The library provides a collection of "logits processors" that intercept and modify the probability distribution (logits) of the next token during the generation process. By boosting or diminishing the likelihood of specific tokens, it can force the model to include certain phrases, limit response lengths, or ensure outputs adhere to a specific format.
Who it’s for
Developers using LLM frameworks like transformers, vLLM, or TensorRT-LLM who need deterministic control over model outputs for specialized tasks.
Highlights
- GenLengthLogitsProcessor: Encourages or discourages shorter answers by adjusting the EOS token likelihood.
- CiteFromPromptLogitsProcessor: Boosts tokens present in the prompt to encourage citations or similarity.
- ForceLastPhraseLogitsProcessor: Ensures the model ends its response with a specific phrase, such as a references section.
- MultipleChoiceLogitsProcessor: Constrains the model to answer multiple-choice questions using only the provided options.
- TriggerPhraseLogitsProcessor: Automatically inserts specific phrases (like code blocks) after a trigger token is encountered.
- PreventHallucinationLogitsProcessor: Uses a fallback phrase when token confidence drops below a certain threshold to reduce hallucinations.
- MaxTimeLogitsProcessor: Forces the sequence to end after a maximum time limit, optionally waiting for a natural break like a full stop.
Related
- Dispatch
- Project
- Project
- Project
- Project