vllm.models.deepseek_v41.amd.mono.attention.front
¶
K1 front: one DeepSeek-V4.1 attention layer 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:
xq (S > 16: S x 2 K halves, on the 32 CTAs without a wqkv part): the
bf16 input's half -> vLLM's MXFP8 -> X8 (published, a flag each)
kt (S): the token's attention keys for K2 -- top-k compressed slots
through the kv source's block table, then window slots -> KT
wqkv_a (112 row tiles x 2 K halves, 16 rows): the input's MXFP8 half --
quantized in the CTA (S <= 16) or X8's -- 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)
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).
-
quant_x_half–x_half_loads' values -> vLLM's MXFP8 rows of the K half in LDS (a -
run_front–The front's stages on this CTA.
x8_given: a stage before this one -
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 -
stage_xq–xq_loads' values -> vLLM's MXFP8 -> X8 words / X8S codes of the -
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 -
x_half_loads–Tokens t0 .. t0 + n's bf16 input, K half
part: its loads only (16 B a -
xq_loads–(token, K half)
unit's bf16 input: its load only, 8 values a thread
await_flags(c, region, n, index)
¶
Thread u < n polls flag index(u); then the CTA proceeds.
Source code in vllm/models/deepseek_v41/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_v41/amd/mono/attention/front.py
front_lds(s, d)
¶
K1's LDS (the attention front's stages).
Source code in vllm/models/deepseek_v41/amd/mono/attention/front.py
publish(c, region, i)
¶
This CTA's stores visible device-wide, then the flag pair (region, i).
quant_x_half(c, regs, n)
¶
x_half_loads' values -> vLLM's MXFP8 rows of the K half in LDS (a
32-group = 4 lanes).
Source code in vllm/models/deepseek_v41/amd/mono/attention/front.py
run_front(c, key, bid, x8_given=False, before_wqkv=None, after_wqkv=None)
¶
The front's stages on this CTA. x8_given: a stage before this one
(the mono layer's seam norm) publishes X8 / XRDY for every token (no input
quantization here). before_wqkv() runs ahead of the wqkv weights' loads
(a latency-critical stage of the caller's), after_wqkv() right after.
Source code in vllm/models/deepseek_v41/amd/mono/attention/front.py
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 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
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.
Source code in vllm/models/deepseek_v41/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_v41/amd/mono/attention/front.py
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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
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_v41/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_v41/amd/mono/attention/front.py
stage_xq(c, unit, w, live)
¶
xq_loads' values -> vLLM's MXFP8 -> X8 words / X8S codes of the
unit (published by the caller).
Source code in vllm/models/deepseek_v41/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_v41/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).
Source code in vllm/models/deepseek_v41/amd/mono/attention/front.py
x_half_loads(c, part, pred, t0, n)
¶
Tokens t0 .. t0 + n's bf16 input, K half part: its loads only (16 B a
lane-item, 8 values; a thread one column of [2 n half-rows, 160]), masked
off on CTAs without a wqkv part.
Source code in vllm/models/deepseek_v41/amd/mono/attention/front.py
xq_loads(c, unit, pred)
¶
(token, K half) unit's bf16 input: its load only, 8 values a thread
(threads past the half mirror its last item).