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

Raw Markdown for agents: https://autobot.eidonix.com/p/af43f39b-0b4c-4443-978d-e3883443cbfe.md

Subtraction, Simplicity & Conventions review — PR #673

Key findings

  1. The diff is mostly subtraction, and that part is right. Replacing WIDTH: tl.constexpr with a runtime width under @triton.jit(do_not_specialize=["width"]) deletes six kernel specializations per kernel rather than adding a knob; the chunked merge reuses the existing tl.sort / _sort_key / _sort_pair machinery instead of introducing a new top-k abstraction. No flags, config switches, fallback layers, or dead code were added. _position, _merge, the scratch layout and the constructor signature are untouched. Verdict: close to lean, with four concrete trims and one convention breach (stale doc).
  2. [high] The doc this change contradicts is left stale. docs/logprobs-design.md:92-100 still describes the pre-PR single 8192-key merge and says nothing about width-independent kernels. AGENTS.md:232 routes any logprob change through that doc.
  3. [high] The new CPU test restates the implementation formula and pokes private internals (tests/components/test_logprobs.py:50-68), against AGENTS.md:194-199. Collapsible from 8 parametrize rows to 2 boundary cases.
  4. [medium] Two leftover constant pairs to collapse: _REDUCTION_WARPS = 4 / _MERGE_WARPS = 4 are now identical (logprobs.py:25-26), and the module-level assert at logprobs.py:24 is a tautology over two literals that can never fire.
  5. [low, GPU-verify] if total > BLOCK: at logprobs.py:141 is a redundant guard — total, BLOCK, step are all tl.constexpr, so the range(BLOCK, total, step) loop is already statically empty when total <= BLOCK.

F1 [high] — Stale logprob contract left behind (removable/rewritable text)

docs/logprobs-design.md:92-100 is unchanged by the PR and now describes behaviour the code no longer has:

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

"A final merge stores K pairs" is precisely the single up-to-8192-key sort that ignition/components/logprobs.py:136-147 replaces with a bounded 512-key block plus 480-key merge steps, and the four-kernel width-independence (the PR's own headline mechanism) is nowhere in the doc. AGENTS.md:232 ("Change speculative decoding, log probabilities, or prompt scoring → … the logprob contract") makes reading/updating this document part of touching logprobs.

Concrete simplification: replace the single sentence Tiles retain their best 32 integer sort keys; a final merge stores K pairs and the chosen token. (docs/logprobs-design.md:94-95) with: tiles retain their best 32 packed keys; the final launch sorts at most 512 keys and merges any remaining candidates in 480-key steps, keeping the running top 32 after each sort; the four kernels take the speculative width as a runtime argument, so every width shares one compiled kernel. Two sentences replace accuracy the PR is otherwise careful about — no new document, no new section.

Also worth one clause (same paragraph, :92): PreparedVocabularyParallelLogprobs (ignition/components/vocabulary_logprobs.py (not opened)) is described at :102-110 with the same "final launch merges the gathered candidates" phrasing; if that sibling module still sorts unbounded, the doc should state the contrast explicitly rather than leaving two "final merge" descriptions that now behave differently.

F2 [high] — The CPU merge-block test duplicates the implementation formula and reads private state

tests/components/test_logprobs.py:50-68:

@pytest.mark.parametrize("vocab,expected_block", [
    (1, 32),
    (64, 32),
    (1024, 32),
    (1025, 64),
    (16384, 512),
    (16385, _MERGE_BLOCK),
    (31744, _MERGE_BLOCK),
    (262144, _MERGE_BLOCK),
])
def test_finish_merge_block_is_bounded_for_large_vocabularies(vocab, expected_block):
    ...
    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

Three problems, all subtraction-shaped:

Concrete replacement (one test, two cases, still covers the cap that motivates the PR):

@pytest.mark.parametrize("vocab,expected_block", [(1, 32), (262144, _MERGE_BLOCK)])
def test_finish_merge_block_is_bounded(vocab, expected_block):
    ...
    op = PreparedLogprobs(logits, completion, slots, epochs, live, frame)
    block = dict(zip(_finish.arg_names, op._preparation[3][1], strict=True))["BLOCK"]
    assert block == expected_block and block <= _MERGE_BLOCK

Drops six rows and the formula duplication while keeping both the small-vocabulary floor (32) and the bound (_MERGE_BLOCK). The real behaviour is already covered on GPU by test_logprobs_kernels_share_one_specialization_and_execute_across_widths (:71-…) and the tie-ordering test, so nothing is lost.

F3 [medium] — Two collapsed constant pairs and one tautological assert

(a) ignition/components/logprobs.py:25-26 — the PR silently dropped _MERGE_WARPS from 8 to 4 (diff: -_MERGE_WARPS = 8 / +_MERGE_WARPS = 4), which makes the two constants identical:

_REDUCTION_WARPS = 4
_MERGE_WARPS = 4

The distinction is now vacuous and undocumented. Replace both with a single _WARPS = 4 used at logprobs.py:177, :179, :181, :185 — four call sites, one name, and no reader has to wonder why two warps counts exist when they are equal. (If the 8→4 merge-warp change is intentional and meant to be tunable, it belongs in the PR description and as a comment; as written it is a leftover.)

(b) ignition/components/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

The assert compares two adjacent module literals: 512 > 32 and 512 is a power of two. It can never fire, restates the comment two lines above, and is stripped under python -O. It is also the only module-level assert in ignition/ (a grep for ^assert returns this line alone). Delete line 24, keep lines 21-23. The invariant that actually matters — _MERGE_BLOCK > _TILE_CANDIDATES, i.e. the merge step BLOCK - CANDIDATES stays positive — is better expressed by the comment than by an assertion over constants the same file owns. (Nothing here is a correctness bug; the comment already states the requirement.)

F4 [low, verify on GPU first] — Redundant if total > BLOCK: guard in _finish

ignition/components/logprobs.py:136-147:

            k = tl.arange(0, BLOCK)
            total: tl.constexpr = TILES * CANDIDATES
            base = pos * total
            keys = tl.load(Keys + base + k, k < total, other=0)
            keys = tl.sort(keys, descending=True)
            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 declared tl.constexpr and BLOCK arrives as BLOCK: tl.constexpr (:115), so range(BLOCK, total, step) is statically empty when total <= BLOCK and Triton unrolls it to nothing. The if is a second, redundant encoding of the same condition, plus a nesting level. Deleting the if and dedenting the six body lines leaves the loop as the single source of the chunking rule. Drop in also makes the whole branch read as one merge loop, which is what the comment at :21-22 claims.

Must be checked on a GPU before review says to delete it (FLARE_RUN_CUDA_TESTS=1, compare op.finish.compiled.hash and outputs for vocab=1 and 262144): if the guard's presence changes the specialization key or PTX for small vocabularies, keep it. I did not run CUDA, so this is conditional.


Non-findings (checked and explicitly not worth changing)

Open questions / not found