vllm_mlx.constrained.thinking_processor¶
Thinking-aware logits processor for reasoning models.
View the complete module source at #L1-L287.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.constrained.thinking_processor
¶
Thinking-aware logits processor for reasoning models.
Manages the full thinking lifecycle: budget enforcement, phase transitions, and content-phase constrained decoding delegation.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher
¶
Detect a target token sequence in a stream using a rolling suffix buffer.
Unlike a naive sequential matcher that resets to position 0 on mismatch, this uses a bounded buffer that catches overlapping prefixes.
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.__slots__
class-attribute
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.target
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher._max_len
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher._buf
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.feed
¶
Feed one token. Returns True when the buffer suffix equals the target.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.reset
¶
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.snapshot
¶
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.restore
¶
vllm_mlx.constrained.thinking_processor.Phase
¶
Bases: Enum
Thinking lifecycle phases.
vllm_mlx.constrained.thinking_processor.Phase.IDLE
class-attribute
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.Phase.THINKING
class-attribute
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.Phase.TRANSITIONING
class-attribute
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.Phase.CONTENT
class-attribute
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor
¶
ThinkingAwareLogitsProcessor(start_token_ids: list[int], end_token_ids: list[int], thinking_token_budget: int, inner: Callable[[array, array], array] | None = None, vocab_size: int = 152064, prompt_has_think_tag: bool = False, no_final_content_token_limit: int | None = None)
Unified logits processor for thinking-model lifecycle management.
Manages a four-phase state machine
IDLE -> THINKING -> TRANSITIONING -> CONTENT
- IDLE: before reasoning start tokens. Pass through.
- THINKING: inside reasoning span. Count tokens, pass through.
- TRANSITIONING: forcing reasoning end sequence via logits masking.
- CONTENT: after reasoning closed. Delegate to inner processor.
No re-entry into THINKING after CONTENT is reached.
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.__slots__
class-attribute
instance-attribute
¶
__slots__ = ('_start_matcher', '_end_matcher', '_end_token_ids', '_content_phase_mask_ids', '_thinking_token_budget', '_inner', '_vocab_size', '_state', '_thinking_tokens', '_transition_index', '_processed_len', '_processed_token_ids', '_snapshots', 'watchdog_was_enforced', '_no_final_content_token_limit')
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._start_matcher
instance-attribute
¶
_start_matcher = BoundedSuffixMatcher(start_token_ids)
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._end_matcher
instance-attribute
¶
_end_matcher = BoundedSuffixMatcher(end_token_ids)
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._end_token_ids
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._content_phase_mask_ids
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._thinking_token_budget
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._inner
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._vocab_size
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._thinking_tokens
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._transition_index
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.watchdog_was_enforced
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._no_final_content_token_limit
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._state
instance-attribute
¶
_state = Phase.TRANSITIONING
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._processed_len
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._processed_token_ids
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._snapshots
instance-attribute
¶
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.state
property
¶
state: Phase
Return the current reasoning lifecycle phase.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.thinking_tokens
property
¶
Return the number of generated tokens counted as reasoning.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.is_retired
property
¶
True when the processor is in CONTENT with no inner constraint.
The engine can use this signal to drop the processor and re-enable MTP for the remaining content generation (Phase 2 optimization).
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.__call__
¶
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._force_transition
¶
Force the next token in the reasoning end sequence.
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._call_inner
¶
Delegate to inner processor if present.
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens
¶
Prevent reserved think-tag starts from leaking into final content.
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._snapshot_state
¶
_snapshot_state() -> tuple[Phase, int, int, tuple[int, ...], tuple[int, ...], bool]
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._restore_snapshot
¶
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._sync_to_tokens
¶
Source code in vllm_mlx/constrained/thinking_processor.py
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._advance_with_token
¶
Source code in vllm_mlx/constrained/thinking_processor.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher · class
Detect a target token sequence in a stream using a rolling suffix buffer.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
target_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher
Exceptions and behavior
Class BoundedSuffixMatcher declares 5 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.__init__ · method
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.__init__(target_ids: list[int]) -> None
Method BoundedSuffixMatcher.__init__ updates self.target, self._max_len, self._buf; calls ValueError, tuple, len, deque; can raise ValueError.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
target_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method BoundedSuffixMatcher.__init__ updates self.target, self._max_len, self._buf; calls ValueError, tuple, len, deque; can raise ValueError.
Directly raised exceptions: ValueError.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.feed · method
Feed one token.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
token_id |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
len(self._buf) == self._max_len and tuple(self._buf) == self.target
Exceptions and behavior
Method BoundedSuffixMatcher.feed calls self._buf.append, len, tuple; returns len(self._buf) == self._max_len and tuple(self._buf) == self.target.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.reset · method
Clear the buffer.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method BoundedSuffixMatcher.reset calls self._buf.clear.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.snapshot · method
Return a serializable copy of the current suffix buffer.
Parameters
This callable has no explicit inputs.
Returns
- Type:
tuple[int, ...] - Direct return expressions:
tuple(self._buf)
Exceptions and behavior
Method BoundedSuffixMatcher.snapshot calls tuple; returns tuple(self._buf).
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.restore · method
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.restore(state: tuple[int, ...]) -> None
Restore the suffix buffer from a previous snapshot.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
state |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method BoundedSuffixMatcher.restore calls self._buf.clear, self._buf.extend.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.Phase · class
Thinking lifecycle phases.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.constrained.thinking_processor.Phase
Exceptions and behavior
Class Phase derives from enum.Enum and declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor · class
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor(start_token_ids: list[int], end_token_ids: list[int], thinking_token_budget: int, inner: Callable[[mx.array, mx.array], mx.array] | None = None, vocab_size: int = 152064, prompt_has_think_tag: bool = False, no_final_content_token_limit: int | None = None)
Unified logits processor for thinking-model lifecycle management.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
start_token_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
end_token_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
thinking_token_budget |
int |
yes |
none |
Required positional or keyword input. |
inner |
Callable[[mx.array, mx.array], mx.array] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
vocab_size |
int |
no |
152064 |
Optional positional or keyword input; defaults to 152064. |
prompt_has_think_tag |
bool |
no |
False |
Optional positional or keyword input; defaults to False. |
no_final_content_token_limit |
int \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Constructs:
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor
Exceptions and behavior
Class ThinkingAwareLogitsProcessor declares 12 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.__init__ · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.__init__(start_token_ids: list[int], end_token_ids: list[int], thinking_token_budget: int, inner: Callable[[mx.array, mx.array], mx.array] | None = None, vocab_size: int = 152064, prompt_has_think_tag: bool = False, no_final_content_token_limit: int | None = None) -> None
Method ThinkingAwareLogitsProcessor.__init__ updates self._start_matcher, self._end_matcher, self._end_token_ids, self._content_phase_mask_ids; calls BoundedSuffixMatcher, list, tuple, dict.fromkeys.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
start_token_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
end_token_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
thinking_token_budget |
int |
yes |
none |
Required positional or keyword input. |
inner |
Callable[[mx.array, mx.array], mx.array] \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
vocab_size |
int |
no |
152064 |
Optional positional or keyword input; defaults to 152064. |
prompt_has_think_tag |
bool |
no |
False |
Optional positional or keyword input; defaults to False. |
no_final_content_token_limit |
int \| None |
no |
None |
Optional positional or keyword input; defaults to None. |
Returns
- Type:
None
Exceptions and behavior
Method ThinkingAwareLogitsProcessor.__init__ updates self._start_matcher, self._end_matcher, self._end_token_ids, self._content_phase_mask_ids; calls BoundedSuffixMatcher, list, tuple, dict.fromkeys.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.state · method
Return the current reasoning lifecycle phase.
Parameters
This callable has no explicit inputs.
Returns
- Type:
Phase - Direct return expressions:
self._state
Exceptions and behavior
Method ThinkingAwareLogitsProcessor.state returns self._state.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.thinking_tokens · method
Return the number of generated tokens counted as reasoning.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
self._thinking_tokens
Exceptions and behavior
Method ThinkingAwareLogitsProcessor.thinking_tokens returns self._thinking_tokens.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.is_retired · method
True when the processor is in CONTENT with no inner constraint.
Parameters
This callable has no explicit inputs.
Returns
- Type:
bool - Direct return expressions:
self._state == Phase.CONTENT and self._inner is None
Exceptions and behavior
Method ThinkingAwareLogitsProcessor.is_retired returns self._state == Phase.CONTENT and self._inner is None.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.__call__ · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.__call__(tokens: mx.array, logits: mx.array) -> mx.array
Method ThinkingAwareLogitsProcessor.__call__ calls self._force_transition, self._call_inner, self._sync_to_tokens; has 3 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
mx.array |
yes |
none |
Required positional or keyword input. |
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
self._force_transition(logits);self._call_inner(tokens, logits);logits
Exceptions and behavior
Method ThinkingAwareLogitsProcessor.__call__ calls self._force_transition, self._call_inner, self._sync_to_tokens; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._force_transition · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._force_transition(logits: mx.array) -> mx.array
Force the next token in the reasoning end sequence.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
masked
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._force_transition calls mx.full, float; returns masked.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._call_inner · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._call_inner(tokens: mx.array, logits: mx.array) -> mx.array
Delegate to inner processor if present.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
mx.array |
yes |
none |
Required positional or keyword input. |
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
self._mask_content_phase_control_tokens(logits)
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._call_inner calls self._inner, self._mask_content_phase_control_tokens; returns self._mask_content_phase_control_tokens(logits).
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens(logits: mx.array) -> mx.array
Prevent reserved think-tag starts from leaking into final content.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
mx.array - Direct return expressions:
logits
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens calls float; returns logits.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._snapshot_state · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._snapshot_state() -> tuple[Phase, int, int, tuple[int, ...], tuple[int, ...], bool]
Method ThinkingAwareLogitsProcessor._snapshot_state calls self._start_matcher.snapshot, self._end_matcher.snapshot; returns (self._state, self._thinking_tokens, self._transition_index, self._start_matcher.snapshot(), self._end_matcher.snapshot….
Parameters
This callable has no explicit inputs.
Returns
- Type:
tuple[Phase, int, int, tuple[int, ...], tuple[int, ...], bool] - Direct return expressions:
(self._state, self._thinking_tokens, self._transition_index, self._start_matcher.snapshot(), self._end_matcher.snapshot…
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._snapshot_state calls self._start_matcher.snapshot, self._end_matcher.snapshot; returns (self._state, self._thinking_tokens, self._transition_index, self._start_matcher.snapshot(), self._end_matcher.snapshot….
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._restore_snapshot · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._restore_snapshot(processed_len: int) -> None
Method ThinkingAwareLogitsProcessor._restore_snapshot updates self._state, self._thinking_tokens, self._transition_index, self.watchdog_was_enforced; calls min, len, self._start_matcher.restore, self._end_matcher.restore.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
processed_len |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._restore_snapshot updates self._state, self._thinking_tokens, self._transition_index, self.watchdog_was_enforced; calls min, len, self._start_matcher.restore, self._end_matcher.restore.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._sync_to_tokens · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._sync_to_tokens(tokens: mx.array) -> None
Method ThinkingAwareLogitsProcessor._sync_to_tokens updates self._processed_len; calls int, tokens.tolist, min, self._restore_snapshot; returns None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
mx.array |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._sync_to_tokens updates self._processed_len; calls int, tokens.tolist, min, self._restore_snapshot; returns None.
No direct raise statement appears in this definition.
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._advance_with_token · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._advance_with_token(token_id: int) -> None
Method ThinkingAwareLogitsProcessor._advance_with_token updates self._state, self._transition_index, self._thinking_tokens, self.watchdog_was_enforced; calls self._start_matcher.feed, self._end_matcher.feed, len, self._end_matcher.reset; returns None.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
token_id |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method ThinkingAwareLogitsProcessor._advance_with_token updates self._state, self._transition_index, self._thinking_tokens, self.watchdog_was_enforced; calls self._start_matcher.feed, self._end_matcher.feed, len, self._end_matcher.reset; returns None.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
BoundedSuffixMatcher |
class | BoundedSuffixMatcher(target_ids: list[int]) |
Detect a target token sequence in a stream using a rolling suffix buffer. | #L16-L48 |
BoundedSuffixMatcher.__init__ |
method | BoundedSuffixMatcher.__init__(target_ids: list[int]) -> None |
Method BoundedSuffixMatcher.__init__ updates self.target, self._max_len, self._buf; calls ValueError, tuple, len, deque; can raise ValueError. |
#L25-L30 |
BoundedSuffixMatcher.feed |
method | BoundedSuffixMatcher.feed(token_id: int) -> bool |
Feed one token. | #L32-L35 |
BoundedSuffixMatcher.reset |
method | BoundedSuffixMatcher.reset() -> None |
Clear the buffer. | #L37-L39 |
BoundedSuffixMatcher.snapshot |
method | BoundedSuffixMatcher.snapshot() -> tuple[int, ...] |
Return a serializable copy of the current suffix buffer. | #L41-L43 |
BoundedSuffixMatcher.restore |
method | BoundedSuffixMatcher.restore(state: tuple[int, ...]) -> None |
Restore the suffix buffer from a previous snapshot. | #L45-L48 |
Phase |
class | Phase() |
Thinking lifecycle phases. | #L51-L57 |
ThinkingAwareLogitsProcessor |
class | ThinkingAwareLogitsProcessor(start_token_ids: list[int], end_token_ids: list[int], thinking_token_budget: int, inner: Callable[[mx.array, mx.array], mx.array] \| None = None, vocab_size: int = 152064, prompt_has_think_tag: bool = False, no_final_content_token_limit: int \| None = None) |
Unified logits processor for thinking-model lifecycle management. | #L60-L287 |
ThinkingAwareLogitsProcessor.__init__ |
method | ThinkingAwareLogitsProcessor.__init__(start_token_ids: list[int], end_token_ids: list[int], thinking_token_budget: int, inner: Callable[[mx.array, mx.array], mx.array] \| None = None, vocab_size: int = 152064, prompt_has_think_tag: bool = False, no_final_content_token_limit: int \| None = None) -> None |
Method ThinkingAwareLogitsProcessor.__init__ updates self._start_matcher, self._end_matcher, self._end_token_ids, self._content_phase_mask_ids; calls BoundedSuffixMatcher, list, tuple, dict.fromkeys. |
#L92-L129 |
ThinkingAwareLogitsProcessor.state |
method | ThinkingAwareLogitsProcessor.state() -> Phase |
Return the current reasoning lifecycle phase. | #L132-L135 |
ThinkingAwareLogitsProcessor.thinking_tokens |
method | ThinkingAwareLogitsProcessor.thinking_tokens() -> int |
Return the number of generated tokens counted as reasoning. | #L138-L141 |
ThinkingAwareLogitsProcessor.is_retired |
method | ThinkingAwareLogitsProcessor.is_retired() -> bool |
True when the processor is in CONTENT with no inner constraint. | #L144-L150 |
ThinkingAwareLogitsProcessor.__call__ |
method | ThinkingAwareLogitsProcessor.__call__(tokens: mx.array, logits: mx.array) -> mx.array |
Method ThinkingAwareLogitsProcessor.__call__ calls self._force_transition, self._call_inner, self._sync_to_tokens; has 3 explicit return paths. |
#L152-L170 |
ThinkingAwareLogitsProcessor._force_transition |
method | ThinkingAwareLogitsProcessor._force_transition(logits: mx.array) -> mx.array |
Force the next token in the reasoning end sequence. | #L172-L182 |
ThinkingAwareLogitsProcessor._call_inner |
method | ThinkingAwareLogitsProcessor._call_inner(tokens: mx.array, logits: mx.array) -> mx.array |
Delegate to inner processor if present. | #L184-L188 |
ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens |
method | ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens(logits: mx.array) -> mx.array |
Prevent reserved think-tag starts from leaking into final content. | #L190-L197 |
ThinkingAwareLogitsProcessor._snapshot_state |
method | ThinkingAwareLogitsProcessor._snapshot_state() -> tuple[Phase, int, int, tuple[int, ...], tuple[int, ...], bool] |
Method ThinkingAwareLogitsProcessor._snapshot_state calls self._start_matcher.snapshot, self._end_matcher.snapshot; returns (self._state, self._thinking_tokens, self._transition_index, self._start_matcher.snapshot(), self._end_matcher.snapshot…. |
#L199-L209 |
ThinkingAwareLogitsProcessor._restore_snapshot |
method | ThinkingAwareLogitsProcessor._restore_snapshot(processed_len: int) -> None |
Method ThinkingAwareLogitsProcessor._restore_snapshot updates self._state, self._thinking_tokens, self._transition_index, self.watchdog_was_enforced; calls min, len, self._start_matcher.restore, self._end_matcher.restore. |
#L211-L229 |
ThinkingAwareLogitsProcessor._sync_to_tokens |
method | ThinkingAwareLogitsProcessor._sync_to_tokens(tokens: mx.array) -> None |
Method ThinkingAwareLogitsProcessor._sync_to_tokens updates self._processed_len; calls int, tokens.tolist, min, self._restore_snapshot; returns None. |
#L231-L252 |
ThinkingAwareLogitsProcessor._advance_with_token |
method | ThinkingAwareLogitsProcessor._advance_with_token(token_id: int) -> None |
Method ThinkingAwareLogitsProcessor._advance_with_token updates self._state, self._transition_index, self._thinking_tokens, self.watchdog_was_enforced; calls self._start_matcher.feed, self._end_matcher.feed, len, self._end_matcher.reset; returns None. |
#L254-L287 |