PR #673 — Bound PreparedLogprobs merge block and share kernels across speculative widths
Author: kbenkhaled (CONTRIBUTOR) · Branch: logprobs-chunked-finish → main · Head: 1337213 · Size: +317 / −22 in 2 files (ignition/components/logprobs.py +39/−22, tests/components/test_logprobs.py +278/−0, new) · State: open, ready for review, no labels, no reviewers, 0 CI checks, 0 comments.
Key findings
- The launch configuration changes for every vocabulary, not just 262k ones.
_MERGE_WARPSdrops 8 → 4 (logprobs.py:26) andmerge_block = min(next_pow2(tiles*32), 512)(logprobs.py:164), so a small vocabulary that used to launch_finishwith 8 warps now runs 4. The description frames the change only as "capped at 512 (4 warps)". _finishstill recompiles per vocabulary. The merge loop bounds aretl.constexpr(total: tl.constexpr = TILES * CANDIDATES,step: tl.constexpr = BLOCK - CANDIDATES,logprobs.py:137-147), so the loop is compile-time unrolled and at V=262,144 (256 tiles) still produces 16 extra unrolled sorts. Only width stops multiplying cubins — consistent with the "4 cubins instead of 24" claim, but the per-vocabulary compile cost is bounded, not removed.- 64-bit indexing is new on all four kernels' hot address path (
pos = row.to(tl.int64) * width + col,logprobs.py:66,83,101,121). It is defensive (no overflow at the shapes in play) and is not measured separately in the description. - No documentation is updated.
docs/logprobs-design.md:90-100still describes "Tiles retain their best 32 integer sort keys; a final merge stores K pairs", i.e. the pre-PR single merge, and says nothing about width-agnostic kernels. - All performance numbers are author-measured on two Jetsons, with nothing in CI. CI on head
1337213is empty; the only Python workflow is CPU-only (CUDA_VISIBLE_DEVICES: ""), so the CUDA half of the new test file can never gate this. - No issue or report requested this work. The motivation exists only in the PR body and in the author's broader Jetson small-memory campaign (#671, #669, #664).
- The change overlaps a documented measurement standard it does not meet.
docs/logprobs-design.md:128-130requires "complete replay and service measurements" for reduction performance claims; the PR reports isolated_finishµs and coldprepare()wall-clock, and lists end-to-endignition export/flare runas unmeasured. Charter line 42 asks for the SM103/SM120/SM121 matrix and a check that exported cores still load — both are explicitly unrun. - Process nits: PR body's
Discord:line is empty, whichAGENTS.md:144-153forbids (same nit was raised on the author's #671); notriage:reviewlabel and no Autobot case-file comment, unlike comparable performance PRs (#231, #652, #671).
The change
Two mechanisms, both in ignition/components/logprobs.py:
- Width de-specialization.
WIDTH: tl.constexprbecomes a runtimewidthargument with@triton.jit(do_not_specialize=["width"])in_statistics(logprobs.py:59-62),_normalization(:76-79),_candidates(:93-97) and_finish(:112-117). The row offset is promoted to 64-bit (logprobs.py:66,83,101,121). All widths now share one compiled cubin per kernel. - Chunked top-32 merge in
_finish. New constant_MERGE_BLOCK = 512with an assert that it exceeds_TILE_CANDIDATESand is a power of two (logprobs.py:21-24);_TILE_CANDIDATES = next_power_of_2(MAX_TOP_LOGPROBS) = 32,_VOCAB_TILE = 1024(:18-20).merge_block = min(next_power_of_2(tiles * _TILE_CANDIDATES), _MERGE_BLOCK)(:164) is passed as_finish'sBLOCK(:182-185)._finishsorts the first BLOCK keys, then merges further candidates inBLOCK - CANDIDATES(480) steps, keeping the running top 32 after each sort (:136-150).
Sizes and reach inside the file: _sort_key (:29-33), _sort_pair (:36-40), _position (:43-56), _merge (:248-261) and the rest of PreparedLogprobs are untouched. The scratch layout (stats, lse, keys, logprobs.py:167-173) and the constructor signature are unchanged, so scratch bytes and ABI are identical; only the _finish BLOCK/num_warps launch config and the four kernels' specialization keys change.
Wiring: PreparedLogprobs is constructed only from PreparedSampling.prepare() (ignition/components/sampling.py:539, with _logprob_args built at sampling.py:524); prepare/functional/run are used at sampling.py:540,607,635,679. CompletionOutputs constants (ignition/components/completion.py:15-23: MAX_TOP_LOGPROBS=20, MAX_LOGPROB_TOKEN_IDS=128, LOGPROB_FIELDS=258) are not changed. The module is one of the 13 retained core modules (tests/preparation/test_core_boundary.py:11-25).
Widths 1..6 come from outside the repo. PreparedSampling.__init__ requires 2-D logits (sampling.py:484-489) and PreparedLogprobs reshapes 2-D to logits[:, None, :] (logprobs.py:156-157), so every in-repo path is width == 1. Multi-width is exercised by scripts/benchmark_logprobs.py:19,33,67-69 (sweeps width 1 and 6 with 3-D logits) and by recipe-side construction in the external local-inference-lab/hyperflare-recipes package. PreparedSampling.prepare() compiles logprobs first (sampling.py:537-561), before _scores, _complete, _metadata, _sanitize, _normalize, _min_p and the FlashInfer workspaces — which is why its compile time sits at the front of a cold catalog build.
Under-declared behaviour difference: the requested-IDs branch (count > 0, logprobs.py:127-134) and the sorted branch (count == 0, :135-150) are gated exactly as before; only pos is now int64. Grid shapes and the [batch,width,tiles,32] uint64 Keys buffer are unchanged.
The why
No issue or report asks for this. Searches for logprob compile time, Triton specialization and slow preparation return no originating report; the problem is documented only by the author's own measurements (Orin Nano 8 GiB ~19.5 min for six _finish specializations; Thor cold prepare 65.40 s).
Why the problem is nonetheless real and structural: ignition/components/capacity.py:80-91 (not opened),160-169 builds speculative shapes/widths and ignition/direct/scheduler.py:207-209 (not opened) derives widths from every speculative graph signature, so a prepared core naturally multiplies per-width kernel variants — exactly what this PR collapses.
Prior art on the same invariant and the same symptom:
- #231 (open,
original-el8) states the underlying Triton rule ("memoizes compiled kernels by specialization and launch options only") and reports a real "preparation used undeclared programs" failure when specializations shift — a caution relevant to a PR that rewrites four kernels' specialization keys. - #652 (merged 2026-12-01, lukealonso) attacks the same export-size/load-time symptom from the export side (pruning unreferenced kernels from cubins; Orin Nano
Prepare kernels0.5 s → 0.1 s, 166.51 → 19.46 MiB uncompressed). Complementary, no file overlap.
Related work
items_touching("ignition/components/logprobs.py")over 180 days returns only #673. Nothing competes with, stacks on, or supersedes it, and nothing onmainhas changed the file since1fbcc3c.- Same-author, same-campaign siblings, all open, no shared files: #671 (Ignition preparation memory budgets for ≤16 GiB integrated devices), #669 (host-backed CUDA VMM fallback), #664 (single-plane BF16 offloaded embedding). #673 is the compile-time member of that Jetson series.
- Nearest topical neighbours: #555 (merged,
c9693765, intermediate batch capacities 6/12/24 — increases the number of prepared speculative shapes, i.e. the pressure this PR relieves) and #608 (merged,9a054b49, restored catalog validation and CPU Python tests — the reason the new CPU test becomes a real gate). - File history:
2a65f7f3derek "Report generation logprobs through prepared completion outputs" →7c805294derek "opt-in prompt logprobs" →48bae6bbderek "requested generation logprob token IDs" (addedMAX_LOGPROB_TOKEN_IDS/_merge) →bce032c0,5be93f8f,16bb710f,4a24d78a(lukealonso: scheduling overlap, ABI-6 completion buffers, Inductor temporaries) →13372138kbenkhaled (this PR). kbenkhaled is the first outside contributor to touch it. - Orientation-packet leads checked and not relevant: #616 (host prefix-cache prep on fragmented memory — matched on "prepare/minutes"), #549 (
requested_idstoken name), #647 (current_stream, export/signing), #644, #578, #642, #483, #332, #229, #637, #447, #82 (generic word matches, no shared file or mechanism). - Worth knowing: the community repeatedly uses top-20 logprob equality as its correctness oracle (#496, #429, #413, #140, #455; logprobs-as-instrument issues #118, #193, #14, #20) — precisely the guarantee this PR claims to preserve bit-for-bit.
Recent activity
ignition/componentsrecent ancestors:555db719(2026-11-30, lukealonso, #648 "Migrate ignition runtime patches and preparation onto public b12x contracts"),50c876df(#484 gridDim stride),9031847a,7745deea(#566 engram prefetch),4d957175,74618652(#557),c9693765(#555),966df82e(#482). The PR builds on that state:@triton.jit(do_not_specialize=...)resolves against whatever Triton/b12x stack #648 pinned, and the four-kernel prepare path inignition/preparation/triton.py:28-51is unchanged for these call sites.tests/componentsrecent:9a054b49(#608, 2026-11-29) restored CPU Python tests, which is why.github/workflows/python-cpu.yml:30-33(not opened) (pytest tests/ -q,CUDA_VISIBLE_DEVICES: "") will now run the new CPU test.- Nothing on
mainsince1fbcc3ctouches the changed files: the change is additive on top of derek's Oct-2026 logprob series and lukealonso's ABI-6 work, reversing nothing.
People
- kbenkhaled (CONTRIBUTOR): 1 merged in 180 days — #592 "Add sm110/thor identifiers" (2026-11-29), i.e. the very SM110 Thor whose numbers this PR reports; 3 open Jetson/memory PRs (#671, #669, #664). Merged areas so far: docs, ignition, ignition/cli, ignition/preparation, tests/preparation — this is their first change to
ignition/components/andtests/components/. Pattern from #671: live-hardware measurement tables, large validation sections, twice "Changes Requested" by Autobot for unvalidated floors/unrun tests/no CI on head, and the same emptyDiscord:line. - Area owners (last 180 days):
ignition/components— lukealonso 108, Martin Vit 58, jasonc 26;tests/components— lukealonso 116, Martin Vit 39, Jason Cook 8.logprobs.pywas authored by derek and is maintained by lukealonso; lukealonso is the natural reviewer, and derek is the author of the merge semantics being changed. - Engagement so far: none — no comments, reviews, labels, or reactions (see Community).
Community
Zero engagement. read_item(673) shows "Discussion (0)"; pr_comments returns no comments; opened and last updated at 2026-12-02 04:42 (one push, no follow-ups). No labels, whereas sibling #671 carries area:memory, area:preparation, enhancement, performance, triage:review. No Autobot case-file comment appears on #673, unlike #231, #652 and #671 — triage has not engaged. Comparable performance PRs in this repo all show an Autobot case-file + review thread, so the silence here reads as age rather than objection.
Project fit
- Charter line 12 ("Keep the runtime small and model-agnostic… shouldn't accumulate per-model branches"): the change is a shared ignition component with no model branch, no flag, no config, no new dependency — aligned.
- Charter line 21 ("Prepare supported model recipes… on SM103, SM120, and SM121"): the PR's limitations say SM103/SM120/SM121 were not measured — the roadmap's named targets were not exercised.
- Charter line 42 ("Check interactions across every supported… hardware target named in the docs… verify that existing data, artifacts, and exported cores still load"): CUDA-graph capture/replay is covered by a new test, but exported-core load and the hardware matrix are unrun. Charter line 28 lists broad coverage of arbitrary GPUs as a non-goal, so untested arches are a stated limitation rather than a scope violation.
AGENTS.md:165-169allows "a demonstrated defect, a measured performance or memory problem, or inaccurate documentation" as a contribution basis — this PR rests on a measured performance problem.AGENTS.md:176-186bans runtime compilation and weakened guarantees: the change removes pre-capture compilation work and claims bit-identical output with tests (aligned, subject to verification).docs/core-design.md:1276-1279: "Bounded top-k optimization is not implemented. Measure sampler cost inside the complete graph before changing it; threshold ties must never be truncated to a fixed number of candidates." The PR measures_finishoutside the complete graph, but keeps 32 candidates across chunk boundaries rather than a fixed 32 overall, so the tie constraint is respected (and the new CUDA test plants >32 ties straddling boundaries).docs/logprobs-design.md:128-130: "Performance claims about the reduction require complete replay and service measurements." The headline numbers are cold-prepare()wall-clock and isolated_finishµs — a direct, quotable mismatch with the project's own measurement standard.- Documentation lag:
docs/logprobs-design.md:90-100still describes the pre-PR single 32-key merge and four launches;docs/api.md:38 (not opened),107-122(tie ordering: decreasing logprob, then increasing token ID) remains accurate but unrevised.
Claims and evidence
| Claim | Evidence in PR | Independent / reproducible? |
|---|---|---|
Cold prepare() Thor SM110 65.40 s → 4.46 s (14.7×) |
author-measured, no artifacts | No: needs a Jetson plus 3-D logits; scripts/benchmark_logprobs.py is the in-repo harness and is not cited |
Cold prepare() Orin Nano 8 GiB SM87 ~19.5 min → 11.83 s (~100×) |
author-measured | No |
_finish 84.2 µs → 38.2 µs at width 6, V=262,144 |
author-measured | No; the PR also states Orin Nano's old BLOCK=8192 runtime latency was not measured |
| "4 logprob cubins instead of 24" | new CUDA test asserts all four kernels' compiled.hash match across widths (1,2,6,16) |
Partly: ignition/preparation/triton.py:28-51 exposes .compiled, but no export was run |
| "bit-for-bit identical output" | new CUDA tests compare to a torch reference (_reference_logprobs, stable descending argsort) over vocab 1..262,144, BF16 and FP32, plus +0.0/-inf/<20 padding and requested-ID/NaN cases |
Yes in principle, but only with FLARE_RUN_CUDA_TESTS=1 on a GPU; the author's raw-int32 equality vs 1fbcc3c9 and bit-exact compile_forward() at widths 1 and 4 are not reproducible from the PR contents |
| "87 passed, 0 failed" on Thor and Orin Nano | none in CI | No: 0 checks on head 1337213; no GPU workflow exists in the repo |
compile_forward / wrap_triton (ignition/preparation/triton.py, as in #648) is what makes the shared cubin serve the compiled path the description says it verified.
Reach
- Users/operators: faster cold preparation of speculative models, especially on 8 GiB Jetsons; no CLI flag, default, manifest or exported-core format change (
_mergeatlogprobs.py:248-261, buffers, dtypes and shapes untouched), so previously exported cores still load and their size is unchanged until re-export. - Runtime latency: improved at V=262,144 per the author; small-vocabulary
_finishnow launches 4 warps instead of 8 (unmeasured), and no old-BLOCK=8192comparison was made on Orin Nano. - Dependencies: relies on Triton supporting
do_not_specialize=[...](already used atignition/components/engram.py:23(not opened) andhelios/tests/fixed_core_fixture.py:27 (not opened),33) — no new library. But the specialization key feeds Triton's program-cache identity, and #231 documents a preparation failure ("undeclared programs") when that identity shifts, so a stale on-disk Triton cache after upgrade is a plausible operator-visible side effect. - Downstream: recipes in
local-inference-lab/hyperflare-recipesconstructPreparedSampling/PreparedLogprobs; the constructor and methods are unchanged, so no recipe change is required (stated as "no runtime core format or ABI changes"). - Documentation: nothing updated; operators reading
docs/logprobs-design.mdstill see the pre-PR merge description.
Process
- Draft/ready: ready for review, base
main, head1337213, opened 2026-12-02 04:42 and last updated the same minute — a single push. - CI: 0 checks.
.github/workflows/python-cpu.yml(not opened) (on: pull_request) would runpytest tests/ -q(the new CPU test only) plus heliopause Rust tests; no GPU job exists. - Review: none. No reviewers requested, no labels (no
triage:review,performance,area:kernels), no Autobot case-file comment. - Convention breach: empty
Discord:line (AGENTS.md:144-153requires a handle or the literalDiscord: no username provided; "Never omit the line") — the same nit was raised on #671. - Test-design note: the new CPU test asserts on private internals — zipping
_finish.arg_nameswithop._preparation[3][1]and expecting BLOCK{32,32,32,64,512,512,512,512}for vocab{1,64,1024,1025,16384,16385,31744,262144}— coupling it to the_preparationtuple layout this same PR edits (logprobs.py:176-186). The CUDA width-sharing test covers widths (1,2,6,16) at V=262,144 only; ordering tests use batch 3 / width 6 at one vocabulary each; nothing exercises_mergeincompletion.py, and nothing checks thatdo_not_specializebehaves the same under a different Triton version. - Coverage change worth noting:
tests/components/test_logprobs.pyis the first direct test of_statistics/_normalization/_candidates/_finish; before this PR no file tested them (tests/components/test_completion_outputs.pycoversCompletionOutputsbuffers and merge, not the kernels). The "87 passed" figure is therefore largely the new file. - Risk framing: small and localized, but it rewrites the specialization identity of four kernels used in every prepared speculative core and changes a merge the docs describe as a single sort; the sharpest review focus is the chunk-index arithmetic (
logprobs.py:136-150) against the tie contract indocs/logprobs-design.md:92-100anddocs/api.md:107-112(not opened).
Open questions / not found
- No issue, report, or user request motivates the change; there is no external corroboration of the compile-time pain beyond the author's measurements.
- The multi-width benchmark (widths 1..6) cannot be reproduced from this repo alone: in-repo logits are 2-D (
width == 1); it needsscripts/benchmark_logprobs.py-style 3-D logits, the external recipe package, and a Jetson. - SM103/SM120/SM121, an actual
ignition export+flare runend-to-end run, loading an already-exported core, and Orin Nano's oldBLOCK=8192latency are all unmeasured. - No evidence was found either way on whether the 4-warp
_finishand int64 indexing regress small-vocabulary latency. - Whether a doc update is required before merge (the description meets
AGENTS.md:194-199's "problem, behavior, validation, limitations" butdocs/logprobs-design.mdis now stale) is a maintainer call, not something the repository states.