vllm.models.kimi_k3.amd.specialized_decode.mono.attention.kda
¶
K1 kda_pre: one Kimi-K3 KDA layer from the AttnRes seam to the gated core
output, for a spec-verify step (R requests x L tokens, S = R L rows).
One launch a layer, BLOCKS CTAs x THREADS threads, in three roles so that
no CTA that polls a mailbox has weight loads in flight (a poll's load retires
behind every earlier load):
attn CTAs 0 .. 55 slice (128 hidden columns each): prefix (+ delta) ->
bf16 prefix out, per-source partial sum of squares and
qk dot (PART); gate (token t on CTA t): softmax weights
(WGT); mix: the softmax mix, its partial sum of squares
(MSQ), every slice's -> output RMSNorm -> bf16 x rows
(plain device-scope stores, an XRDY flag a slice)
gemv CTAs 56 .. in_proj, two 16-row groups each: the first group's
weights issued at kernel start, the second's as x lands
-> q|k|v|g|f_a|beta (PROJ)
kda tasks (R x 12 heads x 8 v-chunks) on CTAs 0 ..: inputs that
need no hand-off loaded first (metadata, conv window,
state rows, f_b rows), then conv update of the owned
channels (q / k out through QK), f_b MFMA + lower-bound
gate, l2norm, the recurrence on 16 state rows (a state a
token written), partial norms (ONRM), gated RMSNorm ->
core_out
Rounding follows the original path where it is elementwise (the AttnRes prefix add, every bf16 hand-off between the original kernels); split-K reductions differ only in their order.
Functions:
-
bf4_words–Four f32 -> two words of packed bf16.
-
gemv_loads–This wave's weight operands of rows 16 rg .. for its K chunks
chunks -
kda_conv–Owned channels: the spec conv update of request
req's L tokens -> new -
kda_gates–f_a, beta and the head's q / k (one poll batch a thread); g1 = f_b f_a by
-
kda_norm–Rows 16 ch ..: gated RMSNorm over the head's 128 (every chunk's partial)
-
kda_pre–Host launcher.
conv_state[slots, dim, state_len] or a transposed view -
kda_recur–State rows 16 ch .. of head h: the recurrence over the L tokens, a state
-
kda_stage–The task's inputs that need no hand-off, issued before its first poll:
-
ld_bf4–bf16 elements i .. i + 4 (i a multiple of 4) as four f32.
-
load_x–Every slice's x ready -> the bf16 x rows into LDS (rows padded).
-
stage_gate–Token t: the 56 slices' partials -> source weights e_s and their sum.
-
stage_gemv–Rows 16 rg .. of in_proj against the LDS x -> bf16 PROJ.
-
stage_mix–Columns 128 task ..: the softmax mix of
vals(4 columns a thread), its -
stage_slice–Columns 128 task ..: every token's sources into LDS
vals(4 columns a -
step_tag–This launch's mailbox tag: the step's epoch (a device counter the runner
bf4_words(v)
¶
gemv_loads(c, rg, chunks)
¶
This wave's weight operands of rows 16 rg .. for its K chunks chunks
(indices into wave, wave + 8, ..): a lane 64 contiguous bytes of its row a
chunk (4 dwordx4). rg past the last group loads the last group.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
kda_conv(c, k, req, h, ch)
¶
Owned channels: the spec conv update of request req's L tokens -> new
conv state; q / k out through QK, v to LDS.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
kda_gates(c, k, req, h)
¶
f_a, beta and the head's q / k (one poll batch a thread); g1 = f_b f_a by MFMA (a wave 16 rows) -> lower-bound gate -> decay in LDS; q / k l2-normed (q scaled).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
kda_norm(c, req, h, ch)
¶
Rows 16 ch ..: gated RMSNorm over the head's 128 (every chunk's partial) -> core_out.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
kda_pre(key, *, prefix, delta, blocks, ares_nw, ares_qk, in_nw, w_in, w_fb, conv_w, conv_state, a_log, dt_bias, on_w, rstate, st_idx, num_acc, core_out, scratch, layer, epoch, health, alarm)
¶
Host launcher. conv_state [slots, dim, state_len] or a transposed view
of [slots, state_len, dim] (strides read); rstate [slots, 12, 128, 128]
fp32; st_idx [R, >= L] int32; scratch zeroed before the step's first
layer (tags are a layer's); epoch a device int32 bumped once a step and
layer this launch's slot below TAG_SLOTS.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
kda_recur(c, k, req, h, ch)
¶
State rows 16 ch .. of head h: the recurrence over the L tokens, a state
written a token, bf16 outputs to LDS ol and their partial norms (ONRM).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
kda_stage(c, req, h, ch)
¶
The task's inputs that need no hand-off, issued before its first poll: metadata, the owned channels' conv window / weights, the initial state rows, the f_b rows of this wave and the per-head constants.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
ld_bf4(ptr, i)
¶
bf16 elements i .. i + 4 (i a multiple of 4) as four f32.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
load_x(c)
¶
Every slice's x ready -> the bf16 x rows into LDS (rows padded).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
stage_gate(c, t)
¶
Token t: the 56 slices' partials -> source weights e_s and their sum.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
stage_gemv(c, rg, ops)
¶
Rows 16 rg .. of in_proj against the LDS x -> bf16 PROJ.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
stage_mix(c, task)
¶
Columns 128 task ..: the softmax mix of vals (4 columns a thread), its
sum of squares (MSQ), every slice's -> rstd, then bf16 x = mixed rstd w ->
the plain x rows, and the slice's XRDY flag.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
stage_slice(c, task)
¶
Columns 128 task ..: every token's sources into LDS vals (4 columns a
thread), the prefix (+ delta) rounded to bf16 and stored back, per-(token,
source) partial sum of squares and qk dot -> PART.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
step_tag(epoch, slot)
¶
This launch's mailbox tag: the step's epoch (a device counter the runner bumps once a step, in the graph) and the launch's slot, so no step's or other launch's pair ever passes for this one's -- nothing is zeroed.