vllm.models.muse_spark.amd.mono.kernels.k3
¶
K3: one Muse Spark decoder layer for S = 8 / 16 rows as one persistent launch.
One rank of a TP = EP = 8 group (rank r owns experts [32 r, 32 r + 32)), 256 CTAs x 512 threads, everything between two attention cores:
[attention] optional: this layer's verify attention (attn_frag.py) at the head
O o-norm x sigmoid(gate) -> o_proj rows 32 b .. over this rank's K slice; the bf16
partial goes to the owner rank of the column block (b // 32): reduce-scatter
AB the owner sums the 8 partials in rank order and all-gathers the reduced o and its
norm partials; every CTA: post-attention norm, gated residual on the fp32 stream,
pre-FFN norm -> ffn_in (one token-reduction round for both norms)
A router logits (fp32) + pre_expert_proj of this rank's shard, K in 8 parts over
8-CTA groups; logit partials and h_raw go to every rank's peer buffer
route every CTA routes every token (identical top-8), the local experts' picks
C, D gate_up / down of the local experts: MXFP4 weights in vLLM's shuffled layouts,
decoded in registers, bf16 MFMA
E per-pick post-expert norm and weighted sum -> the EP partial, reduce-scattered to
the block owner, summed in rank order, all-gathered
F post_expert_proj (this rank's 1024 rows, K in 4 parts) -> every rank
G post-FFN norm, gated residual, the next layer's input norm -> stream (fp32) and
the next attention input (bf16)
QKV the next layer's qkv + gate GEMV (K in eighths); the owners finish whole heads:
qk-norm, RoPE (next_rope), q out, bf16 K / V into vLLM's LBHNC KV cache
Peer regions are double buffered by tag parity; tag = epoch * 64 + layer + 1 with the epoch bumped in lockstep by every rank once per forward.
Functions:
-
bf_mma_operand–Coalesced bf16 weight registers (4 instructions: rows 8 blk + lane / 8, 16 B at
-
bf_tile_load–16 rows (row16 ..) x 128 K (k ..) of a row-major bf16 [*, ldk] weight, coalesced.
-
bf_tile_load_mma–16 rows (row16 ..) x 128 K (k ..) of a row-major bf16 [*, ldk] weight, loaded straight in the
-
build_vllm–The K3 build vLLM launches for S rows (8 / 16) of a TP = EP = 8 group; next_rope: the next
-
dn_loads–Task (u, j)'s w2 operands for this wave (expert etab[u], u clamped below nv).
-
fp4_mma–Chunk c (256 K) of a 16-row MXFP4 group: 8 MFMA steps, B column n = LDS row row0 + n (at
-
mx_chunk–Rows rbase .. rbase + 16 x K chunk c (256) of a shuffled MXFP4 [*, k] weight w and its e8m0
-
o_gate–o-norm (over the head's 8 lanes) x sigmoid(gate) of 8 bf16 (4 pair words xv, gv) -> 4 words.
-
peer_layout–Every rank's peer buffer (IPC-shared), [parity] first.
-
route_token–Tokens
tkns(this wave's, all valid), interleaved for ILP: sigmoid + -
scratch_layout–This rank's scratch regions. ss, ss1, ss2g, ssa1 and ssa2 are unused; they keep the
-
task_ring–Tasks task .. end - 1: compute(q[0], task, it, *args) with the next len(q) tasks' loads
bf_mma_operand(ops, qq, lane)
¶
Coalesced bf16 weight registers (4 instructions: rows 8 blk + lane / 8, 16 B at 128 h + 16 (lane % 8)) -> the MFMA A operand of step qq (K 32 qq + 8 g of row r).
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
bf_tile_load(wbase, row16, ldk, k, lane)
¶
16 rows (row16 ..) x 128 K (k ..) of a row-major bf16 [*, ldk] weight, coalesced.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
bf_tile_load_mma(wbase, row16, ldk, k, lane, cm=CM_NT)
¶
16 rows (row16 ..) x 128 K (k ..) of a row-major bf16 [*, ldk] weight, loaded straight in the 16x16x32 bf16 MFMA A-operand layout: element qq (of 4) is the operand of MFMA step qq (lane l = row l % 16, K 32 qq + 8 (l / 16) .. + 8), 16 rows x 64 B an instruction. The same operand values as bf_tile_load + bf_mma_operand (bit-identical results) without the 8 ds_bpermute a step.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
build_vllm(S=8, W=8, next_rope=True, attn='')
¶
The K3 build vLLM launches for S rows (8 / 16) of a TP = EP = 8 group; next_rope: the next layer has RoPE; attn = "swa" / "full": this layer's verify attention fused at the head.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
dn_loads(w2, w2s, w_post, etab, task, lane, wave, ok, nv=None)
¶
Task (u, j)'s w2 operands for this wave (expert etab[u], u clamped below nv).
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
fp4_mma(ops, base, bl, brow, lane, acc, c, jpar, rows, row0=0)
¶
Chunk c (256 K) of a 16-row MXFP4 group: 8 MFMA steps, B column n = LDS row row0 + n (at
most rows - 1: columns past the expert's picks read some row, their outputs are never stored).
jpar: the task's 16-row group parity (j & 1), for the shuffled scales.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
mx_chunk(ok, w, ws, rbase, k, c, lane, g, r, nbytes, sbytes)
¶
Rows rbase .. rbase + 16 x K chunk c (256) of a shuffled MXFP4 [*, k] weight w and its e8m0 scales ws: 2 dwordx4 + 1 scale dword. vLLM shuffle_weight((16, 16)): lane L reads the 16 B at 16 L of the 1 KB block (16 rows x K bytes 64 (2 c + q) ..): one instruction = 1 KB contiguous; fp4_mma's permlane swaps map the pieces to the MFMA lanes. e8m0_shuffle: lane 16 g + r reads the dword (rbase // 32, c, K block % 4 = 2 (g % 2) + g // 2, row r): rows r, r + 16 x K blocks of 4 apart; 64 lanes = 256 B contiguous (kernel_s_dword).
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
o_gate(xv, gv)
¶
o-norm (over the head's 8 lanes) x sigmoid(gate) of 8 bf16 (4 pair words xv, gv) -> 4 words.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
peer_layout(S, world=W)
¶
Every rank's peer buffer (IPC-shared), [parity] first.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
route_token(tkns, bias_v, lgss, tid, lane, rt)
¶
Tokens tkns (this wave's, all valid), interleaved for ILP: sigmoid +
bias, radix top-8, rank, renorm -> rid / rw.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
scratch_layout(S, world=W)
¶
This rank's scratch regions. ss, ss1, ss2g, ssa1 and ssa2 are unused; they keep the offsets of the regions after them.
Source code in vllm/models/muse_spark/amd/mono/kernels/k3.py
task_ring(load, compute, q, task, it, end, unr, *args)
¶
Tasks task .. end - 1: compute(q[0], task, it, *args) with the next len(q) tasks' loads
(load(task)) in flight. unr (len(q) = 2): three tasks an iteration in fixed slots (q[0],
q[1], qc): two tasks' loads stay in flight during each compute, no rotation copy waits for its
data (the tail: the second loop).