Skip to content

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

BoundedSuffixMatcher(target_ids: list[int])

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
def __init__(self, target_ids: list[int]) -> None:
    if not target_ids:
        raise ValueError("target_ids must be non-empty")
    self.target = tuple(target_ids)
    self._max_len = len(target_ids)
    self._buf: deque[int] = deque(maxlen=self._max_len)

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.__slots__ class-attribute instance-attribute

__slots__ = ('target', '_buf', '_max_len')

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.target instance-attribute

target = tuple(target_ids)

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher._max_len instance-attribute

_max_len = len(target_ids)

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher._buf instance-attribute

_buf: deque[int] = deque(maxlen=self._max_len)

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.feed

feed(token_id: int) -> bool

Feed one token. Returns True when the buffer suffix equals the target.

Source code in vllm_mlx/constrained/thinking_processor.py
def feed(self, token_id: int) -> bool:
    """Feed one token. Returns True when the buffer suffix equals the target."""
    self._buf.append(token_id)
    return len(self._buf) == self._max_len and tuple(self._buf) == self.target

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.reset

reset() -> None

Clear the buffer.

Source code in vllm_mlx/constrained/thinking_processor.py
def reset(self) -> None:
    """Clear the buffer."""
    self._buf.clear()

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.snapshot

snapshot() -> tuple[int, ...]

Return a serializable copy of the current suffix buffer.

Source code in vllm_mlx/constrained/thinking_processor.py
def snapshot(self) -> tuple[int, ...]:
    """Return a serializable copy of the current suffix buffer."""
    return tuple(self._buf)

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.restore

restore(state: tuple[int, ...]) -> None

Restore the suffix buffer from a previous snapshot.

Source code in vllm_mlx/constrained/thinking_processor.py
def restore(self, state: tuple[int, ...]) -> None:
    """Restore the suffix buffer from a previous snapshot."""
    self._buf.clear()
    self._buf.extend(state)

vllm_mlx.constrained.thinking_processor.Phase

Bases: Enum

Thinking lifecycle phases.

vllm_mlx.constrained.thinking_processor.Phase.IDLE class-attribute instance-attribute

IDLE = 'idle'

vllm_mlx.constrained.thinking_processor.Phase.THINKING class-attribute instance-attribute

THINKING = 'thinking'

vllm_mlx.constrained.thinking_processor.Phase.TRANSITIONING class-attribute instance-attribute

TRANSITIONING = 'transitioning'

vllm_mlx.constrained.thinking_processor.Phase.CONTENT class-attribute instance-attribute

