vllm.models.kimi_k3.amd.specialized_decode.mono.attention.back
¶
K2a attn_post: one Kimi-K3 KDA layer from the gated core output to the
MoE's input row -- o_proj, its TP all-reduce inside the kernel, and the MLP
AttnRes seam.
One launch a layer and rank, BLOCKS x THREADS:
gemv CTAs 56 .. o_proj (448 x 16 rows, K = 1536 local): bf16 GEMV of the
core rows (plain loads: the previous launch wrote them) ->
bf16 partial -> pushed to every rank's AR region (system
scope, this rank's slot)
attn CTAs 0 .. 55 per 128 columns: the 8 ranks' partials summed in rank
order (fp32 -> bf16: the custom all-reduce's result) ->
LDS delta; then K1's AttnRes stages with the MLP's weights:
prefix + delta -> prefix out, the sources' softmax mix,
post_attention_layernorm -> the MoE input x
The AR region is double-buffered by the step epoch's parity: a rank a step ahead writes the other half, so no peer's unread partials are overwritten.
Functions:
-
ar_half_pairs–One parity's AR region:
[src rank][token][column pair]. -
load_core–Core rows t0 .. t0 + n (of S x 1536 bf16) -> LDS, rows padded;
cm -
o_loads–Rows 16 rg .. of o_proj, this wave's K chunks (wave, wave + 8 < 12): a lane
-
peer_at–peers[p](an Addr a rank) for a traced rankp. -
rearm_ar–(OPT_SENT) Re-arm the words
stage_reduceread fortask, -
reduce_two_shot–The owner of
colsums the 8 scattered partials (rank order, as the -
sent_item–(OPT_SENT) A reduce item's (token, column pair), so consecutive items
-
sent_ix–(OPT_SENT) Word index of (src rank, pair at
col, token t), blocked -
sent_on–(OPT_SENTS) This build's all-reduce
which("ar": o_proj's, -
sent_sum–The
TPranks' sentinel words of (col pair, t) inownsummed in -
slice_loads–stage_slice's loads of slicetaskthat need no hand-off: each -
stage_o–Rows 16 rg .. for the core tile t0 .. t0 + n: GEMV -> bf16 partials ->
-
stage_reduce–Columns 128 task ..: the 8 ranks' partials, rank order, -> bf16 delta in
-
stage_slice_pre–kda.stage_slicefor K2 (delta in LDS, no block write) on the -
two_shot–Above 8 rows the AR scatters each partial to its columns' owner rank,
_raw4(ptr, i)
¶
bf16 elements i .. i + 4 as two raw words (kda.ld_bf4's load).
ar_half_pairs(s)
¶
load_core(c, t0, n, cm=0)
¶
Core rows t0 .. t0 + n (of S x 1536 bf16) -> LDS, rows padded; cm
CM_DEV when this launch's own CTAs wrote them (K2's fused M1b).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
o_loads(c, rg)
¶
Rows 16 rg .. of o_proj, this wave's K chunks (wave, wave + 8 < 12): a lane 64 B of its row a chunk.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
peer_at(peers, p)
¶
peers[p] (an Addr a rank) for a traced rank p.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
rearm_ar(c, task)
¶
(OPT_SENT) Re-arm the words stage_reduce read for task,
after the mix (off the critical path).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
reduce_two_shot(c, task, t, col)
¶
The owner of col sums the 8 scattered partials (rank order, as the
one-shot) and puts the bf16 sum to the other ranks' slot [owner]; they
poll it there (a slot the scatter leaves free off the owner).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
sent_item(idx, s)
¶
(OPT_SENT) A reduce item's (token, column pair), so consecutive items
read consecutive sent_ix words.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
sent_ix(src, col, t, s, width)
¶
(OPT_SENT) Word index of (src rank, pair at col, token t), blocked
[src][16-col group][token][8 pairs]; shared by push and reduce.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
sent_on(c, which='ar')
¶
(OPT_SENTS) This build's all-reduce which ("ar": o_proj's,
"latr", "final") goes through its sentinel region (layer.k2_sent; a
plain call: a method call on c inside a traced branch would make FlyDSL
carry c as branch state).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
sent_sum(c, own, col, t, width, rearm=True)
¶
The TP ranks' sentinel words of (col pair, t) in own summed in
fp32 in rank order (as sum_partials), re-armed unless rearm is
off (the caller re-arms them later).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
slice_loads(c, task)
¶
stage_slice's loads of slice task that need no hand-off: each
round's block and prefix words, then the round-invariant ares_nw / ares_qk
words (a live thread's columns are the same every round: THREADS % QC == 0).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
stage_o(c, rg, ops, t0, n)
¶
Rows 16 rg .. for the core tile t0 .. t0 + n: GEMV -> bf16 partials -> every rank's AR region, this rank's slot (thread: token, row pair; a put a peer).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
stage_reduce(c, task)
¶
Columns 128 task ..: the 8 ranks' partials, rank order, -> bf16 delta in LDS (thread: token, column pair).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
stage_slice_pre(c, task, ld)
¶
kda.stage_slice for K2 (delta in LDS, no block write) on the
preloaded words ld (slice_loads).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/back.py
two_shot(s)
¶
Above 8 rows the AR scatters each partial to its columns' owner rank, which reduces and broadcasts: 2/8 of the one-shot's bytes a link.