vllm.reasoning.hy_v4_reasoning_parser
¶
Classes:
-
HYV4ReasoningExtractor–Reasoning extraction for HYV4, on plain data.
-
HYV4ReasoningParser–vLLM adapter around
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 decoded text, retaining incomplete reasoning delimiters.
-
finish_streaming–Release a truncated delimiter as reasoning at the end of a stream.
-
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?
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>.
extract_content_ids(input_ids)
¶
Return the token ids after </think> (all of them in no_think).
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.
extract_reasoning_streaming(previous_text, current_text, delta_text, previous_token_ids, current_token_ids, delta_token_ids)
¶
Classify decoded text, retaining incomplete reasoning delimiters.
Stop-string buffering can delay delimiter text beyond its token ID. Only the complete text closes reasoning; token IDs remain available separately for structured-output checks and the tool-parser handoff.
finish_streaming()
¶
Release a truncated delimiter as reasoning at the end of a stream.
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).
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).
HYV4ReasoningParser
¶
Bases: ReasoningParser
vLLM adapter around HYV4ReasoningExtractor.
Decides thinking from the request's reasoning_effort and converts
the extractor's ReasoningDelta to DeltaMessage. Uses text-confirmed
streaming transitions rather than raw token-ID boundaries.
Methods:
-
adjust_request–Keep reasoning delimiters visible when registered as special tokens.
adjust_request(request)
¶
Keep reasoning delimiters visible when registered as special tokens.
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.