vllm.reasoning
¶
Modules:
-
abs_reasoning_parsers– -
basic_parsers– -
beam_reasoning_parser– -
cohere_command_reasoning_parser– -
deepseek_r1_reasoning_parser– -
deepseek_v3_reasoning_parser– -
ernie45_reasoning_parser– -
gemma4_utils–Gemma4 thinking/reasoning output parsing utilities for offline inference.
-
gptoss_reasoning_parser– -
granite_reasoning_parser– -
hunyuan_a13b_reasoning_parser– -
hy_v3_reasoning_parser– -
hy_v4_reasoning_parser– -
identity_reasoning_parser– -
k2_horizon_reasoning_parser– -
kimi_k3_reasoning_parser–Reasoning parser for the Kimi K3 (XTML) chat format.
-
minimax_m2_reasoning_parser– -
minimax_m3_reasoning_parser– -
muse_glimmer_reasoning_parser–Compatibility entry point for the Muse Glimmer reasoning parser.
-
muse_reasoning_parser–Reasoning-content parser for Muse.
-
olmo3_reasoning_parser– -
poolside_v1_reasoning_parser–Laguna reasoning parser.
-
response_template_reasoning_parser– -
step3_reasoning_parser–
Classes:
-
ReasoningParser–Abstract reasoning parser class that should not be used directly.
-
ReasoningParserManager–Central registry for ReasoningParser implementations.
__all__ = ['ReasoningParser', 'ReasoningParserManager']
module-attribute
¶
Register a lazy module mapping.
Example
ReasoningParserManager.register_lazy_module( name="qwen3", module_path="vllm.reasoning.qwen3_engine_reasoning_parser", class_name="Qwen3ParserReasoningAdapter", )
ReasoningParser
¶
Abstract reasoning parser class that should not be used directly. Provided and methods should be used in derived classes.
It is used to extract reasoning content from the model output.
Methods:
-
adjust_initial_state_from_prompt–Hook called once at the start of streaming with the prompt tokens.
-
adjust_request–Adjust request parameters; override in subclasses as needed.
-
count_reasoning_tokens–Count the number of reasoning tokens in a sequence.
-
extract_content_ids–Extract content token ids from the input_ids.
-
extract_reasoning–Extract reasoning content from a complete model-generated string.
-
extract_reasoning_streaming–Instance method that should be implemented for extracting reasoning
-
find_reasoning_end–Find the first reasoning end in
token_ids. -
has_engine_confirmed_reasoning_end–Whether the engine has confirmed the reasoning end transition.
-
is_reasoning_end–Check if the reasoning content ends in the input_ids.
-
is_reasoning_end_streaming–Check if the reasoning content ends in the input_ids on a
-
prepare_structured_tag–Instance method that is implemented for preparing the structured tag
-
set_prompt_token_ids–Provide the rendered prompt before the output is parsed.
Attributes:
-
implicit_reasoning_end_token_ids(frozenset[int]) –Reasoning-end tokens that are also content, e.g. a tool-call start.
-
reasoning_end_str(str | None) –Set
reasoning_end_strto the strings that delimit -
reasoning_end_token_ids(frozenset[int]) –Every token id that alone ends reasoning.
-
reasoning_start_str(str | None) –Set
reasoning_start_strto the strings that delimit
implicit_reasoning_end_token_ids
property
¶
Reasoning-end tokens that are also content, e.g. a tool-call start.
reasoning_end_str
property
¶
Set reasoning_end_str to the strings that delimit
the reasoning block (e.g. ""</seed:think>"" and "</think>").
reasoning_end_token_ids
property
¶
Every token id that alone ends reasoning.
Empty if reasoning can also end in a way that is not a single token.
reasoning_start_str
property
¶
Set reasoning_start_str to the strings that delimit
the reasoning block (e.g. ""<seed:think>"" and "<think>").
adjust_initial_state_from_prompt(prompt_token_ids)
¶
Hook called once at the start of streaming with the prompt tokens.
Gives parsers a chance to adjust their initial parsing state based on the prompt — for example, when the chat template leaves the prompt inside an open reasoning channel and the engine's default initial state would otherwise misclassify the first generated tokens.
Default is a no-op; override in subclasses as needed.
adjust_request(request)
¶
Adjust request parameters; override in subclasses as needed.
count_reasoning_tokens(token_ids)
¶
Count the number of reasoning tokens in a sequence.
Text-based reasoning models typically wrap their chain-of-thought
between special start/end tokens (e.g., <think> ... </think>).
Implementations that support reasoning token counting should override
this method. The default implementation returns 0 so existing
parsers remain unchanged unless they explicitly opt in.
Parameters:
Returns:
-
int(int) –Number of tokens that belong to reasoning content.
extract_content_ids(input_ids)
abstractmethod
¶
extract_reasoning(model_output, request)
abstractmethod
¶
Extract reasoning content from a complete model-generated string.
Used for non-streaming responses where we have the entire model response available before sending to the client.
Parameters:
-
(model_output¶str) –The model-generated string to extract reasoning content from.
-
(request¶ChatCompletionRequest | ResponsesRequest) –The request object that was used to generate the model_output.
Returns:
extract_reasoning_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids)
abstractmethod
¶
Instance method that should be implemented for extracting reasoning from an incomplete response; for use when handling reasoning calls and streaming. Has to be an instance method because it requires state - the current tokens/diffs, but also the information about what has previously been parsed and extracted (see constructor)
find_reasoning_end(token_ids)
¶
Find the first reasoning end in token_ids.
Returns its offset and whether its token is content, or
ReasoningEnd(len(token_ids), False) if there is none. Returns None
if the parser cannot locate reasoning ends by token id.
has_engine_confirmed_reasoning_end()
¶
Whether the engine has confirmed the reasoning end transition.
Engine-based parsers may defer terminal processing when the detokenizer holds back text. This method returns the engine's processed state, not a raw token-ID check.
Only called for parsers with engine_based_streaming = True.
is_reasoning_end(input_ids)
abstractmethod
¶
Check if the reasoning content ends in the input_ids.
It is used in structured engines like xgrammar to check if the
reasoning content ends in the model output.
Parameters:
Returns:
-
bool–True if the reasoning content ends in the input_ids.
is_reasoning_end_streaming(input_ids, delta_ids)
¶
Check if the reasoning content ends in the input_ids on a decode step.
It is used in structured engines like xgrammar to check if the
reasoning content ends in the model output during a decode step.
input_ids the entire model output and delta_ids are the last few
computed tokens of the model output (like during a decode step).
Parameters:
-
(input_ids¶Sequence[int]) –The entire model output.
-
(delta_ids¶Iterable[int]) –The last few computed tokens of the model output at the current decode step.
Returns:
prepare_structured_tag(original_tag, tool_server)
¶
Instance method that is implemented for preparing the structured tag
set_prompt_token_ids(prompt_token_ids)
¶
Provide the rendered prompt before the output is parsed.
Parsers that can tell whether the prompt already closes reasoning (e.g. continue_final_message) use it to classify the output. Default is a no-op; override in subclasses as needed.
ReasoningParserManager
¶
Central registry for ReasoningParser implementations.
Supports two registration modes
- Eager registration via
register_module - Lazy registration via
register_lazy_module
Each reasoning parser must inherit from ReasoningParser.
Methods:
-
get_reasoning_parser–Retrieve a registered or lazily registered ReasoningParser class.
-
import_reasoning_parser–Import a user-defined reasoning parser.
-
list_registered–Return names of all eagerly and lazily registered reasoning parsers.
-
register_lazy_module–Register a lazy module mapping for delayed import.
-
register_module–Register module with the given name or name list. it can be used as a
_load_lazy_parser(name)
classmethod
¶
Import and register a lazily loaded reasoning parser.
_register_module(module, module_name=None, force=True)
classmethod
¶
Register a ReasoningParser class immediately.
get_reasoning_parser(name)
classmethod
¶
Retrieve a registered or lazily registered ReasoningParser class.
If the parser is lazily registered, it will be imported and cached on first access.
Raises:
-
KeyError–if no parser is found under the given name.
import_reasoning_parser(plugin_path)
classmethod
¶
Import a user-defined reasoning parser.
list_registered()
classmethod
¶
Return names of all eagerly and lazily registered reasoning parsers.
register_lazy_module(name, module_path, class_name)
classmethod
¶
Register a lazy module mapping for delayed import.
Example
ReasoningParserManager.register_lazy_module( name="qwen3", module_path="vllm.reasoning.qwen3_engine_reasoning_parser", class_name="Qwen3ParserReasoningAdapter", )
register_module(name=None, force=True, module=None)
classmethod
¶
Register module with the given name or name list. it can be used as a decoder(with module as None) or normal function(with module as not None).