PR #673: Bound PreparedLogprobs merge block and share kernels across speculative widths

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/c85b6388-2337-44d6-b766-0e60348306fe

Opened by a workflow run, Dec 1, 2026 11:43 PM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: kbenkhaled (CONTRIBUTOR; no Discord handle — the PR's Discord: line is empty, which AGENTS.md forbids) Motivation: Preparing a speculative model compiled each of four logprob Triton kernels once per speculative width and sorted every tile candidate at once, which took ~19.5 minutes on an 8 GiB Jetson Orin Nano. The PR makes the kernels width-agnostic and merges candidates in bounded 512-element chunks so preparation is faster without changing output. Scale: +317 / −22 lines in 2 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #673 (PreparedLogprobs bounded merge block, width-agnostic kernels)

Charter alignment. The change sits in one shared ignition component with no model branch, no flag, no new dependency, and no ABI/scratch-layout change — consistent with "keep the runtime small and model-agnostic" and "solve the right problem in the right place." It rests on a measured performance problem, which the contribution rules accept as a basis. Two frictions: the multi-width benefit is reachable only through out-of-repo 3-D logits (scripts/benchmark_logprobs.py, the external recipes package — in-repo paths are width == 1), and the roadmap's named targets SM103/SM120/SM121 plus "existing exported cores still load" are explicitly unrun.

Novelty & status. Genuinely additive. items_touching(logprobs.py) over 180 days returns only #673 and nothing on main has changed since 1fbcc3c — not obsolete. #652 (merged) attacks the same export-size/load-time symptom from the export side, has no file overlap, and is complementary rather than superseding; the merged #555 (intermediate batch capacities) actually increases the speculative-shape pressure this relieves.

Value vs maintenance cost. Beneficiaries are operators building cold speculative catalogues, most acutely on 8 GiB devices: 65.40 s → 4.46 s (Thor, SM110) and ~19.5 min → 11.83 s (Orin Nano, SM87), 4 cubins instead of 24. Complexity is small and localized (+39/−22), and the new 278-line test file is the first direct test of _statistics/_normalization/_candidates/_finish — durable value independent of the optimization, on a top-20 logprob equality guarantee the community already uses as its correctness oracle.

The evidence is nonetheless author-measured only: 0 CI checks on 1337213, the sole Python workflow is CPU-only, so the CUDA half can never gate this. The headline numbers are isolated _finish µs and cold prepare() wall-clock, which docs/logprobs-design.md:128-130 explicitly rules insufficient ("complete replay and service measurements"). _finish still unrolls per vocabulary (16 extra sorts at V=262,144), so compile cost is bounded, not removed. Three behaviours are unmeasured: the _MERGE_WARPS 8→4 launch change that now applies to every vocabulary, the new int64 hot-path indexing, and Orin Nano's old BLOCK=8192 latency. do_not_specialize rewrites four kernels' specialization identity, and #231 documents "undeclared programs" failures when that identity shifts. docs/logprobs-design.md:90-100 is stale, and the Discord: line is empty (the same nit raised on #671).

Before merge: served/replay measurement per the documented standard; one target-matrix or exported-core-load check; small-vocabulary regression data for the 4-warp launch and int64 indexing; a docs/logprobs-design.md update; Discord: filled in.

Verdict: Worth it with changes. Right layer, plausible magnitude, one file, first real kernel tests — but the served-workload evidence, hardware matrix and doc update the charter requires must land first.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: triage:review, performance, area:kernels

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +performance, +area:kernels

Subtraction and simplicity

Subtraction/Simplicity review of PR #673 (ignition/components/logprobs.py +39/−22, new tests/components/test_logprobs.py). The core is genuine subtraction — a constexpr WIDTH becomes a runtime width under do_not_specialize, deleting six specializations per kernel, and the chunked merge reuses the existing tl.sort/_sort_key machinery. No flags, fallbacks, or dead code added. Four trims:

  1. [high] Stale contract: docs/logprobs-design.md:92-100 still says "Tiles retain their best 32 integer sort keys; a final merge stores K pairs", describing the pre-PR 8192-key sort and omitting width-independence; AGENTS.md:232 routes logprob changes through this doc. Rewrite two sentences.
  2. [high] tests/components/test_logprobs.py:50-68 hard-codes all eight points of min(next_power_of_2(cdiv(vocab,1024)*32),512) and asserts via dict(zip(_finish.arg_names, op._preparation[3][1])); AGENTS.md:194-199 rejects such source-restating checks. Replace with two cases (vocab 1 → 32, 262144 → _MERGE_BLOCK, plus <= _MERGE_BLOCK).
  3. [medium] logprobs.py:25-26 _REDUCTION_WARPS = 4 / _MERGE_WARPS = 4 are now identical (the 8→4 drop is undescribed) — collapse to one _WARPS; and logprobs.py:24's module-level assert is a tautology over two literals (512 > 32, power of two) that can never fire — delete, keep the comment.
  4. [low, GPU-verify] logprobs.py:141 if total > BLOCK: is redundant since total/step/BLOCK are constexpr; the range() is already empty when total <= BLOCK. Delete the guard and dedent six lines, after confirming no cubin/hash change.

Non-findings: repeated pos = row.to(tl.int64) * width + col (:66,83,101,121) not worth a helper; do_not_specialize matches existing idiom (engram.py:23 (not opened)); no dead code or knobs; constructor/scratch/ABI untouched; the new test file is first-ever coverage of these kernels.

Open: whether the merge-warp 8→4 change was measured; whether vocabulary_logprobs.py (not opened) shares the unbounded final sort (follow-up, worth docs/TODO.txt).

Full report · Notes

Correctness and contracts

Reviewed PR #673 (ignition/components/logprobs.py +39/−22, new tests/components/test_logprobs.py). No correctness defect found: the chunked top-32 merge is exact (proved by induction over the 480-slot centre), argument positions, scratch layout, ABI/export path, gating and tie ordering are all unchanged, and existing exported cores keep loading.

Findings, highest first:

  1. Major — evidence covers one vocabulary for a change reaching every V ≥ 16,385 (logprobs.py:164, main logprobs.py:166): main passed the unbounded next_power_of_2(tiles*32) (1024…8192 keys); the only measured point is V=262,144 (84.2→38.2 µs). No 32k/128k data, though those are what Flare serves locally.
  2. Major — _MERGE_WARPS 8→4 (logprobs.py:26) changes _finish's warp count for every vocabulary, including the ≤16,384 path where BLOCK is unchanged, and is framed only as part of the 512 cap with no measurement.
  3. Major — stale contract doc: docs/logprobs-design.md:90-100 still describes a single 32-key merge and says nothing about width-agnostic kernels, though AGENTS.md:232 names it as the required doc for logprob changes.
  4. Major — no CI-gating test can catch a merge regression: all three behavioural tests are FLARE_RUN_CUDA_TESTS-gated (test_logprobs.py:71,122,210) and CI runs with CUDA_VISIBLE_DEVICES: ""; the only CI-visible test asserts a private BLOCK int (test_logprobs.py:60-68).
  5. Minor — _finish is still vocabulary-specialized (TILES: tl.constexpr, logprobs.py:114,137-143): the merge loop unrolls 17 sorts at V=262,144; the bound is per sort block, not per vocabulary.
  6. Minor — CPU test couples to the private _preparation[3][1] tuple (test_logprobs.py:67) that this PR itself edits.
  7. Minor — process: empty Discord: line (AGENTS.md:144-153) and unmeasured items not recorded in docs/TODO.txt (AGENTS.md:57-58).

I verified and retract the misattribution suspicion: the 84.2→38.2 µs row is genuinely attributable to the chunked merge.

Open: no measurement of small/medium vocabularies at 4 warps; SM103/120/121 and an exported-core run remain unmeasured by the author's own admission.

Full report · Notes

Final review

Recommendation: Changes Requested

The kernel changes in ignition/components/logprobs.py are mathematically sound, bit-exact, and address a real speculative-decoding preparation bottleneck (~15×–100× faster cold prepare() by collapsing per-width cubins and bounding _finish's bitonic sort block), backed by the repository's first direct unit and CUDA tests for these kernels. No correctness, ABI, or CUDA-graph capture defects were found. However, before merge, the runtime launch changes that apply across all vocabularies (_MERGE_WARPS 8→4 for every V, chunked serial sorts for V >= 16,385) need before/after latency coverage beyond the single V = 262,144 / width = 6 point (plus complete-replay/exported-core validation per docs/logprobs-design.md:129-130), the PR description should make the 8 → 4 warp transition explicit, and CPU CI needs to run on head 1337213.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

  1. Measure the unmeasured runtime regimes and document the full before/after launch change (ignition/components/logprobs.py:23-26, 137-147, 164):
    • Verified behavior & impact: Two independent launch changes apply well beyond the single measured point (V = 262,144, width = 6):
      1. _MERGE_WARPS changed from 8 to 4 (ignition/components/logprobs.py:26 vs main:22), affecting every vocabulary—including V <= 16,384 where BLOCK is unchanged—while the PR description only mentions 4 warps inside the 512 cap bullet without stating the 8 → 4 transition.
      2. merge_block = min(triton.next_power_of_2(tiles * _TILE_CANDIDATES), _MERGE_BLOCK) (ignition/components/logprobs.py:164) replaces a single 1024..4096-key sort with 2..9 serial 512-key sorts for every V >= 16,385 (e.g., 9 serial sorts at V = 131,072). None of V <= 16,384, 32k–128k, or width = 1 are measured before/after, and docs/logprobs-design.md:129-130 specifies: "Performance claims about the reduction require complete replay and service measurements."
    • Concrete fix:
      • Add before/after CUDA-graph latency measurements (e.g. using the in-repo scripts/benchmark_logprobs.py harness at width in (1, 6)) covering representative small (<= 16,384), mid (~128k), and 262,144 vocabularies, plus a complete replay or exported-core check (docs/logprobs-design.md:129-130, docs/performance-work.md:45-51), or explicitly bound the runtime speedup claim to the measured V = 262,144 case while tracking unrun SM103/SM120/SM121 and exported-core checks in docs/TODO.txt (AGENTS.md:57-58).
      • Update the PR description's "What changed" section (AGENTS.md:88-94) to explicitly note the _MERGE_WARPS 8 → 4 change (affecting all vocabularies) and clarify that _finish remains specialized per vocabulary via TILES: tl.constexpr (collapsing only the width dimension).
      • Ensure CPU CI (.github/workflows/python-cpu.yml (not opened)) runs and passes on the PR head before merge.

Subtract / Simplify

  1. Drop tautological module-level assert (ignition/components/logprobs.py:24):
    • assert _MERGE_BLOCK > _TILE_CANDIDATES and (_MERGE_BLOCK & (_MERGE_BLOCK - 1)) == 0 checks two adjacent module literals (512 and 32), is the only top-level assert in ignition/, cannot fail at runtime, and is stripped under python -O. Deleting line 24 leaves the concise comment at lines 21–22 intact.

Nits

Dropped on verification

Full report

Classify triage

Selected: triage:validation

Threshold: 65%

Triage

Apply labels

Applied: +triage:validation, -triage:review