vllm.models.kimi_k3.nvidia.specialized_decode.drafter.model
¶
The specialized decode's DSpark drafter (decode_backend=latency_specialized).
What changes against the stock K3DSparkForCausalLM (all exact):
- context_proj (5 x 7168 -> 7168, 514 MB BF16) is replicated on every TP rank
in the stock model, so each TP8 / DCP8 rank streams all of it every draft step.
Here it is column-parallel with its output all-gathered: each rank streams 1/TP
of the weight (same dot products, full K per output column) and one
[R * (k + 1), 7168 / TP] BF16 all-gather rebuilds the rows.
- every drafter linear and the lm_head shard run on linears.DraftGemm.
- the k sequential Markov steps run as one launch each (markov.py).
- the draft block's attention folds its tokens into heads (attention.py).
- at TP > 1 (comm.py, Lamport mailboxes on multicast symmetric memory): the
context projection's and the lm_head's all-gathers, and the embedding's
all-reduce fused with the first RMSNorm; under DCP (= TP) the draft attention's
query gather and LSE combine + W_UV on the specialized decode's DCP mailboxes
(attention.DraftDcp). forward replaces K3DSparkModel.forward for the
batches these serve (the stock forward otherwise). The draft layers' all-reduce
+ RMSNorm sites stay on flashinfer's fused one-shot (LAYER_AR_ROWS).
All of it lives here: register makes vLLM build SpecializedK3DSparkForCausalLM
(a subclass of the stock drafter) for the DSpark draft architecture, and the stock
dspark_mla.py / mla.py stay unchanged. The column-parallel context projection
replaces the stock replicated one at construction, before the weights load (the
replicated one is allocated and freed once, at load).
Classes:
-
SpecializedK3DSparkForCausalLM–The stock DSpark drafter with the changes listed above, built in place of
-
SpecializedK3DSparkModel–K3DSparkModelwhose forward runsspecialized_forward(the drafter's
Functions:
-
after_loading–Route the drafter's linears through DraftGemm and reserve the folded draft
-
context_proj–The draft's context projection column-parallel with a gathered output when
-
draft_shape–What the drafter's load-time reservations are sized by: the largest draft
-
forward–K3DSparkModel.forwardwith the embedding's all-reduce fused into the -
install_collectives–Build the drafter's mailboxes (collective: every TP rank runs it at load, in
-
install_draft_fold–Fold the draft block's tokens into heads in the layer's MLA decode
-
register–Serve the DSpark draft with
SpecializedK3DSparkForCausalLMin this
SpecializedK3DSparkForCausalLM
¶
Bases: K3DSparkForCausalLM
The stock DSpark drafter with the changes listed above, built in place of
K3DSparkForCausalLM (register). Same weights, same checkpoint names.
Methods:
-
sample_sequential–The speculator asks the model for its own Markov sampling first.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
sample_sequential(speculator, num_reqs, head_hidden)
¶
The speculator asks the model for its own Markov sampling first.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
SpecializedK3DSparkModel
¶
Bases: K3DSparkModel
K3DSparkModel whose forward runs specialized_forward (the drafter's
collectives, set at load by install_collectives) first; its None (a batch
it does not serve) or no hook runs the stock forward.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
_build_dcp(backbone)
¶
The draft attention's DCP path when DCP = TP (rank d owns head block d).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
_folded_impl(base)
cached
¶
base (the layer's MLA impl class) whose forward_mqa runs the folded
draft decode first. Keeps the class name (logs, backend checks).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
_gathered_linear()
cached
¶
ColumnParallelLinear(gather_output=True) whose all-gather is the drafter's
(comm.DrafterComm.gather_context, attached at load), NCCL's otherwise.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
_prepared_embedding(backbone, tp)
¶
The vocab-parallel embedding's local lookup (cutedsl.common.embedding,
zero rows for ids another rank owns) whose all-reduce forward fuses with
the first draft layer's RMSNorm; None keeps the stock embedding.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
after_loading(model)
¶
Route the drafter's linears through DraftGemm and reserve the folded draft
attention's CAKE workspace for the largest draft batch (model is a
specialized K3DSparkForCausalLM).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
context_proj(backbone, prefix)
¶
The draft's context projection column-parallel with a gathered output when
TP > 1 divides it, replacing the stock replicated one before the weights load
(the checkpoint's context_proj.weight is sharded by its loader); None keeps
the stock one.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
draft_shape(vllm_config)
¶
What the drafter's load-time reservations are sized by: the largest draft
batch (requests), the block length k, the local attention heads and the
plan length of captured graphs; None when the draft attention cannot run CAKE
(DCP returns an LSE: the cute-dsl kernel).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
forward(backbone, comm, dcp, embed, input_ids, positions, inputs_embeds)
¶
K3DSparkModel.forward with the embedding's all-reduce fused into the
first RMSNorm (ArNorm) and the draft attention on dcp, or None (the stock
forward) for a batch these do not serve. Same layers, same order.
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
install_collectives(model)
¶
Build the drafter's mailboxes (collective: every TP rank runs it at load, in the same order) and route the forward, the context projection and the lm_head gather through them. Returns (DrafterComm or None, DraftDcp or None).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
install_draft_fold(attn)
¶
Fold the draft block's tokens into heads in the layer's MLA decode
(attention.draft_forward_mqa: one decode row per request instead of one per
token; the stock forward_mqa for a batch it does not fold).
Source code in vllm/models/kimi_k3/nvidia/specialized_decode/drafter/model.py
register()
¶
Serve the DSpark draft with SpecializedK3DSparkForCausalLM in this
process (ModelRegistry.register_model, vLLM's model-class extension point).
specialized_decode_config calls it when the deployment selects the
specialized decode: the target model is built (and calls it) before the
speculator loads the drafter. A draft class resolved earlier in this process
(cached by get_model_architecture) is dropped so the load resolves again.