Case file — PR #684: perf(sampling): collapse per-row PreparedSampling loop to 1 row-independent FlashInfer launch
Head 6991986, base main (2acc3f3), open, "ready for review", +19/−9 in 2 files, no labels, no reviews, no comments, no CI checks on head. Author lukealonso (COLLABORATOR).
Key findings
- The change is a swap of mechanism inside one helper, and it also leaves the file self-contradictory.
_filter_scoresnow makes one batched call (ignition/components/sampling.py:596-597), but thePreparedSamplingclass docstring still says "Each row uses a separate FlashInfer call … CUDA's Philox subsequence is therefore zero regardless of packed row or physical slot" (ignition/components/sampling.py:467-469). The PR description does not mention docs at all, and the diff touches neither the docstring nor the two design docs. - Two documents encode the old rule as the contract, and one anticipates this exact change.
docs/core-design.md:1289-1294states "Each request uses a one-row draw with Philox subsequence zero … so batch packing cannot change its random stream" — now false as written.docs/mtp-design.md:486-490says to use one-row calls "unless a library API supplies an equally qualified request-keyed stream", i.e. it authorises this change while its statement about the ordinary decode sampler goes stale. Neither is updated. - The declared merge prerequisite has no artifact in the repo to change. The PR says "Merge
local-inference-lab/flashinfer#208and update the FlashInfer pin before merging this PR." There is no pin:pyproject.toml:47declaresflashinfer-python = { git = "...flashinfer.git", branch = "main" }, and nouv.lockexists in the tree. The ordering requirement is therefore enforced by nothing, andsample_probabilities_outcallstorch.ops.flashinfer.sampling_from_probs_outwith a positional schema that lives entirely upstream (ignition/components/flashinfer_sampling.py:41-47). - The headline claim is a component node count with no reproducible or CI-backed measurement, and the project's own measurement doc prescribes exactly what was not run.
docs/performance-work.md:37-47requiresqualify.gpu_replayfor complete GPU graph duration "including … sampling" and verification "through an exported core loaded byflare run CORE --embedding-table-storage ram";docs/core-design.md:1276-1279says "Measure sampler cost inside the complete graph before changing it". The PR states whole-modelflare runlatency was not measured, no full-model core export was run, and thequalificationCargo feature was unavailable locally. - The property the change relies on is covered by a test that never runs in CI.
test_native_flashinfer_rng_is_invariant_to_capacity_packing_and_physical_slot(tests/components/test_sampling_flashinfer.py:183-205) assertslen(set(sampled)) == 1across rows 1/2/4 and slot rotations — but the module is skipped unlessFLARE_RUN_CUDA_TESTS=1(:28-31), and CI runs.venv/bin/python -m pytest tests/ -qwithCUDA_VISIBLE_DEVICES: ""(.github/workflows/python-cpu.yml:30-33(not opened)). No workflow setsFLARE_RUN_CUDA_TESTS. - The charter's perf-PR bar is not met by the PR's own account. Charter How We Work: "Performance PRs need benchmarks showing an actual speedup over
mainon a served workload (#210)." The PR offers an "Expected serving effect" and explicitly declines the served benchmark. sample_probabilitiesis now dead code (with its newrow_independent_rngkwarg andreturn_valid): a repo-wide search finds only the definition atignition/components/flashinfer_sampling.py:35and no caller.- Process anomaly: no CI checks and no Autobot case file on #684, while sibling PRs #658 and #673 by different/authors received case files within minutes of opening.
The change
Size: 2 files, +19/−9. Full diff read.
ignition/components/flashinfer_sampling.py
sample_probabilities(probabilities, seed, offset, return_valid=False, *, row_independent_rng=False)(:35-38) — new keyword forwarded tosampling.sampling_from_probs. No caller remains in-tree.- New
@torch.compiler.allow_in_graph def sample_probabilities_out(probabilities, samples, valid, seed, offset, *, row_independent_rng=False)(:41-47): callssampling.get_sampling_module()for its side effect, thentorch.ops.flashinfer.sampling_from_probs_out(probabilities, samples, valid, None, True, seed, 0, offset, 0, row_independent_rng)— all positional; the op schema is upstream, not in this repo. - Pre-existing
verify_chain(:50-54) already passesrow_independent_rng=Truewith the comment "Each row draws from its own seed and offset only, so its tokens do not depend on its batch slot" — the mechanism this PR extends to the plain sampler.
ignition/components/sampling.py
- Import switched to
sample_probabilities_out(:24-28). - In
_filter_scores, removedfor row in range(self._rows)with per-rowsample_probabilities(...)plusscratch["sampled_tokens"][row:row+1].copy_(sampled)andscratch["sample_valid"][row:row+1].copy_(valid); replaced by one call writing straight into the prepared buffers withrow_independent_rng=True(:596-597).
What the description does not say it also does / does not do:
- Does: makes
sample_probabilitiesunused; changes the dynamic path too, since_filter_scoresis shared by the captured path (__call__→_filter_scores(self.scratch_tensors),:599-607) and the functional/dynamic path (run→_filter_scores(scratch, local=True, row_inputs=...),:656-674). - Does not: update the class docstring (
:459-473),docs/core-design.md,docs/mtp-design.md, or thephilox4x32_referencedescription (sampling.py:236-242), whose documented law "FlashInfer samples from the first word … with an explicit offset of 4*counter" now rests on FlashInfer's new flag rather than on the one-row construction. - Behaviour preserved in the dead-row case:
_sanitize_scoreswrites a dummy one-hot (:304-312),_normalize_probswrites 1.0 at token 0 when mass ≤ 0 (:324-332), and_completeignores rows whose epoch/slot do not match (:363-378), so batching invalid rows does not inject NaN.
The why
- Stated problem: a per-row serialisation existed only because FlashInfer's
SamplingFromProbKernelmixed the thread-block indexbxintocurand_init, so a batched launch would have made a request's token depend on its batch slot. At capacityC=64that cost 64 kernel launches + 128 scalar copies = 192 sequential nodes per decode graph. - The constraint is documented as a project-level rule, not just a local workaround:
docs/core-design.md:1289-1294anddocs/mtp-design.md:486-490both state the one-row/Philox-subsequence-zero invariant. The per-row shape dates from the original prepared-sampling work (805531de"Share FlashInfer sampling and request state across model recipes",7f4a2aa0,ffae55ab, all Luke Alonso, 2026-10-10). - No linked issue or user report was found for this specific performance problem — the motivation is carried entirely by the PR body plus the design docs. The
row_independent_rngcapability is attested only by the PR description's reference tolocal-inference-lab/flashinfer#208(external; not verifiable from this repository). - How widely wanted: the sampler is the shared decode sampler for all recipes, so the cost was paid by every decode graph of every exported core;
docs/core-design.md:537listssampling.pyas the sampling component.
Related work
local-inference-lab/flashinfer#208(external, prerequisite). Addsrow_independent_rng: bool = FalsetoSamplingFromProbKernel,SamplingFromProbandtorch.ops.flashinfer.sampling_from_probs_out(as described). Not in this repo's copy; merge state unknown from here. Without it, both the new kwarg and the new call fail.- #658 (open, same author, 2026-12-01) edits the same file, different hunk: registers
DeviceRequestState.vocab_idswithrecord_numeric_tensor(sampling.py:125-131vs596-597). No textual conflict; the two are the only open work on the file, both by lukealonso. - #673 (open, kbenkhaled, 2026-12-02) reworks
ignition/components/logprobs.py(not opened) —PreparedLogprobs, the sibling componentPreparedSampling.prepare()constructs (sampling.py:543-544) and that runs in the same decode graph; same "cut launches/compile count" motivation, no file overlap. - #555 (merged, voipmonitor, 2026-11-27) added batch capacities 6, 12, 24 (
ignition/components/capacity.py:13), i.e. it multiplied the number of captured decode graphs per export and therefore the number of graphs that paid the old 192-node loop. This PR is the beneficiary of that change. - #479 (merged, voipmonitor, 2026-11-23) was the previous merged change to
sampling.py(static fused addend / gated gather, commite091689b); unrelated mechanism, same file. - Precedent inside the repo:
verify_chain'srow_independent_rng=True(flashinfer_sampling.py:50-54) — the pattern already trusted for speculative verification, now extended to plain sampling. - Nothing superseded or undone. No open PR competes for
_filter_scoresor the sampling launch; no commit onmainis reversed by this change.
Recent activity
mainhas not moved on the two changed files since the PR branched (2acc3f3): zero commits touching them after the branch point;search_historyconfirms the newest commit to each is the PR head itself.- Recent
ignition/componentscommits before this PR:555db719(2026-11-30, Luke Alonso, migrate runtime patches onto public b12x contracts, #648),50c876df(2026-11-28, Ricky Brent, state-transfer tiling),9031847a(2026-11-28, Luke Alonso),7745deea(2026-11-28, Martin Vit, Engram lookahead #566),4d957175(2026-11-27, Luke Alonso),74618652(2026-11-27, Martin Vit, #557),c9693765(2026-11-27, Martin Vit, #555),966df82e(2026-11-27, Martin Vit, #482). None sampling-launch-specific, so this change builds on a stable path rather than reversing recent work. - Branch name at head is
unify-b12x-moe-collective-and-recurr, unrelated to sampling (the author reuses branch names across PRs, e.g. #658's isfix/ga10b-export-preparation), so it conveys no stacking information.
People
- Author
lukealonso: COLLABORATOR; charter names@voipmonitor,@original-el8,@lukealonsoas priority contributors whose voice carries extra weight; AGENTS.md:376-381 names "project owner Luke Alonso lalonso@gmail.com" as the approver for new captured-graph operation families — so the author is the approver for this class of change. 38 merged PRs in 180 days, areas: helios/src (28), docs (23), ignition/preparation (12), flare-cli/src (10), heliopause/src (8). - Area ownership:
ignition/componentscommits over 180 days — Luke Alonso 108, Martin Vit 58, jasonc 26.sampling.pyhistory is overwhelmingly Luke Alonso; Martin Vit and Jason Cook have landed sampling-adjacent changes (#555 capacities,5e356e63#208 DeepSeek top-p,2a65f7f3logprobs). - Policy people a reviewer may expect to weigh in:
yatesdr(closed #215 and #210 — sets dependency and performance policy),original-el8(triage, dependency compatibility),flare-autobot(case files/reviews on most PRs). - Engagement so far: zero — no comments, no reviews, no labels, no reactions, no Autobot case file.
Community
Nothing found: no comments, reviews, or reactions on #684; no discussion elsewhere linking to it (search of the local copy for #684's subject returns no other item).
Project fit
Aligned:
- Placement: both edited modules are in the 12 Helios-ABI runtime interface modules that must stay in core
ignition(AGENTS.md:388-396; enforced bytests/preparation/test_core_boundary.py). No per-model branch, no user-facing flag, no new recipe. - "Prefer proven b12x operators and FlashInfer sampling over duplicate kernels" (AGENTS.md:404-409): using FlashInfer's out-variant is the sanctioned route rather than a local kernel.
- Graph boundary: AGENTS.md:420-425 forbids eager fallbacks and steady-state allocation; the change reduces graph nodes and writes into preallocated scratch.
docs/mtp-design.md:486-490explicitly allows a library API that "supplies an equally qualified request-keyed stream" in place of one-row calls.- Not a new captured-graph operation family: no protobuf, manifest, graph kind or recipe change, so AGENTS.md:376-381's approval rule is not triggered by a new contract (and the owner is the author).
In tension:
- "Performance PRs need benchmarks showing an actual speedup over
mainon a served workload (#210)" — not provided; the PR reports a component node count and an expected serving effect. - "Be explicit and pin everything … pin dependencies to exact versions or commits (#215)" and roadmap item "FlashInfer dependency fix (#215) … keeping builds strictly pinned" — the repo instead tracks FlashInfer
mainby branch (pyproject.toml:47, changed by Luke Alonso's10467f1a"Track FlashInfer main in pyproject.toml", 2026-11-20, afteryatesdrclosed #215 on 2026-11-19 with "Flare keeps the exact FlashInfer pin"). This PR's correctness rides on an unmerged upstream PR under that branch-tracking setup. docs/core-design.md:1289-1294(one-row draw contract) is now contradicted by the code;docs/mtp-design.md's description of the ordinary decode sampler is stale.
Claims and evidence
| Claim | Backing | Gap |
|---|---|---|
192 nodes → 1 launch; "23 total graph nodes for the entire PreparedSampling graph" at SM120, C=64, vocab=16384 |
PR body; measured with torch.cuda.CUDAGraph(keep_graph=True) |
Not reproducible from the repo; no committed script or test; node-count helpers in-tree exist only for exported cores, not component graphs |
| Bit-exact sampled tokens independent of batch slot | 7 of 64 slots (0,1,7,15,31,48,63) checked against single-row launches on one SM120 GPU | Not against main's FlashInfer (only against flashinfer#208); does not cover all 64 slots; single GPU, single arch |
pytest tests/components/ -q: 185 passed, 55 skipped |
Self-reported | Cannot be re-run here; not CI output; GPU tests within that count skip |
tests/components/test_sampling_flashinfer.py not run via GraphReplayWorker |
Stated honestly — local .venv lacks the qualification Cargo feature |
This is the test that would prove the property; it is skipped in CI too (CUDA_VISIBLE_DEVICES="") |
| "Reduces … sampling launch overhead on newly exported decode cores" | Inference from node count | No whole-model or flare run measurement, contrary to docs/performance-work.md:37-47 and docs/core-design.md:1276-1279 |
| "Existing prepared model cores continue to load and serve unchanged" | Consistent with the diff (2 Python files, no ABI/graph-kind change) | Already-captured cores keep the old 192-node graphs; the benefit only materialises on re-export — the description says "on newly exported decode cores", which is accurate, but a reader could mistake this for a drop-in win |
The description is unusually candid about limitations (names the unrun benchmark, the missing Cargo feature, the external dependency), which is worth noting alongside the gaps.
Reach
- Every recipe and every request:
PreparedSamplingis the shared decode sampler (docs/core-design.md:537); no flag exists to opt out. Model-specific recipes live outside this repo (hyperflare_recipes, AGENTS.md:382-396). - Both execution paths change at once: captured graph (
sampling.py:599-607) and dynamic/functional used withdynamic_inputs=True/ AOT (:656-674). - No compatibility break: no protobuf/Helios/CLI/wire change; no re-export forced, but pre-existing cores keep the old node count.
- Configuration/defaults unchanged; scale of benefit tracks
MAX_CONCURRENCY = 64(ignition/components/capacity.py:11) and the capacity catalog(1,2,4,6,8,12,16,24,32,64)(capacity.py:13) — every exported capacity gets the smaller graph, and the fixed per-row cost dominated at small batches. - Hardware scope of the evidence: SM120 (RTX PRO 6000 Blackwell) only; charter-supported targets are SM103, SM120, SM121. Nothing in the code is arch-specific, but no SM103/SM121 evidence exists.
- Deployment risk concentrated in the dependency: if this lands before FlashInfer
maincarries #208, every export that samples and everypytest tests/run touching sampling fails. - Documentation left stale for operators/reviewers:
sampling.py:459-473,docs/core-design.md:1289-1294,docs/mtp-design.md:486-490.
Process
- Open, not a draft, labelled "ready for review"; opened/last updated 2026-12-02 16:51 (single timestamp — no edits since opening); under a day old at intake. No labels, no reviewers, no comments, no CI checks on head.
- Repo CI would be
.github/workflows/python-cpu.yml(not opened) (runs onpull_request, no path filter, CPU-only withCUDA_VISIBLE_DEVICES: ""), plusnative-serving.yml(not opened) andhelios-lifecycle.yml(not opened); whether the absence of checks is queue delay or the workflows not triggering for this head cannot be determined from the local copy. - No Autobot case file was generated for #684, whereas #658 and #673 both got one within minutes of opening — worth flagging to whoever watches process.
- Merge-order dependency is manual only (see dependency finding). PR description covers all four charter-required parts (why, what changed, claimed result, evidence) and discloses limitations.
Open questions / what could not be found
- Whether
local-inference-lab/flashinfer#208is merged, and whether FlashInfermaincurrently exposessampling_from_probs_outwith the positional schema atflashinfer_sampling.py:45-46— not checkable from this repository. - The actual argument order/meaning of
sampling_from_probs_out's 10 positional arguments (all... , None, True, seed, 0, offset, 0, row_independent_rng) is undocumented in-tree; a reviewer must read FlashInfer to confirm theNoneworkspace and the two0fields. - Whether any downstream consumer depended on 64 separate launches (streams/events around the sampler) — nothing in-tree suggests it, but recipes are external.
- No issue, user report, or benchmark request was found motivating the change; no discussion anywhere links to #684.
- Whether a GPU CI job is planned (no workflow sets
FLARE_RUN_CUDA_TESTS), so the slot-invariance test currently guards nothing automatically. docs/performance-work.md:37namesqualify.gpu_replayas the required measurement tool, butqualifywas extracted from core Flare (17bb3c4a, 2026-11-22) andtests/preparation/test_core_boundary.pyforbidsqualifyimports — whether that documented path still exists for contributors is a separate docs/reality gap worth surfacing to the same reviewers.