vllm.reasoning.olmo3_reasoning_parser ¶
Indices dataclass
¶
Source code in vllm/reasoning/olmo3_reasoning_parser.py
Olmo3ReasoningBuffer dataclass
¶
Source code in vllm/reasoning/olmo3_reasoning_parser.py
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 187 188 189 190 191 192 |
|
__init__ ¶
__init__(
think_start: str = "<think>",
think_end: str = "</think>",
buffer: str = "",
state: Olmo3ReasoningState = REASONING,
) -> None
__len__ ¶
add_text ¶
add_text(delta_text: str) -> Optional[DeltaMessage]
Source code in vllm/reasoning/olmo3_reasoning_parser.py
process_buffer ¶
process_buffer() -> Optional[DeltaMessage]
Source code in vllm/reasoning/olmo3_reasoning_parser.py
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
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 |
|
buffer instance-attribute
¶
buffer = Olmo3ReasoningBuffer(
think_start=think_start, think_end=think_end
)
__init__ ¶
__init__(tokenizer: AnyTokenizer, *args, **kwargs)
Source code in vllm/reasoning/olmo3_reasoning_parser.py
extract_content_ids ¶
Source code in vllm/reasoning/olmo3_reasoning_parser.py
extract_reasoning_content ¶
extract_reasoning_content(
model_output: str,
request: Union[ChatCompletionRequest, ResponsesRequest],
) -> tuple[Optional[str], Optional[str]]
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 |
---|---|
Optional[str] | tuple[Optional[str], Optional[str]]: Tuple pair containing the |
Optional[str] | reasoning content and non-reasoning content. |
Source code in vllm/reasoning/olmo3_reasoning_parser.py
extract_reasoning_content_streaming ¶
extract_reasoning_content_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],
) -> Union[DeltaMessage, None]
Extract content using token ID sequence state machine
Source code in vllm/reasoning/olmo3_reasoning_parser.py
Olmo3ReasoningState ¶
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 |
---|---|
Optional[Indices] | Tuple of IndicesTuples representing the overlapping portions in each |
Optional[Indices] | string, or a tuple of None if no overlap exists |