vllm.models.deepseek_v4.amd.mono.attention.front
¶
K1 front: one attention layer (the counts below are TP8's) from its
normed input row to the rotated query and the step's KV rows in the
sliding-window cache.
One launch a layer and rank, BLOCKS CTAs x THREADS threads, S rows.
Every CTA issues its weight loads (its wqkv part and its wq_b tasks) at the
kernel start, before it waits on anything; the stages:
wqkv_a (128 row tiles x 2 K halves, 16 rows; a CTA each): the input's MXFP8
half (X8, from the seam's norm) a token tile at a time (the next
tile's rows in flight) times wqkv's -> fp32 partials -> QKVP
qkv (S): the halves summed -> bf16; q_norm -> bf16 -> MXFP8 -> QX8
(published, a flag a token); kv_norm -> bf16 -> GPT-J RoPE -> bf16
-> the fp8_ds_mla record at the token's slot
wq_b (H x 512 / 16, 16 rows): QX8 times wq_b -> bf16 -> GPT-J RoPE of
each head's dims 448.. -> q (global, bf16)
kt (S, run by K2 after vLLM's indexer): the token's attention keys --
top-k compressed slots through the kv source's block table (or,
``global_keys``, every compressed slot of vLLM's c128a table), then
window slots -> KT
Each elementwise step follows vLLM's ROCm path (mxfp8_quantize,
FusedQKVRMSNorm, fused_deepseek_v4_qnorm_rope_kv_rope_quant_insert);
the GEMV reductions differ from the Triton GEMMs' only in their order.
Adapted from ATOM's V4.1 attn_pre (K1), less its mHC seam.
Functions:
-
await_flags–Thread u < n polls flag
index(u); then the CTA proceeds. -
front_context–The front stages' context: LDS views, mailbox (tag
tag), scratch -
front_lds–K1's LDS (the attention front's stages).
-
publish–This CTA's stores visible device-wide, then the flag pair (region, i).
-
run_front–The front's stages on this CTA, from the input's MXFP8 X8 / XRDY that a
-
stage_kt–Token t's keys for K2:
KT[t][k] = slot | 1 << 31for its top-k compressed -
stage_qkv–Token t: the K halves summed -> bf16; q_norm -> bf16 -> MXFP8 (QX8);
-
stage_wqb–Rows 16 (task0 + BLOCKS k) .. of the rank's H x 512 query rows, every
-
stage_wqkv–Rows 16 task .. of wqkv over K half
partagainst tokens t0 .. t0 + n -
wqb_pos–This thread's token position for
stage_wqb's epilogue of tile -
wqb_rope–(cos, sin) of this thread's pair in
stage_wqb's epilogue over a tile
_kt_round(c, t, k, ntopk, kv_len, width, req, cm)
¶
stage_kt's key k of token t.
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
await_flags(c, region, n, index)
¶
Thread u < n polls flag index(u); then the CTA proceeds.
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
front_context(key, lds, args, scratch, tag, layout=None)
¶
The front stages' context: LDS views, mailbox (tag tag), scratch
regions, arguments (args: the kernel's, by name).
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
front_lds(s, d)
¶
K1's LDS (the attention front's stages).
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
publish(c, region, i)
¶
This CTA's stores visible device-wide, then the flag pair (region, i).
run_front(c, key, bid, before_wqkv=None, after_wqkv=None)
¶
The front's stages on this CTA, from the input's MXFP8 X8 / XRDY that a
stage before them (the mono layer's seam norm) publishes for every token.
before_wqkv() runs ahead of the wqkv weights' loads (a latency-critical
stage of the caller's), after_wqkv() right after. The step's key table
is K2's (stage_kt): an index source's top-k comes after this launch.
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
stage_kt(c, t)
¶
Token t's keys for K2: KT[t][k] = slot | 1 << 31 for its top-k compressed
rows (k < ntopk), the window slot for k in [ntopk, kv_len), -1 for an
invalid or absent key; KLEN[t] = kv_len (0 for a pad row), KLEN[S + t] =
ntopk. The top-k table holds request-local compressed indices (through the
block table) or, global_keys, the slots themselves (a row of the
runtime width bt_stride: vLLM's every compressed key of a C128 layer).
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
stage_qkv(c, t)
¶
Token t: the K halves summed -> bf16; q_norm -> bf16 -> MXFP8 (QX8); kv_norm -> bf16 -> RoPE -> bf16 -> the fp8_ds_mla record at slot_mapping[t]. 256 threads (8 q columns and 2 kv columns each); threads 256.. mirror thread 255 and store nothing.
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
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 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 342 343 344 345 346 347 348 349 | |
stage_wqb(c, task0, bops, t0, n, rope)
¶
Rows 16 (task0 + BLOCKS k) .. of the rank's H x 512 query rows, every task k of the CTA: GEMVs -> bf16 -> GPT-J RoPE of a head's dims 448.. (fp32) -> bf16 -> q.
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
stage_wqkv(c, task, part, ops, t0, n, live)
¶
Rows 16 task .. of wqkv over K half part against tokens t0 .. t0 + n
-> fp32 partials QKVP[part] (live: a CTA with a wqkv part).
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
wqb_pos(c, t0, n)
¶
This thread's token position for stage_wqb's epilogue of tile
t0 .. t0 + n.
Source code in vllm/models/deepseek_v4/amd/mono/attention/front.py
wqb_rope(c, task0, pos_t, n)
¶
(cos, sin) of this thread's pair in stage_wqb's epilogue over a tile
of n rows (pos_t: its token's position; every task of the CTA shares
the pair's dims: tasks BLOCKS apart are whole heads apart).