Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #673

Raw Markdown for agents: https://autobot.eidonix.com/p/65608533-4ba8-4495-8482-9db62489e0a9.md

#1 [high] Lens findings: subtraction/simplicity on PR #673

F1 (high) Stale doc left behind — docs/logprobs-design.md:92-100 still says "Tiles retain their best 32 integer sort keys; a final merge stores K pairs" (single 8192-key sort); no mention of width-agnostic kernels. AGENTS.md:232 requires reading/updating the logprob contract for logprob changes. Replace those 2 sentences with the chunked merge (BLOCK<=512, 480-key merge steps, bit-exact top-20) and a clause that the four kernels are width-independent.

F2 (high) tests/components/test_logprobs.py:57-68 — 8-row parametrize table (1,32),(64,32),(1024,32),(1025,64),(16384,512),(16385,MB),(31744,MB),(262144,MB) recomputes min(next_pow2(cdiv(vocab,1024)*32),512) from the implementation, and asserts via private internals dict(zip(_finish.arg_names, op._preparation[3][1], strict=True)). AGENTS.md:194-199 bans source/text checks that only restate the code. Collapse to 2-3 boundary cases asserting the bound: assert finish_args["BLOCK"] <= _MERGE_BLOCK plus == 32 for vocab=1 and == _MERGE_BLOCK for 262144. Saves ~8 table rows and the formula duplication.

F3 (medium) ignition/components/logprobs.py:25-26 now _REDUCTION_WARPS = 4 / _MERGE_WARPS = 4 — the PR dropped _MERGE_WARPS 8->4 (undescribed) so the distinction is vacuous; collapse to one _WARPS = 4 used at :177,:179,:181,:185. Same file :24 assert _MERGE_BLOCK > _TILE_CANDIDATES and (_MERGE_BLOCK & (_MERGE_BLOCK - 1)) == 0 is a tautology over two module literals (512 vs 32) that can never fire and is stripped under -O; delete, keep the comment at :21-22.

F4 (low, verify on GPU) logprobs.py:141-147 if total > BLOCK: guard is redundant — total/step/BLOCK are constexpr so for offset in range(BLOCK, total, step) is already empty (and unrolls to nothing) when total<=BLOCK; deleting the if and dedenting 5 lines removes one nesting level.

Non-findings: width de-specialization genuinely deletes 6x specializations; no flags/knobs/fallback paths added; _sort_key/_sort_pair/_position/_merge and the constructor/scratch layout untouched; pos = row.to(tl.int64) * width + col repeated 4x (:66,:83,:101,:121) is marginal (Triton helper would inline) and not worth a review objection.

#2 [high] Research summary

Subtraction/Simplicity review of PR #673 (2 files: ignition/components/logprobs.py +39/−22, tests/components/test_logprobs.py +278 new). Scratchpad entry 1 holds the four findings.

The core of the diff is genuinely subtraction, not addition: converting WIDTH: tl.constexpr to a runtime width deletes six specializations per kernel rather than adding a knob, and the chunked merge reuses the existing tl.sort/_sort_key/_sort_pair instead of introducing a new top-k helper. No flags, config switches, fallback paths, dead code, or duplicate abstraction were added; _position, _merge, the scratch layout, and the constructor are untouched. So the verdict is "close to lean", with four concrete trims:

  1. High — the doc the change contradicts is left stale. docs/logprobs-design.md:92-95 still says "Tiles retain their best 32 integer sort keys; a final merge stores K pairs", describing the pre-PR single 8192-key sort and nothing about width-independent kernels; AGENTS.md:232 routes logprob changes through that doc. Replace those two sentences.
  2. High — the CPU merge-block test restates the implementation formula and pokes private internals. tests/components/test_logprobs.py:49-68 hard-codes all eight {32, 64, 512} points of min(next_power_of_2(cdiv(vocab,1024)*32),512) and asserts through dict(zip(_finish.arg_names, op._preparation[3][1], strict=True)). Two or three boundary cases asserting the bound (== 32 at vocab 1, == _MERGE_BLOCK at 262144, <= _MERGE_BLOCK) cover the property; AGENTS.md:194-199 rejects checks that only restate source.
  3. Medium — two leftover constant pairs. _REDUCTION_WARPS = 4 / _MERGE_WARPS = 4 are now identical (the 8→4 merge-warps drop is undescribed), so collapse to one _WARPS = 4; and the module-level assert _MERGE_BLOCK > _TILE_CANDIDATES and (_MERGE_BLOCK & (_MERGE_BLOCK - 1)) == 0 is a tautology over two literals (512 vs 32) that can never fire, is stripped under -O, and duplicates the comment above it — delete the assert, keep the comment.
  4. Low (verify on GPU first) — if total > BLOCK: at logprobs.py:141 is redundant; total, BLOCK, step are all tl.constexpr, so for offset in range(BLOCK, total, step) already unrolls to nothing when total <= BLOCK. Deleting the guard and dedenting five lines removes a nesting level and makes the loop the single source of the chunking rule.

