vllm.reasoning ¶
Modules:
-
abs_reasoning_parsers– -
basic_parsers– -
cohere_command_reasoning_parser– -
deepseek_r1_reasoning_parser– -
deepseek_v3_reasoning_parser– -
ernie45_reasoning_parser– -
gemma4_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– -
identity_reasoning_parser– -
kimi_k2_reasoning_parser– -
minimax_m2_reasoning_parser– -
mistral_reasoning_parser– -
nemotron_v3_reasoning_parser– -
olmo3_reasoning_parser– -
poolside_v1_reasoning_parser–Laguna reasoning parser.
-
qwen3_reasoning_parser– -
seedoss_reasoning_parser– -
step3_reasoning_parser– -
step3p5_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_reasoning_parser", class_name="Qwen3ReasoningParser", )
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_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
-
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
Attributes:
-
reasoning_end_str(str | None) –Set
reasoning_end_strto the strings that delimit -
reasoning_start_str(str | None) –Set
reasoning_start_strto the strings that delimit
Source code in vllm/reasoning/abs_reasoning_parsers.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
reasoning_end_str property ¶
Set reasoning_end_str to the strings that delimit the reasoning block (e.g. ""</seed:think>"" and "</think>").
reasoning_start_str property ¶
Set reasoning_start_str to the strings that delimit the reasoning block (e.g. ""<seed:think>"" and "<think>").
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.
Source code in vllm/reasoning/abs_reasoning_parsers.py
extract_content_ids(input_ids) abstractmethod ¶
Extract content token ids from the input_ids. Parameters: input_ids: list[int] The input_ids of the model output. Returns: list[int] The extracted content from the input_ids.
Source code in vllm/reasoning/abs_reasoning_parsers.py
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:
Source code in vllm/reasoning/abs_reasoning_parsers.py
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)
Source code in vllm/reasoning/abs_reasoning_parsers.py
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.
input_ids: list[int] The input_ids of the model output.
bool True if the reasoning content ends in the input_ids.
Source code in vllm/reasoning/abs_reasoning_parsers.py
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).
input_ids: list[int] The entire model output. delta_ids: list[int] The last few computed tokens of the model output at the current decode step.
bool True if the reasoning content ends in the delta_ids on a decode step.
Source code in vllm/reasoning/abs_reasoning_parsers.py
prepare_structured_tag(original_tag, tool_server) ¶
Instance method that is implemented for preparing the structured tag Otherwise, None is returned
Source code in vllm/reasoning/abs_reasoning_parsers.py
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 by the path
-
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
Source code in vllm/reasoning/abs_reasoning_parsers.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
_load_lazy_parser(name) classmethod ¶
Import and register a lazily loaded reasoning parser.
Source code in vllm/reasoning/abs_reasoning_parsers.py
_register_module(module, module_name=None, force=True) classmethod ¶
Register a ReasoningParser class immediately.
Source code in vllm/reasoning/abs_reasoning_parsers.py
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.
Source code in vllm/reasoning/abs_reasoning_parsers.py
import_reasoning_parser(plugin_path) classmethod ¶
Import a user-defined reasoning parser by the path of the reasoning parser define file.
Source code in vllm/reasoning/abs_reasoning_parsers.py
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.parsers.qwen3_reasoning_parser", class_name="Qwen3ReasoningParser", )
Source code in vllm/reasoning/abs_reasoning_parsers.py
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).