nemo_voice_agent.vllm.v1.sample.logits_processor.reasoning_budget_logits_processor
nemo_voice_agent.vllm.v1.sample.logits_processor.reasoning_budget_logits_processor
vLLM V1 LogitsProcessor that enforces a per-request reasoning (thinking) token budget.
Models like Nemotron-Nano use <think>/</think> delimiters (same convention as
DeepSeek-R1). This processor monitors generated tokens, counts those inside the
thinking block, and forces end tokens when the budget is reached.
Per-request parameters (via SamplingParams.extra_args):
thinking_budget (int): Maximum number of thinking tokens allowed before forcing the end sequence. Required to activate the processor for a given request.
thinking_budget_grace_period (int, optional):
Number of tokens before the budget at which \n and end-token
logits start being boosted. Defaults to 10 % of thinking_budget.
think_start_tokens (str, optional):
Text that marks the beginning of a thinking block. The processor
tokenizes this string at request time. Defaults to "<think>".
think_end_tokens (str, optional):
Text to force when the budget is reached. The processor tokenizes
this string at request time. Defaults to "\n</think>". Can be
set to a custom closing such as "Reached thinking limit.\n</think>".
Usage — offline with vllm.LLM::
llm = LLM(model=model, logits_processors=[ReasoningBudgetLogitsProcessor], …) params = SamplingParams( temperature=0.6, max_tokens=256, extra_args={“thinking_budget”: 64}, ) outputs = llm.generate(prompts, params)
Usage — online with vllm serve::
vllm serve <model>
—logits-processors ’[”…/reasoning_budget_logits_processor:ReasoningBudgetLogitsProcessor”]‘
then per-request via the OpenAI client:
extra_body={“vllm_xargs”: {“thinking_budget”: 64}}
Module Contents
Classes
Data
API
Bases: LogitsProcessor
Enforce a per-request thinking-token budget for reasoning models.
The processor tracks thinking-start / thinking-end boundaries in each
request’s output. Once a request’s thinking token count enters the
grace window, \n and end-token logits are boosted. At the hard
limit all logits except the next forced end token are set to -inf.
Additively boost newline and end-token logits.
Encode text without special tokens.
Set all logits to -inf except the next token in the end sequence.
Advances forcing_end_idx each call.
Obtain a tokenizer from the vLLM config.
Called by process_dict_updates for each newly added request.
Return True if prompt_tok_ids ends with pattern, ignoring any trailing tokens whose ID is in skip_ids (e.g. newlines).
Update state by scanning output_tok_ids[from_idx:].
Modify the logits in place to force thinking-budget exits when the limit is reached.
Return whether this processor preserves argmax behavior (it does not).
Sync per-request thinking state with the batch update from vLLM.
Validate thinking-budget-related extra_args on the provided sampling params.
Mutable per-request tracking state.