vllm.models.kimi_k3.amd.specialized_decode.mono.attention.mla
¶
M1a mla_pre: one Kimi-K3 MLA layer from the AttnRes seam to AITER's
decode input, for a spec-verify step (S rows) at TP8 + DCP8 (the DCP group the
TP group: rank r's 12 heads are heads 12 r .. of the gathered query) or TP8 +
DCP1 (ranks 1: the query is this rank's 12 heads, no gather).
One launch a layer, BLOCKS CTAs x THREADS threads:
attn CTAs 0 .. 55 AttnRes + input_layernorm as K1 (``kda.stage_*``) ->
bf16 x rows, an XRDY flag a slice
gemv CTAs 56 .. fused_qkv_a (132 x 16 rows) and g_proj (96 x 16), task
gi and gi + 200: q_c | kv_c | k_pe -> QA (bf16 pairs);
the gate bf16(sigmoid(bf16 g)) -> ``gate_out``
norm (token t on CTA t)
q_a / kv_a RMSNorm: q_c -> plain bf16 rows, a QCR flag
a token; kv_c (normed) | k_pe -> fp8 cache entry when
the token's slot is this rank's (>= 0)
q_b (16 rows, CTAs 64 ..)
q_c rows in LDS: q_nope -> QN (bf16 pairs); q_pe -> fp8
-> every rank's QG (DCP1: ``q_out``)
W_UK (a wave a (token tile, head, 16 latent rows), CTAs 208 ..)
q_nope -> MXFP4 (aiter's even scale, a lane a 32-block),
one 16x16x128 FP4 MFMA against W_K -> bf16 -> fp8 ->
every rank's QG (DCP1: ``q_out``)
(``qbf16``, DCP1: bf16 -> ``q_out``, M1c's)
unpack (every CTA, DCP8)
this rank's QG -> the dense gathered ``q_out``
[S, ranks 12, 576] fp8
Rounding follows the vLLM path where it is elementwise (bf16 hand-offs, the fp8 quants, the MXFP4 quant of the W_UK input); split-K sums differ only in their order.
Functions:
-
bf_words–ndwords of a bf16 row at wordi(device scope). -
block_sum2–Waves 0 .. 5's sum and waves 6, 7's sum of
v(q / kv threads). -
even_code–Aiter's
_mxfp4_scale_from_amaxcode from |bf16| bitsam: the -
fp8_word–Four f32 -> four E4M3 (vLLM's saturating quant, scale 1).
-
gemv_tasks–Gemv CTA
gi: task gi (weights issued before x lands), then gi + 200. -
mla_pre–Host launcher.
w_k(12, 512, 64) u8 MXFP4 andw_k_scale(12, 512, -
peer_pairs–QG: every source rank's [S, 12, 144] fp8 words, a pair each.
-
proj_loads–Task
task's 16 weight rows (fused_qkv_a, then g_proj) for this wave; -
put_q–Query values
4 w ..(four f32, bf16-exact) of (token t, local head h): -
put_qg–fp8 word
wof (token t, local head h) -> every rank's QG; at DCP1 -
stage_norm–Token t: q_c (threads 0 .. 383, 4 columns each) and kv_c (384 ..) RMSNorm;
-
stage_proj–Task
taskagainst the LDS x (tokens t0 .. t0 + n): q_c | kv_c | k_pe -
stage_qb–q_b rows 16 task ..: head h = task / 12, its nope rows (sub < 8) -> QN or
-
stage_uk–Wave task (tile, head, 16 latent rows): W_K's rows against the 16 tokens'
-
stage_unpack–This rank's QG ->
q_out[S, QH, 576]: a thread 2 words a round (QG
bf_words(ptr, i, n)
¶
n dwords of a bf16 row at word i (device scope).
block_sum2(c, v)
¶
Waves 0 .. 5's sum and waves 6, 7's sum of v (q / kv threads).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
even_code(am)
¶
Aiter's _mxfp4_scale_from_amax code from |bf16| bits am: the
exponent of amax rounded at mantissa bit 21, minus 2, clamped at 0.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
fp8_word(v)
¶
gemv_tasks(c, gi)
¶
Gemv CTA gi: task gi (weights issued before x lands), then gi + 200.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
mla_pre(key, *, prefix, delta, blocks, ares_nw, ares_qk, in_nw, w_qkv, w_g, q_nw, kv_nw, w_qb, w_k, w_k_scale, kv_cache, slots, gate_out, q_out, scratch, peers, rank, layer, epoch, health, alarm, tl=None)
¶
Host launcher. w_k (12, 512, 64) u8 MXFP4 and w_k_scale (12, 512,
4) e8m0, any strides but W_K's last; kv_cache [blocks, block_size, 576]
one-byte, entries dense; slots [S] int64 (-1: another rank's token);
gate_out [S, 1536] bf16; q_out [S, q_heads(key), 576] fp8 (dense; bf16 with
qbf16);
peers every rank's peer buffer base (i64 a rank; unread at ranks 1,
may be None); layer a slot below
kda.TAG_SLOTS.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | |
peer_pairs(s, ranks)
¶
proj_loads(c, task)
¶
Task task's 16 weight rows (fused_qkv_a, then g_proj) for this wave;
a task past the last loads the last.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
put_q(c, t, h, w, v)
¶
Query values 4 w .. (four f32, bf16-exact) of (token t, local head h):
fp8 -> QG / q_out, or with qbf16 bf16 pairs -> q_out.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
put_qg(c, t, h, w, word)
¶
fp8 word w of (token t, local head h) -> every rank's QG; at DCP1
straight to q_out (nothing in this launch reads it).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
stage_norm(c, t)
¶
Token t: q_c (threads 0 .. 383, 4 columns each) and kv_c (384 ..) RMSNorm; q_c -> plain bf16 row + QCR; kv_c | k_pe (threads 0 .. 15) -> fp8 entry.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
stage_proj(c, task, ops, t0, n)
¶
Task task against the LDS x (tokens t0 .. t0 + n): q_c | kv_c | k_pe
rows -> QA, g rows -> the gate.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
stage_qb(c, task)
¶
q_b rows 16 task ..: head h = task / 12, its nope rows (sub < 8) -> QN or pe rows -> fp8 -> QG.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
stage_uk(c, task)
¶
Wave task (tile, head, 16 latent rows): W_K's rows against the 16 tokens' MXFP4 q_nope -> bf16 -> fp8 -> QG (a lane 4 rows of one token).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/mla.py
stage_unpack(c)
¶
This rank's QG -> q_out [S, QH, 576]: a thread 2 words a round (QG
pair 2 u, u = global thread + round x grid). Gathered head g also lands
at R x 12 + g while that is a pad head (g < QH - R x 12).