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–The bf16 x rows t0 .. t0 + n into LDS rows 0 .. (rows padded).
-
mix_src–Token t's source
src, slice columns cc .. cc + 4: fromvals, or -
poll_rows_to_lds–gemv.rows_to_ldsfrom tagged pairs: columns k0 .. k0 + k of rows -
stage_gate–Token t: the 56 slices' partials -> source weights e_s and their sum.
-
stage_gates–The gates of tokens bid, bid + 56, .. (< S) on attn CTA
bid. -
stage_gemv–Rows 16 rg .. of in_proj against the LDS x (tokens t0 .. t0 + n) -> bf16
-
stage_mix–Columns 128 task ..: the softmax mix of the sources (4 columns a thread,
-
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
-
vals_all–Whether every (token, source)'s slice stays in LDS
vals(else the -
wait_x–Every slice's x ready.
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, tl=None)
¶
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
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 | |
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, t0, n)
¶
The bf16 x rows t0 .. t0 + n into LDS rows 0 .. (rows padded).
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
mix_src(c, t, src, cc, c0)
¶
Token t's source src, slice columns cc .. cc + 4: from vals, or
(prefix only in LDS) a block re-read from blocks -- the same bf16 values
stage_slice read.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
poll_rows_to_lds(c, region, k, n, xl, xrow, ldk, k0, t0)
¶
gemv.rows_to_lds from tagged pairs: columns k0 .. k0 + k of rows
t0 .. t0 + n of the [S, ldk] bf16 rows a producer put as (word, tag) pairs
into region, polled (two pairs a spec, every thread's specs one batch)
-> LDS rows 0 .. n - 1.
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_gates(c, bid)
¶
The gates of tokens bid, bid + 56, .. (< S) on attn CTA bid.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
stage_gemv(c, rg, ops, t0, n)
¶
Rows 16 rg .. of in_proj against the LDS x (tokens t0 .. t0 + n) -> 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 the sources (4 columns a thread, 16 tokens a round), 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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
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.
Source code in vllm/models/kimi_k3/amd/specialized_decode/mono/attention/kda.py
vals_all(s, ns, extra=0)
¶
Whether every (token, source)'s slice stays in LDS vals (else the
prefix only; stage_mix re-reads the blocks), extra bytes beside it.