vllm.models.deepseek_v4.amd.mono.attention.back
¶
K2 back: one 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 head's RMSNorm
factor (``q_head_rstd``) from it; 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
A wide key table (``bounded``) skips the chunks past a token's
keys, known from its position.
combine (S x H): a (token, head)'s chunks merged with the sink folded in
(``bounded``: its live chunks only, ``merge_live``),
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 (448, 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
-
merge_all–The chunks' (sum, 8 dims) of (t, h) weighted by exp2(max - the max),
-
merge_live–merge_allover the live chunks only,MERGE_BATCHat a time (a -
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).
-
q_head_rstd–Each head's weightless RMSNorm of the token's q in LDS:
-
run_back–The attention back's stages on this CTA: split, combine, wo_a, wo_b.
-
split_chunk–Flash-decoding over chunk
chof tokent, every head of the rank -
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
_chunk_loads(c, t, h, d0, cc)
¶
Chunk cc's (max, sum) of head h and its partial's 8 dims from d0.
Source code in vllm/models/deepseek_v4/amd/mono/attention/back.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/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_v4/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_v4/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_v4/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_v4/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_v4/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_v4/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_v4/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_v4/amd/mono/attention/back.py
merge_all(c, t, h, d0, nlive, sink)
¶
The chunks' (sum, 8 dims) of (t, h) weighted by exp2(max - the max),
the sink's term first, in chunk order: every chunk loaded at once (a
past-nlive chunk weighs nothing).
Source code in vllm/models/deepseek_v4/amd/mono/attention/back.py
merge_live(c, t, h, d0, nlive, sink)
¶
merge_all over the live chunks only, MERGE_BATCH at a time (a
wide key table: most of its chunks past a token's keys).
Source code in vllm/models/deepseek_v4/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).
q_head_rstd(c)
¶
Each head's weightless RMSNorm of the token's q in LDS:
rsq(mean(q^2) + eps) -> qn [head]. vLLM norms q before its RoPE, which
keeps every pair's norm: the scores scale by it after the dot product.
Source code in vllm/models/deepseek_v4/amd/mono/attention/back.py
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_v4/amd/mono/attention/back.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 | |
split_chunk(c, t, ch)
¶
Flash-decoding over chunk ch of token t, 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_v4/amd/mono/attention/back.py
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 436 437 438 439 440 441 442 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 | |
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_v4/amd/mono/attention/back.py
stage_split(c, unit)
¶
Flash-decoding over chunk unit % nchunk of token unit // nchunk
(split_chunk). A build whose key table is wider than a token's top-k
(bounded: every compressed row of a long context) skips a chunk past
the token's keys at most, known from its position alone: no load of its q
or keys.
Source code in vllm/models/deepseek_v4/amd/mono/attention/back.py
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_v4/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.