Explicit non-findings: the four repeated pos = row.to(tl.int64) * width + col lines (:66,:83,:101,:121) are not worth a helper (a Triton-jit helper would inline to the same code); keeping the requested-IDs branch untouched is correct.

#3 [high] Verbatim citations + verdict for PR 673 subtraction review

Companion to entry 1. Exact verbatim citations, for the report.

F1 docs/logprobs-design.md:92-95 (unchanged by PR; now inaccurate): "Four prepared Triton launches reduce requested positions. Vocabulary tiles first compute FP32 maxima and exponential sums, then a small reduction writes each position's normalization. Tiles retain their best 32 integer sort keys; a final merge stores K pairs and the chosen token. Keys rank the reported FP32 logprobs" -> Replace "Tiles retain their best 32 integer sort keys; a final merge stores K pairs and the chosen token." with: tiles retain 32 keys; the final launch sorts at most 512 keys and merges remaining candidates in 480-key steps, keeping the running top 32 after each sort; the four kernels take width at runtime so all speculative widths share one cubin. AGENTS.md:232 requires docs/logprobs-design.md for logprob changes.

F2 tests/components/test_logprobs.py:49-59 (parametrize table) and :66-68: " op = PreparedLogprobs(logits, completion, slots, epochs, live, frame) finish_args = dict(zip(_finish.arg_names, op._preparation[3][1], strict=True)) assert finish_args["BLOCK"] == expected_block" Table rows: (1,32),(64,32),(1024,32),(1025,64),(16384,512),(16385,_MERGE_BLOCK),(31744,_MERGE_BLOCK),(262144,_MERGE_BLOCK) == triton.cdiv(vocab,1024)*32 rounded/capped at :164. Suggested replacement: 2 cases (vocab=1 -> 32; vocab=262144 -> _MERGE_BLOCK) plus assert finish_args["BLOCK"] <= _MERGE_BLOCK; drops the formula duplication and 6 rows. Note it also couples to op._preparation[3][1], the tuple this PR edits at logprobs.py:176-186. AGENTS.md:194-199 ("source-text checks ... cannot establish runtime correctness").

F3a logprobs.py:25-26: "_REDUCTION_WARPS = 4 _MERGE_WARPS = 4" (two identical constants; PR changed _MERGE_WARPS 8->4 at diff line -_MERGE_WARPS = 8 / +_MERGE_WARPS = 4). Collapse to one _WARPS = 4 used at :177,:179,:181,:185. F3b logprobs.py:21-24: "# Merge per-tile candidates in bounded chunks so large vocabularies (e.g. 256k -> 8192 keys)

do not unroll an 8192-element bitonic network in Triton/PTX while keeping bit-exact ordering.

_MERGE_BLOCK = 512 assert _MERGE_BLOCK > _TILE_CANDIDATES and (_MERGE_BLOCK & (_MERGE_BLOCK - 1)) == 0" Tautology over two module literals (512 > 32, 512 power of two) - cannot fire, stripped under python -O, and restates the comment. Only module-level assert in ignition/ (grep for ^assert returns just this line + ignition/bench/runner.py:240 unrelated). Delete assert, keep comment.

F4 logprobs.py:141-147: " if total > BLOCK: step: tl.constexpr = BLOCK - CANDIDATES for offset in range(BLOCK, total, step): idx = offset + (k - CANDIDATES) incoming = tl.load(Keys + base + idx, (k >= CANDIDATES) & (idx < total), other=0) keys = tl.where(k < CANDIDATES, keys, incoming) keys = tl.sort(keys, descending=True)" total (:137) and step (:142) are tl.constexpr, BLOCK is constexpr => range(BLOCK,total,step) is statically empty when total<=BLOCK. Delete the if, dedent the loop. MUST verify on GPU (constexpr short-circuit semantics) before asserting; frame as conditional.

Non-findings to state: (a) @triton.jit(do_not_specialize=["width"]) matches existing repo pattern (ignition/components/engram.py:23, helios/tests/fixed_core_fixture.py:27,33) - idiomatic, no new dependency; (b) four-line pos = row.to(tl.int64) * width + col repetition (:66,:83,:101,:121) not worth a helper; (c) no dead code, flags, config knobs, or fallback branches added; _position/_merge/scratch layout/constructor untouched; scratch bytes and ABI unchanged; (d) new test file is the first test of these kernels, so it is net-new coverage rather than duplicated coverage.

Verdict: diff is close to lean; the substance is deletion (6 specializations per kernel) not addition. 4 trims above, 2 high-value (stale doc; over-specified private-internals test).