Skip to content

vllm.models.qwen3_5.xpu.specialized_decode.planning

Host-only batch planning and bounded observability for MoE specialization.

Classes:

  • DecodeRuntime –

    Shared planning state; never owns another weight or cache representation.

DecodeRuntime

Shared planning state; never owns another weight or cache representation.

Source code in vllm/models/qwen3_5/xpu/specialized_decode/planning.py
class DecodeRuntime:
    """Shared planning state; never owns another weight or cache representation."""

    def __init__(self):
        self.executors: list[FusedMoeDecode] = []
        self.step: DecodeStep | None = None
        self.steps: Counter[str] = Counter()
        self.history: deque[tuple[tuple[str, ...], DecodeStep]] | None = None

    def prepare_step(self, batch: "InputBatch") -> DecodeStep:
        reason = None
        if batch.num_draft_tokens:
            reason = "draft_tokens"
        elif (
            not 0
            < batch.num_reqs
            <= batch.num_tokens
            <= batch.num_tokens_after_padding
            <= MAX_DECODE_ROWS
        ):
            reason = "token_rows"
        elif any(
            batch.num_tokens_after_padding * e.top_k > MAX_ROUTED_ROWS
            for e in self.executors
        ):
            reason = "routed_rows"
        self.step = DecodeStep(
            batch.num_reqs, batch.num_tokens, batch.num_tokens_after_padding, reason
        )
        self.steps[reason or "eligible"] += 1
        if self.history is not None:
            self.history.append((tuple(batch.req_ids), self.step))
        return self.step

    def prepare_capture(self, num_reqs: int, num_tokens: int) -> None:
        reason = (
            None if 0 < num_reqs == num_tokens <= MAX_DECODE_ROWS else "capture_shape"
        )
        self.step = DecodeStep(num_reqs, num_tokens, num_tokens, reason)

    def snapshot(self) -> dict:
        return {
            "layers": len(self.executors),
            "planned_steps": dict(self.steps),
            "persistent_scratch_bytes": sum(e.scratch_bytes for e in self.executors),
            "specialized_weight_bytes": (
                0 if all(e.bindings_match() for e in self.executors) else None
            ),
            "native_launches_including_capture": sum(
                e.native_launches for e in self.executors
            ),
            "bindings_shared": all(e.bindings_match() for e in self.executors),
        }