Repository navigation
cuda: sparse gather attention over listed cache rows (Kolibri 1.1, slice 1 of #4846) - #5166
Conversation
|
Thank you, @jschmied. CHANGES REQUESTED at The shared fold in One host refusal defect remains at Please check the excessive key-head count before any multiplication by
|
d7ddcb1 to
4118f86
Compare
|
Done on
|
|
Thank you—the key-head guard now rejects the overflowing shape before any multiplication by The sparse gather, duplicate and empty-list behavior, index masking, nonfinite replay, and warp-order fold are consistent in source. Nothing served calls the new kernel, so I have no remaining code defect to request. The only residual coverage I would add is one focused CUDA case combining a negative count, a duplicate across a tile boundary, invalid indices during forced nonfinite replay, and one query head per key head, beside the planted control and existing block-attention checks. No checkpoint is needed for this unwired kernel.
|
4118f86 to
da3c61f
Compare
…shared in attn_fold.cuh tf_sparse_attention attends each (row, key head) to its own list of cache rows: GQA up to 16 query heads a key head, head dim 128, the list cut into four warps' slices folded in warp order, NaN and infinite values replayed as block_attention.cu does. block_attention.cu takes its Fold from attn_fold.cuh, unchanged (SASS identical on every SM built). Contract cells for Kolibri 1.1's 48 over 4 heads with a planted control (the kernel told one key fewer).
…e contract lists nothing, every slot, past cap and unnamed rows
… the cache rows weighs nothing and is not read
…ock_attention's fold
…tion image and export
…is refused (its count's 32-key tiles round up in i32)
… 31), where a count's tile round-up would overflow i32
…; n + 31 overflowed i32 at max_cap, a host mirror checks the boundary
…fused before hk x 128 is taken (2^57 heads overflowed it)
…n excessive count is refused, not an overflow
…r when the sparse attention set fails
da3c61f to
7ebff9f
Compare
|
Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
The focused CUDA case from your review (7187194600) is in #5242: one query head per key head, a negative count, a duplicate across a 32-key tile edge, and unnamed entries during a forced nonfinite replay, beside the planted control and the block attention checks. It is green on the real kernel; with the replay's named-entry check planted out, only the new case goes red. Test only, no kernel change. |
Refs #4846
Head:
4118f86beb, rebased onto main67ae36c4dcafter #5051 landed. The kernel contract and the full CI set ran on thishead; the SASS comparison ran before the rebase (see "Against main"). The gradient-serving pins of
cuda/kernels.zigandcuda/root.zigarerefreshed for the new image and export.
Slice 1 of Kolibri 1.1 (#4846): a core CUDA kernel that attends each query row to its own list of cache rows, the
attention a sparse indexer's picks (top-k, local and sink keys) need. No family calls it yet; nothing served changes.
What changes
kernels/cuda/sparse_attention.cu,cuda/sparse_attention.ziglist[row][g][0 .. counts[row][g])of the cache'skeysrows,strideelements apart: GQA up to 16 query heads a key head, head dim 128, the list cut into four warps' slices folded in warp order; NaN and infinite values replayed asblock_attention.cudoeskernels/cuda/attn_fold.cuhblock_attention.cuhad inline, now included by bothtests/cuda/contract_sparse_attn.zig,core/contract/sparse_attention_records.zigtests/cuda/contract_family_sets.zigtopk_rowsandsparse_indexpair; on a failed init those two unwind in reverse init orderThe kernel's stated rules (in the kernel and the wrapper's doc comment):
for it (a per-tile ballot mask, and the same check on the NaN/infinity replay path);
block_attention.cu's fold: past fp32's range (for example 128 equal keys with V2^122) a head is +-inf in both kernels; this PR keeps that behaviour and those bits rather than a new order.
Shapes the wrapper refuses before any launch (
check,error.SparseShape; the key-head count is checked before anyproduct with it): no query heads, more than 65,535 key heads, a head count not a whole
number of key heads, more than 16 query heads a key head, an empty list capacity, no cache rows or more than i32
holds, a row stride under hk x 128 elements or not a multiple of 8, a list capacity past
max_cap(INT_MAX - 31: thelast 32-key tile's indices stay in i32). The kernel counts a list's tiles as
n / 32 + (n % 32 != 0), which cannotoverflow at that capacity.
Against main
block_attention.cunow includesattn_fold.cuh; its machine code is unchanged:tools/zig/cuda_sass_compare.py --images block_attention(base9961ca4920, then the merge base, against9803062e39; nvcc 13.0; main up to67ae36c4dcchanges none of thefiles
block_attention.cucompiles from, and the commits since9803062e39touch onlysparse_attention.cu, the wrapperand tests) gives
SUMMARY PASS images=1 functions=5:tf_block_attention's SASS and encoding sha256 equal on sm_80, sm_86, sm_89, sm_120 and sm_121 (sm_120/121 SASSa54ab7a9..., sm_80486667ad..., sm_86c57e7dba..., sm_8929a74df8...). No other kernelincludes the header. Nothing is wired into a family, so there is no served path to compare (no seeded, resume or
concurrency claim); those come with the Kolibri 1.1 forward PR.
Evidence
Kernel contract on
4118f86beb(tf-cuda-test kernel-contract 'sparse attention' 'block attention', GB10, nvcc 13.0), exit code 0:48 query heads over 4 key heads; the shapes gate adds each dimension's tile edges.
zig/tests/cuda/contract_sparse_attn.zig:163): an empty list, a list fillingevery slot and told cap + 5, and entries -1 and one past the last cache row inside the count. Gate 4 leaves them
out: its mirrored sums need every head finite.
zig/tests/cuda/contract_sparse_attn.zig:33, the kernel told one key fewer.1db7c5c365, the old kernel body) fail the shapes gate on theplanted lists; with the clamp and the mask (
83efd3cca5) they pass. Theh = 0refusal has its unit test incuda/sparse_attention.zig.cuda/sparse_attention.zig"check takes Kolibri 1.1's groups ..." acceptsmax_capand refusesmax_cap + 1(fails on571c1a0364, before1424b1d075). The tile count atmax_capis checked by a host mirror ofthe kernel's i32 arithmetic ("the tile count at max_cap ..."): a device run at that capacity needs an 8 GiB list per
(row, key head), so the kernel itself is not run there.
h = hk = 2^57(rows, cap and keys 1, stride 0); on7079d36011, beforece328e4ac1,hk x 128overflowed first and the test build panicked.Full CI set (x86 lane) on
4118f86beb:25583/25729 tests passed (146 skipped), gradient-serving pins,cuda-host, pr-check, fmt, diff-check and lean all rc 0. Lean check: 0 new problems (152 on the base, 152 on the head).
Not here (later PRs): the indexer that produces the lists (#5051), and the Kolibri 1.1 forward that wires both.
Proposed CHANGELOG line:
cuda: sparse gather attention over listed cache rows (tf_sparse_attention, with contract); block attention's fold shared in attn_fold.cuh.