CONTENT = 'content'

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
def __init__(
    self,
    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:
    self._start_matcher = BoundedSuffixMatcher(start_token_ids)
    self._end_matcher = BoundedSuffixMatcher(end_token_ids)
    self._end_token_ids = list(end_token_ids)
    # Mask only the first token of each sequence: sufficient because most
    # tokenizers encode <think>/<|think|> as a single special token.
    self._content_phase_mask_ids = tuple(
        dict.fromkeys([start_token_ids[0], end_token_ids[0]])
    )
    self._thinking_token_budget = thinking_token_budget
    self._inner = inner
    self._vocab_size = vocab_size
    self._thinking_tokens = 0
    self._transition_index = 0
    self.watchdog_was_enforced = False
    self._no_final_content_token_limit = no_final_content_token_limit
    # When the chat template already injected <think> into the prompt,
    # the first generated token is already inside the thinking span.
    # Start in THINKING (or TRANSITIONING if budget=0) instead of IDLE.
    if prompt_has_think_tag:
        if thinking_token_budget == 0:
            self._state = Phase.TRANSITIONING
        else:
            self._state = Phase.THINKING
    else:
        self._state = Phase.IDLE
    self._processed_len = 0
    self._processed_token_ids: list[int] = []
    self._snapshots = [self._snapshot_state()]

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

_end_token_ids = list(end_token_ids)

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._content_phase_mask_ids instance-attribute

_content_phase_mask_ids = tuple(dict.fromkeys([start_token_ids[0], end_token_ids[0]]))

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._thinking_token_budget instance-attribute

_thinking_token_budget = thinking_token_budget

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._inner instance-attribute

_inner = inner

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._vocab_size instance-attribute

_vocab_size = vocab_size

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._thinking_tokens instance-attribute

_thinking_tokens = 0

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._transition_index instance-attribute

_transition_index = 0

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.watchdog_was_enforced instance-attribute

watchdog_was_enforced = False

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._no_final_content_token_limit instance-attribute

_no_final_content_token_limit = no_final_content_token_limit

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._state instance-attribute

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._processed_len instance-attribute

_processed_len = 0

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._processed_token_ids instance-attribute

_processed_token_ids: list[int] = []

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._snapshots instance-attribute

_snapshots = [self._snapshot_state()]

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

thinking_tokens: int

Return the number of generated tokens counted as reasoning.

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.is_retired property

is_retired: bool

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__

__call__(tokens: array, logits: array) -> array
Source code in vllm_mlx/constrained/thinking_processor.py
def __call__(self, tokens: mx.array, logits: mx.array) -> mx.array:
    # The MLLM scheduler applies processors before the first completion
    # token is emitted, so ``tokens`` can be empty on step 0.
    if tokens.size == 0:
        if self._state == Phase.TRANSITIONING:
            return self._force_transition(logits)
        if self._state == Phase.CONTENT:
            return self._call_inner(tokens, logits)
        return logits

    self._sync_to_tokens(tokens)

    if self._state == Phase.TRANSITIONING:
        return self._force_transition(logits)

    # Phase.CONTENT
    if self._state == Phase.CONTENT:
        return self._call_inner(tokens, logits)
    return logits

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._force_transition

_force_transition(logits: array) -> array

Force the next token in the reasoning end sequence.

Source code in vllm_mlx/constrained/thinking_processor.py
def _force_transition(self, logits: mx.array) -> mx.array:
    """Force the next token in the reasoning end sequence."""
    target_id = self._end_token_ids[self._transition_index]
    # Mask all logits to -inf, then set the target token to 0.
    # Handle both 1-D (vocab,) and 2-D (1, vocab) logits shapes.
    masked = mx.full(logits.shape, float("-inf"))
    if masked.ndim == 1:
        masked[target_id] = 0.0
    else:
        masked[..., target_id] = 0.0
    return masked

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._call_inner

_call_inner(tokens: array, logits: array) -> array

Delegate to inner processor if present.

Source code in vllm_mlx/constrained/thinking_processor.py
def _call_inner(self, tokens: mx.array, logits: mx.array) -> mx.array:
    """Delegate to inner processor if present."""
    if self._inner is not None:
        logits = self._inner(tokens, logits)
    return self._mask_content_phase_control_tokens(logits)

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._mask_content_phase_control_tokens

_mask_content_phase_control_tokens(logits: array) -> array

Prevent reserved think-tag starts from leaking into final content.

Source code in vllm_mlx/constrained/thinking_processor.py
def _mask_content_phase_control_tokens(self, logits: mx.array) -> mx.array:
    """Prevent reserved think-tag starts from leaking into final content."""
    for token_id in self._content_phase_mask_ids:
        if logits.ndim == 1:
            logits[token_id] = float("-inf")
        else:
            logits[..., token_id] = float("-inf")
    return logits

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
def _snapshot_state(
    self,
) -> tuple[Phase, int, int, tuple[int, ...], tuple[int, ...], bool]:
    return (
        self._state,
        self._thinking_tokens,
        self._transition_index,
        self._start_matcher.snapshot(),
        self._end_matcher.snapshot(),
        self.watchdog_was_enforced,
    )

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._restore_snapshot

_restore_snapshot(processed_len: int) -> None
Source code in vllm_mlx/constrained/thinking_processor.py
def _restore_snapshot(self, processed_len: int) -> None:
    # In CONTENT phase, snapshots stop growing (see _sync_to_tokens).
    # If rollback targets a CONTENT position beyond the snapshot list,
    # use the last available snapshot -- the state is identical since
    # _advance_with_token is a no-op in CONTENT.
    snap_idx = min(processed_len, len(self._snapshots) - 1)
    (
        self._state,
        self._thinking_tokens,
        self._transition_index,
        start_state,
        end_state,
        self.watchdog_was_enforced,
    ) = self._snapshots[snap_idx]
    self._start_matcher.restore(start_state)
    self._end_matcher.restore(end_state)
    self._processed_len = processed_len
    self._processed_token_ids = self._processed_token_ids[:processed_len]
    self._snapshots = self._snapshots[: snap_idx + 1]

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._sync_to_tokens

_sync_to_tokens(tokens: array) -> None
Source code in vllm_mlx/constrained/thinking_processor.py
def _sync_to_tokens(self, tokens: mx.array) -> None:
    target_len = int(tokens.size)
    token_ids = tokens.tolist()
    common_len = 0
    max_common = min(target_len, self._processed_len)
    while (
        common_len < max_common
        and self._processed_token_ids[common_len] == token_ids[common_len]
    ):
        common_len += 1
    if common_len < self._processed_len:
        self._restore_snapshot(common_len)
    if target_len == self._processed_len:
        return
    for token_id in token_ids[self._processed_len :]:
        self._advance_with_token(token_id)
        self._processed_token_ids.append(token_id)
        self._processed_len += 1
        # Skip snapshots in CONTENT -- _advance_with_token is a no-op
        # there, so snapshots would just waste memory on long generations.
        if self._state != Phase.CONTENT:
            self._snapshots.append(self._snapshot_state())

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor._advance_with_token

_advance_with_token(token_id: int) -> None
Source code in vllm_mlx/constrained/thinking_processor.py
def _advance_with_token(self, token_id: int) -> None:
    if self._state == Phase.IDLE:
        if self._start_matcher.feed(token_id):
            self._state = Phase.THINKING
            if self._thinking_token_budget == 0:
                self._state = Phase.TRANSITIONING
                self._transition_index = 0
        return

    if self._state == Phase.THINKING:
        if self._end_matcher.feed(token_id):
            self._state = Phase.CONTENT
            return
        self._thinking_tokens += 1
        if self._thinking_tokens >= self._thinking_token_budget:
            self._state = Phase.TRANSITIONING
            self._transition_index = 0
        elif (
            self._no_final_content_token_limit is not None
            and self._thinking_tokens >= self._no_final_content_token_limit
        ):
            self._state = Phase.TRANSITIONING
            self._transition_index = 0
            self.watchdog_was_enforced = True
        return

    if self._state == Phase.TRANSITIONING:
        expected = self._end_token_ids[self._transition_index]
        if token_id == expected:
            self._transition_index += 1
            if self._transition_index >= len(self._end_token_ids):
                self._state = Phase.CONTENT
                self._end_matcher.reset()
        return

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
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher(target_ids: list[int])

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.

View source #L16-L48.

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.

View source #L25-L30.

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.feed · method
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.feed(token_id: int) -> bool

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.

View source #L32-L35.

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.reset · method
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.reset() -> None

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.

View source #L37-L39.

vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.snapshot · method
vllm_mlx.constrained.thinking_processor.BoundedSuffixMatcher.snapshot() -> tuple[int, ...]

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.

View source #L41-L43.

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.

View source #L45-L48.

vllm_mlx.constrained.thinking_processor.Phase · class
vllm_mlx.constrained.thinking_processor.Phase()

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.

View source #L51-L57.

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.

View source #L60-L287.

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.

View source #L92-L129.

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.state · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.state() -> Phase

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.

View source #L132-L135.

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.thinking_tokens · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.thinking_tokens() -> int

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.

View source #L138-L141.

vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.is_retired · method
vllm_mlx.constrained.thinking_processor.ThinkingAwareLogitsProcessor.is_retired() -> bool

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.

View source #L144-L150.

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.

View source #L152-L170.

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.

View source #L172-L182.

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.

View source #L184-L188.

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.

View source #L190-L197.

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.

View source #L199-L209.

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.

View source #L211-L229.

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.

View source #L231-L252.

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.

View source #L254-L287.

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