Repository navigation
cuda: the graph's decode attention sums its live splits alone - #60
Merged
Merged
Conversation
The graph form launches S_max splits, sized at the cache's capacity, so that one graph serves every position. Past the live count each split still staged and wrote a neutral partial, and tl_attn_combine read all S_max of them: at 4096 cached tokens of capacity, Gemma 4 E2B's 512-wide layers wrote and read 1.3 MB a layer at any depth, and a short cache paid for the capacity's splits. - attn_dec_core: an empty range (a dpos split past the live count) writes its heads' m alone, at attn_m_empty, and returns before any barrier. attn_m_empty names the softmax's starting m, which the core and the combine share. - tl_attn_combine: the max still reads every split's m (16 loads in flight, as before), and counts up to the last split whose m is not empty; the sums stop there. Live splits come first, so that is the live count, read from the partials themselves: no d_pos, no rule, no second combine kernel. The host path's splits are never empty, so it sums all S. The sums run over the same splits in the same order as the host path's, so the output stays bit-identical to it. Two forms tried first and dropped: a combine that derives the live count from d_pos (the load and the rule's divisions sit before its sums, +0.3 to +0.6 us a call where every split is live), and one that skips an empty split inside the sums loop (the branch on each loaded m serializes the loads, +1 us).
Cleanups from /simplify on the live-splits change. - The empty split's rule (its m alone, at attn_m_empty; empty splits come after the rest, so the combine's sums stop after the last that is not) is part of the partials' layout, and is now said once, on attn_partials. The kernels and launcher that relied on it in their own words point there. - attn_dec_core's warp merge starts from attn_m_empty, as its states do, rather than a second spelling of -1e30. - attn64's comment says what the empty m guards: the combine never reads the partials the windowed passes leave behind. The PTX is the same, instruction for instruction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up 2 of #51. The graph form of the decode attention launches S_max splits, sized at the cache's capacity, so one graph serves every position. Past the live count each split still staged and wrote a neutral partial, and
tl_attn_combineread all S_max of them (Gemma 4 E2B's 512-wide layers: 1.3 MB written and read a layer at any depth, with the default 4096 capacity).attn_dec_core: an empty range (a dpos split past the live count) writes its heads' m alone, atattn_m_empty, and returns before any barrier.attn_m_emptynames the softmax's starting m, which the core and the combine share.tl_attn_combine: the max still reads every split's m (16 loads in flight, as before) and counts up to the last split whose m is not empty; the sums stop there. Live splits come first, so this is the live count, read from the partials themselves: no d_pos, no split rule, no second combine kernel. The host path's splits are never empty, so it sums all S as before.The sums run over the same splits in the same order as the host path's, so the output stays bit-identical to it.
Two forms tried first and dropped:
attn_dpos_chunkagain): the load and the rule's divisions sit before its sums, +0.3 to +0.6 us a call where every split is live;GPU time a call (graph replay over 8 caches, capacity 4096, f16 cache, median of 5 alternating pairs, RTX 3090)
Where every split is live (2048 cached at 4096 capacity) the change is -0.4 to +0.3 us; the Llama 1B shape keeps +0.27 us (its 5 pairs +0.24 to +0.39).
End to end (bench_qwen_llama, tok/s, alternating rounds)
Tests
cuda_ukernelstill finds no local memory.Metal has no graph form of this attention, so nothing changes there.