vllm.reasoning.olmo3_reasoning_parser ¶
Olmo3ReasoningParser ¶
Bases: ReasoningParser
Reasoning parser for Olmo 3 model
Olmo3ReasoningParser
This class implements a reasoning parser specifically designed for the Olmo 3 family of models. Olmo 3 models do not use special tokens to indicate reasoning; rather, reasoning trace is wrapped in <think> and </think>, which are tokenized using standard vocabulary entries. Because of this, the parser operates in string space, accumulating the characters in a buffer until it sees <think> or </think>. tokens to switch modes.
Key Features
- For non-stream output, Recognizes and extracts reasoning (text bracketed by
<think>and</think>) and content (everything after the first</think>). - For stream process, it uses a buffer to accumulate delta text, and output progressive delta messages as soon as thinking starts or ends.
- For reliability, some Olmo 3 models may hardcode the first
<think>token is the input text (similar to Deepseek R1, or reasoning-only Qwen models). To support such variants, the parser can optionally work in cases where the first<think>token is missing from generation.
Source code in vllm/reasoning/olmo3_reasoning_parser.py
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 | |
extract_reasoning ¶
extract_reasoning(
model_output: str,
request: ChatCompletionRequest | ResponsesRequest,
) -> tuple[str | None, str | None]
Extract the reasoning content & content sections, respectively. If the sequence doesn't match what we expect, i.e., the model generates something else, all content is considered non-reasoning content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output | str | Output of the model to be parsed. | required |
request | ChatCompletionRequest | ResponsesRequest | Request being processed. | required |
Returns:
| Type | Description |
|---|---|
str | None | tuple[Optional[str], Optional[str]]: Tuple pair containing the |
str | None | reasoning content and non-reasoning content. |
Source code in vllm/reasoning/olmo3_reasoning_parser.py
extract_reasoning_streaming ¶
extract_reasoning_streaming(
previous_text: str,
current_text: str,
delta_text: str,
previous_token_ids: Sequence[int],
current_token_ids: Sequence[int],
delta_token_ids: Sequence[int],
) -> DeltaMessage | None
Extract content using token ID sequence state machine
Source code in vllm/reasoning/olmo3_reasoning_parser.py
string_overlap ¶
Find the longest overlap where the end of string a matches the start of string b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a | str | First string | required |
b | str | Second string | required |
Returns:
| Type | Description |
|---|---|
Indices | None | Tuple of IndicesTuples representing the overlapping portions in each |
Indices | None | string, or a tuple of None if no overlap exists |