vllm.reasoning.hy_v4_reasoning_parser ¶
Classes:
-
HYV4ReasoningExtractor–Reasoning extraction for HYV4, on plain data.
-
HYV4ReasoningParser–vLLM adapter around :class:
HYV4ReasoningExtractor. -
ReasoningDelta–One streaming reasoning delta. Either/both fields may be None.
Functions:
-
detect_token_suffix–Detect the per-checkpoint suffix used by Hunyuan structural tokens.
HYV4ReasoningExtractor ¶
Reasoning extraction for HYV4, on plain data.
thinking selects the mode: - True: parse <think>...</think>; the start token is injected at the end of the prompt and is therefore usually absent from the output. - False: no_think -- the whole output is content, no reasoning.
Methods:
-
count_reasoning_tokens–Count reasoning tokens (0 in no_think).
-
extract_content_ids–Return the token ids after
</think>(all of them in no_think). -
extract_reasoning–Split a complete output into
(reasoning, content). -
extract_reasoning_streaming–Classify a streaming delta as reasoning and/or content.
-
has_reasoning_ended–Idempotent STATE query: has
</think>been emitted yet? -
reasoning_ended_in_delta–Edge detector (NOT idempotent): did reasoning end in this step?
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
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 187 188 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 | |
count_reasoning_tokens(token_ids) ¶
Count reasoning tokens (0 in no_think).
The <think> start token is injected at the END of the prompt, so it is normally absent from token_ids. Only skip a leading start token when it actually appears first (legacy / no prompt-injection); otherwise count every token up to </think>.
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
extract_content_ids(input_ids) ¶
Return the token ids after </think> (all of them in no_think).
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
extract_reasoning(model_output) ¶
Split a complete output into (reasoning, content).
In no_think mode reasoning is None and the whole output is content. The start token may be absent (injected in the prompt), so reasoning is assumed to begin at the start of the output.
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
extract_reasoning_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids) ¶
Classify a streaming delta as reasoning and/or content.
In no_think mode every delta is content. Otherwise: same logic as vLLM's generic thinking parser, except the final branch (no start token seen anywhere) treats output as reasoning-then-content, because HYV4 injects <think> in the prompt (absent from the output).
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
has_reasoning_ended(token_ids) ¶
Idempotent STATE query: has </think> been emitted yet?
Monotonic -- once the end token is present this stays True. Use for "has reasoning finished, given everything so far". (no_think is always ended.) Contrast with reasoning_ended_in_delta (edge detector).
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
reasoning_ended_in_delta(token_ids, delta_ids) ¶
Edge detector (NOT idempotent): did reasoning end in this step?
True only on the step whose delta_ids contains </think>. Callers use it once behind their own "already ended" latch, so it need not be monotonic; it only checks the new delta (cheaper than scanning the whole sequence). Contrast with has_reasoning_ended (cumulative state).
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
HYV4ReasoningParser ¶
Bases: ReasoningParser
vLLM adapter around :class:HYV4ReasoningExtractor.
Decides thinking from the request's reasoning_effort and converts the extractor's ReasoningDelta to DeltaMessage.
Source code in vllm/reasoning/hy_v4_reasoning_parser.py
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 | |
ReasoningDelta ¶
detect_token_suffix(tokenizer) ¶
Detect the per-checkpoint suffix used by Hunyuan structural tokens.
Parameters:
-
(tokenizer¶TokenizerLike) –Tokenizer of the served checkpoint.
Returns:
-
str–The suffix including its leading colon (e.g.
":6124c78e"), or"" -
str–when the checkpoint uses unsuffixed tokens.
Raises:
-
RuntimeError–The tokenizer declares the structural tokens through
model_specific_special_tokens, which transformers 5 no longer round-trips.