Repository navigation
core: exact row top-k, sparse index scores and block summaries for sparse indexers - #5051
Conversation
|
Thank you @jschmied. The top-k comparisons, causal open-block ranges and explicit precision/layout refusals are in place, and these helpers remain separate from serving. One cleanup remains in the parent: after top-k setup succeeds, a failure while setting up the sparse-index set leaks the top-k allocation and module. Please add its error cleanup before the next initialization and a regression for that failure. The existing numerical results can keep their scope; this guard alone needs no repeat run.
|
|
Thank you, @jschmied. The explicit NaN key, padding bound and head-sum stress improve the numerical coverage. The current head merges cleanly. The earlier cleanup ask remains at zig/tests/cuda/contract_family_sets.zig:90: top-k setup succeeds before sparse-index setup, with no top-k error cleanup between them. If the second setup fails, its predecessor's set and module leak. Please add the immediate error guard and the focused failure regression from the last review. The existing numerical receipts keep their tested scope.
|
|
Thanks @ashhart. The cleanup is in
The body's "Since b3e89e5" section lists the earlier follow-ups (NaN key, padding bound, NaN-cut and multi-head stress rows) with their runs. |
|
Thank you, @jschmied. The pair helper closes the cleanup ask: it arms top-k destruction before sparse-index setup can fail. The focused allocator test uses that same helper, covers failure and success, and is unchanged across the reported failing/passing guard comparison. The actual destructor unloads the module and frees the set. No further source change is requested. The kernels and numerical fixtures are unchanged from the previous review, and this head merges cleanly. The cleanup alone needs no numerical rerun. Keep existing results tied to their tested images; any still-unfilled mixed-NaN/padding and head-sum stress cells remain suitable for focused synthetic GB10 qualification without a checkpoint.
|
|
Thank you, @jschmied. The GB10 kernel contract for this head passed: all 12 kernels through gates 1-4, all 5 planted controls red, and the
|
9c2f4c0 to
abd048c
Compare
…arse indexers CUDA kernels tf_topk_rows / tf_topk_rows_wide, tf_index_scores, tf_index_blocks and tf_index_open_blocks, each with a kernel contract and a planted control; core/sparse_index.zig as their float64 reference (one score order, budget, the dense rule as a policy field, the pool shortcut, NVFP4 options for token keys, queries and block summaries and the summaries' input, pools bound to their sequence); core/sparse_topology.zig for per-layer KV, selection, pool and index-key owners from explicit lists; core/nvfp4_store.zig (E2M1 with E4M3 scales, saturation, NaN rule, floor). GLM's select kernels are untouched (SASS identical).
…nonfinite rows; a k the padding loop cannot step is refused
…ps in 64 bits and k leaves room for a block's stride
…a stress row over every head, its head sum simulated in the accumulator
…est that a failing second set leaks nothing
…d sparse_index images and exports
…nvcc 13.0.88 builds it
abd048c to
f8c1085
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. |
… lines main adds at the top
… lines main adds at the top
Refs #4846
Head:
a2e25b9812. The evidence below ran onb3e89e5c81unless a line names another sha; the follow-ups since are listedunder "Since b3e89e5" with the runs on their own heads.
Slice B of Kolibri 1.1 (after slice A, #4941): the core pieces a sparse indexer needs, generic and in core, with
CUDA kernels and their contracts. Nothing here is wired into a family yet; no family's behaviour changes. Against main: no served tokens or bytes can change (no family calls these yet), and GLM's select kernels compile to identical SASS; there is no served or seeded equality claim, so no parity-controls run applies. GLM's
select kernels are untouched (their SASS is identical, below); moving GLM onto the shared header is a later,
byte-identical PR of its own.
What changes
kernels/cuda/common/topk_rows.cuh,topk_rows.cu,cuda/topk_rows.zigkofnscores, positions bit-equal tocore/sparse_index.zigselect; 128 threads, and 1,024 threads when rows <= 48 and n >= 4,096 (the same switch GLM uses)kernels/cuda/sparse_index.cutf_index_scoresphi(q_h . k_g), fp32 sums, times a configurable scale (default 1); writes-inffrom each row's count toldtf_index_blocks,tf_index_open_blockst + 1), so a prompt chunk's rows never see a later row's keyscore/sparse_index.zigflips();denseis a policy rule (off by default; equal to every stage only where the open block is scored, a closed one shown to differ); the pool shortcut tested equal to every stage; separate NVFP4 options for token keys, queries and block summaries, andsummary_input(summaries from the original or the stored keys); a pool bound to its sequence, layer and positioncore/sparse_topology.zigindex_cache); a sparse layer left out of the selection list is refused (UnsettledSelectOwner), not guessedcore/nvfp4_store.zigRefused by name before any launch (
cuda/sparse_index.zigscoresFor/blocksFor):IndexHeadDim,IndexHeads,IndexKeyHeads,IndexPhi,IndexReduce,IndexSummary,IndexStreams,IndexPagedKeys, andIndexPrecision(NVFP4 keys, queries or summaries: the kernels read bf16). A follower given a pool from another owner, position or
sequence gets
error.ForeignPool.Where each rule comes from
index_*,kv_source_layers)queries_nvfp4/keys_nvfp4are options)summary_nvfp4,summary_inputare parameters; no source decides it)dense)bf16_topkThe publisher's package was used only as a black box for outputs. No engine's source was read for these rules.
Evidence
Kernel contract (
tf-cuda-test kernel-contract 'topk rows' 'sparse index' 'glm select' 'glm decode select', GB10,nvcc 13.0):
SUMMARY 15 kernels: 15 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems.tf_topk_rows,tf_topk_rows_wide): positions equal tosparse_index.selecton every row, over 19 shapes,including 1/4/16 x 16,384 keys top-2,048, 24 x 4,096, 6 x 65,536, 2 x 131,072 and 60 x 8,192; the same with every
score tied, and with subnormal scores (lost under flush-to-zero; the images are built
--ftz=false). Counts out ofrange (-3, n + 7) are planted and clamped.
the float64 bound;
ld = n + 37checks the-inffill; a count-0 row and an oversized count. Sums gate: exact atk 64, where fp16 sums would miss by 3,495,253x and bf16 by 5,592,405x.
Sums gate: exact at k 128 (fp16 would miss by 1,792x with the open block left out).
Planted controls, each red as planted:
zig/tests/cuda/contract_topk_rows.zig:32: told each row one score fewer than it has.zig/tests/cuda/contract_sparse_index.zig:37: scores told each row one key fewer.zig/tests/cuda/contract_sparse_index.zig:249: block means told one key fewer.zig/tests/cuda/contract_sparse_index.zig:413: open blocks told each row's end one key later.zig/tests/cuda/contract_sparse_index.zig:414: open blocks told one key fewer than the cache holds (the kernel'sbound on
ends; the normal entry plants ends of -5 and n + 9, clamped).Register / shared-memory records for sm_80/86/89/120/121 in
core/contract/sparse_index_records.zig; the live limitscheck passes for all five launches.
GLM unchanged:
glm_glue.cuSASS identical between main47a605aa12(the base) andb3e89e5c81on sm_80, sm_86, sm_89,sm_120 and sm_121 (nvcc 13.0 -O3, cuobjdump). No GLM timing run: its machine code did not change.
Host tests (core, Zig): every selection is causal, ascending, without repeats and within budget (a planted future key,
a repeat, a missing sink key and one key over budget are each caught); dense counter-case (ten keys under a budget of
16 are all attended); block boundaries; NaN order; key heads and scale; shortcuts equal to every stage scored; NVFP4
flips across the top-k boundary; foreign pool refused (planted: it was accepted); topology roles for layers 14, 24 and
49; planted bad lists refused by name; NVFP4 saturation, NaN rule and floor (each planted).
Since b3e89e5
87617d97a0(tests) +ed1270a72d(fix): every NaN of either sign or payload maps to one key above +inf (PTX doesnot state NaN encodings); the padding loop steps in 64 bits and the host refuses k above
maxInt(i32) - 1024. Thenonfinite rows now count NaN of both signs and with payloads (row 1 was told -3 before, so its NaN was never ranked).
Test first: the k host test fails on
87617d97a0; the NaN rows pass on the old kernel too (GB10 returns one NaN).d0048e586d(tests): a row whose k cuts through 2,560 mixed NaN (lower index first), and a stress row over everyhead whose head sum is simulated in the accumulator (an fp16 or bf16 head sum misses it).
4d70a5559b(test) +e87d88d74a(fix):contract_family_sets.zigsets the top-k and sparse-index sets up as apair (
contract_set_pair.zig): a failing sparse-index setup releases the top-k set and its module. Host testtest-contract-set-pair-host(intest-cuda-host): leaks on4d70a5559b, passes one87d88d74a.d0048e586d(topk rows,sparse index,glm select,glm decode select): 15 kernels passgates 1-4, 0 fail; 5 controls red as planted. Full CI set on
d0048e586dand one87d88d74a: ci, cuda-host,pr-check, fmt, diff-check and lean all rc=0 (
X86-ALL-GREEN), lean 0 new. GLM:common/topk_rows.cuhis includedby
topk_rows.cualone, so no GLM image changes.a2e25b9812: the gradient-serving pins ofcuda/kernels.zigandcuda/root.zig(raw) refreshed for the newimages and exports;
zig build test-gradient-servingpasses (it failed CI one87d88d74a).Full CI set (x86 lane,
kol11-b3-final-x86) onb3e89e5c81: ci, cuda-host, pr-check, fmt, diff-check and lean all rc=0(
X86-ALL-GREEN); lean: 0 new problems (164 on the base, 164 on the head).Shapes: the shapes gate runs every served shape above plus each dimension's edges (the tile less a step, the tile,
the tile plus a step, the least and the largest size;
contract.zig:57). The full hazard row list (1, 2, 3, 4, 7, 8, 13,16, 31, 32, 65) is not run one by one: the kernels give each row its own block, so rows have no tile tail; key-count
tails are covered by the edges and by
ld = n + 37.Not here (later PRs): wiring into the Kolibri 1.1 forward, tensor-core scoring, a multi-CTA top-k, incremental
summaries, and GLM's migration to the shared header.
Seeded, resume, concurrency and against-main replies: not applicable here; no family calls these kernels yet, so no
served path changes (GLM's machine code is identical, above). They come with the Kolibri 1.1 forward PR.
Proposed CHANGELOG line:
core: exact row top-k, sparse index scores and block summaries (CUDA, with contracts), layer roles for sparse indexers, NVFP4 store.