vllm.models.deepseek_v41.amd.mono.attention.back
¶
K2 back: one DeepSeek-V4.1 attention layer from the rotated query to the
rank's wo_b partial.
One launch a layer and rank, BLOCKS x THREADS, S rows:
split (S x chunks of CK keys): flash-decoding over one chunk of a token's
keys (K1's key table: top-k compressed rows, then window rows) for
every head of the rank. The token's q in LDS; each wave one
(head tile, 16-key tile): its fp8_ds_mla rows loaded once,
dequantized into its QK operands and kept raw in LDS; QK (bf16
MFMA), the chunk's max / sum per head, bf16 p in LDS; PV over the
chunk's raw rows (wave w: dims 64 w ..) -> the chunk's partial
(bf16) and its (max, sum) per head, published
combine (S x H): a (token, head)'s chunks merged with the sink folded in,
bf16, inverse GPT-J RoPE of dims 448.., vLLM's MXFP8 of each 32
-> XO (published)
wo_a (G x 1024 / 32, two 16-row tiles): the group's XO rows times wo_a
-> bf16 -> MXFP8 of the 32 rows -> X8B (published)
wo_b (320, 16 rows): X8B times wo_b -> bf16 -> ``out``
Hand-offs are plain device-scope data behind tagged flags (half the bytes of a
tagged pair per value). Adapted from ATOM's V4.1 attn_post (K2a), which
reads a bf16 pool and ends in a peer all-reduce.
Functions:
-
await_flags–Thread u < n polls flag
index(u); then the CTA proceeds. -
back_context–The attention back's context: LDS views (
lds: an allocated -
back_lds–K2's attention LDS: the union of
back_lds_members. -
back_lds_members–K2's attention LDS structs: the split stage's and the GEMVs' (a union's
-
back_plan–(nchunk, n_split, n_comb, COMB0, WOA0, WOB0, early_wob) of a build.
-
chunk_keys–A split unit's keys: a 16-key tile a wave of a head group.
-
epoch_begin–This CTA has read the launch pair's epoch: its own mark word (no
-
epoch_end–CTA 0, once every CTA marked this epoch (thread u checks CTA u's mark):
-
head_groups–Wave groups a split unit's head tiles are spread over: two (a tile each,
-
key_rec–(data address, scale address, valid) of token t's key k from K1's key
-
p_row–A P row (one head's chunk of bf16 p) in LDS, i32 words.
-
publish–This CTA's stores visible device-wide, then the flag pair (region, i).
-
run_back–The attention back's stages on this CTA: split, combine, wo_a, wo_b.
-
stage_combine–(token, 8 heads)
unit, a wave a head, 8 dims a lane: the chunks -
stage_split–Flash-decoding over chunk
unit % nchunkof tokenunit // nchunk, -
stage_woa–Rows 32 task .. of wo_a -> bf16 -> vLLM's MXFP8 of the 32 -> X8B.
-
stage_wob–Rows 16 task .. (and 16 task2 ..,
has2) of wo_b -> bf16 -> out, or
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/back.py
back_context(key, lds, args, scratch, tag, layout=None)
¶
The attention back's context: LDS views (lds: an allocated
back_lds, or a dict of the members' views), mailbox (tag tag),
scratch regions, arguments by name.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
back_lds(s, d)
¶
K2's attention LDS: the union of back_lds_members.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
back_lds_members(s, d)
¶
K2's attention LDS structs: the split stage's and the GEMVs' (a union's members: one at a time).
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
back_plan(key)
¶
(nchunk, n_split, n_comb, COMB0, WOA0, WOB0, early_wob) of a build.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
chunk_keys(d, s)
¶
epoch_begin(c, epoch, ep)
¶
This CTA has read the launch pair's epoch: its own mark word (no
contended atomic) := ep + 1, which epoch_end checks.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
epoch_end(c, epoch, ep, reset=None)
¶
CTA 0, once every CTA marked this epoch (thread u checks CTA u's mark):
reset() (state later pairs must find cleared), then the epoch moved on.
The next pair's hand-offs carry a tag no earlier pair wrote; later launches'
kernels start after this one ends.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
head_groups(d, s)
¶
Wave groups a split unit's head tiles are spread over: two (a tile each, 64-key chunks, twice the units) while the units fit the grid, else one (a wave's keys loaded and dequantized once for every head tile).
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
key_rec(c, t, k)
¶
(data address, scale address, valid) of token t's key k from K1's key table: slot | 1 << 31 for a compressed row, a window slot otherwise, -1 for none (it reads a zero record: its scores are masked, its values zeros).
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
p_row(d, s)
¶
publish(c, region, i)
¶
This CTA's stores visible device-wide, then the flag pair (region, i).
run_back(c, key, bid)
¶
The attention back's stages on this CTA: split, combine, wo_a, wo_b.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 | |
stage_combine(c, unit)
¶
(token, 8 heads) unit, a wave a head, 8 dims a lane: the chunks
merged with the sink folded in, bf16, inverse RoPE, MXFP8 of each 32 -> XO,
published (a flag a (token, head group)).
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 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 | |
stage_split(c, unit)
¶
Flash-decoding over chunk unit % nchunk of token unit // nchunk,
every head of the rank -> the chunk's partial and (max, sum) per head. Wave
(head group hg, key tile kt): keys 16 kt .. of the chunk (loaded and
dequantized once) against the group's head tiles; then dims 64 w .. of the
PV over every key and head.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
191 192 193 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 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 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 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
stage_woa(c, task, ops, t0, n)
¶
Rows 32 task .. of wo_a -> bf16 -> vLLM's MXFP8 of the 32 -> X8B.
Source code in vllm/models/deepseek_v41/amd/mono/attention/back.py
stage_wob(c, task, ops, task2, ops2, has2, t0, n, mark=False)
¶
Rows 16 task .. (and 16 task2 .., has2) of wo_b -> bf16 -> out, or
(c["wob_out"], the mono layer) the caller's hook with each bf16 pair.