Recommendation: Changes Requested
The core change in PreparedSampling._filter_scores is a clean, high-value simplification (+19/−9 across 2 files) that collapses up to 192 sequential CUDA graph nodes at C=64 into one batched FlashInfer out-op launch with no Helios runtime, Protobuf, or core compatibility regressions. However, two concrete blockers must be resolved before merge: the PR depends on unmerged upstream local-inference-lab/flashinfer#208 with no pin or CI gate enforcing merge order, and the real production export paths (compile_forward and aot_forward) plus tests/components/test_sampling_flashinfer.py have not been exercised against the new torch.ops.flashinfer.sampling_from_probs_out custom op. Stale RNG contract documentation and the charter's served-workload performance evidence bar also need to be addressed.
Merge Risk
Level: High
- Hard runtime break if merged out of order with upstream FlashInfer:
ignition/components/flashinfer_sampling.py:45-47resolvestorch.ops.flashinfer.sampling_from_probs_outonly at GPU preparation time, whilepyproject.toml:47tracks FlashInferbranch = "main"with nouv.lockand CPU CI runs withCUDA_VISIBLE_DEVICES: ""(.github/workflows/python-cpu.yml:31-33(not opened)). Merging beforelocal-inference-lab/flashinfer#208lands on FlashInfermainwill break every model export that usesPreparedSamplingwhile CI remains green. - Unverified compiled/AOT lowering on the shared decode sampler:
PreparedSamplingis the shared decode sampler across all recipes (docs/core-design.md:1270-1274). Production exports compile forwards viacompile_forward(ignition/preparation/compilation.py:365-389) andaot_forward(ignition/preparation/aot.py:555-561), which tracesample_probabilities_outwithFakeTensors, depend onsampling_from_probs_out's op schema declaringsamplesandvalidas mutated (compilation.py:519,618-620,728-735), and serialize/reload theOpOverload(aot.py:361-364,539-542). Because only eagertorch.cuda.CUDAGraphcapture was run, fake-kernel, mutation-schema, or AOT-deserialization mismatches would only surface during full export. - No core compatibility or runtime concurrency risk once upstream lands: No Rust/Helios, Protobuf, CLI, or ABI changes; existing exported cores continue to load and serve unchanged (retaining their previously captured graphs until re-export). Both eager (
__call__,sampling.py:599-607) and dynamic/functional (run,sampling.py:656-680) paths preserve dead-row sanitization, TP broadcast ordering, and preallocated scratch lifetimes.
Walkthrough
ignition/components/flashinfer_sampling.py:34-38: Threads keyword-onlyrow_independent_rng=Falseintosample_probabilities(...), even though this PR removes its sole in-tree caller.ignition/components/flashinfer_sampling.py:41-47: Adds@torch.compiler.allow_in_graph def sample_probabilities_out(probabilities, samples, valid, seed, offset, *, row_independent_rng=False), invokingsampling.get_sampling_module()andtorch.ops.flashinfer.sampling_from_probs_out(probabilities, samples, valid, None, True, seed, 0, offset, 0, row_independent_rng).ignition/components/sampling.py:24-28: Switches the import fromsample_probabilitiestosample_probabilities_out.ignition/components/sampling.py:596-597: Replaces thefor row in range(self._rows)loop (per-rowsample_probabilities+sampled_tokens/sample_valid.copy_()) inPreparedSampling._filter_scoreswith a single batchedsample_probabilities_out(..., row_independent_rng=True)call writing directly intoscratch["sampled_tokens"]andscratch["sample_valid"]for both captured (__call__) and functional (run) execution paths.
Pre-merge Checks
- [PASS] Security / malicious screen: No untrusted inputs, secret handling, or prompt-injection attempts found in the PR description, comments, or diff.
- [WARN] Charter & value fit: Architecturally well-placed in core
ignition/componentswith zero per-model branches or ABI churn (AGENTS.md:388-396,tests/preparation/test_core_boundary.py:11-25) and authorized bydocs/mtp-design.md:486-491; however, the PR does not meet the charter's served-workload benchmark bar for performance PRs (#210,docs/design-review.md:109-112) and relies on an unpinned moving branch (pyproject.toml:47,#215). - [PASS] Related / duplicate / conflict check: No competing fix on
mainor open PRs; open PR #658 touches a disjoint hunk inignition/components/sampling.py:129-131(DeviceRequestState.vocab_ids). - [WARN] Tests & verification evidence: Only CPU component tests (self-reported
185 passed, 55 skipped) and an ad-hoc eagertorch.cuda.CUDAGraphcheck on 7 of 64 slots on SM120 were run;tests/components/test_sampling_flashinfer.py(includingcompile_forward=True,compile_forward='aot', andtest_native_flashinfer_rng_is_invariant_to_capacity_packing_and_physical_slot) was not run locally and is skipped in CPU CI (.github/workflows/python-cpu.yml:32(not opened)).
Blockers
-
Unmerged upstream dependency (
local-inference-lab/flashinfer#208) with no pin or CI gate (ignition/components/flashinfer_sampling.py:45-47,pyproject.toml:47)- Verified behavior & impact:
sample_probabilities_outcallstorch.ops.flashinfer.sampling_from_probs_outwith 10 positional arguments includingrow_independent_rng, which does not exist untillocal-inference-lab/flashinfer#208lands. Contrary to the PR description's instruction to "update the FlashInfer pin before merging",pyproject.toml:47tracksbranch = "main"(flashinfer-python = { git = "https://github.com/local-inference-lab/flashinfer.git", branch = "main" }) and there is nouv.lockin the repository, so nothing enforces merge order and CPU CI (.github/workflows/python-cpu.yml:29-33(not opened)) passes even against a FlashInfermainlacking#208. - Fix: Merge
local-inference-lab/flashinfer#208into FlashInfermainfirst, verify this PR against the merged FlashInfermaincommit (and update the PR description to remove the nonexistent pin-update step or pin the exact revision per charter#215).
- Verified behavior & impact:
-
Compiled/AOT preparation paths and
tests/components/test_sampling_flashinfer.pyare completely unverified on the new custom op (ignition/components/flashinfer_sampling.py:41-47,ignition/preparation/compilation.py:519,618-620,728-735,ignition/preparation/aot.py:361-364,539-542,tests/components/test_sampling_flashinfer.py:145-205)- Verified behavior & impact: Production core exports compile forwards via
compile_forwardandaot_forward, which trace@torch.compiler.allow_in_graphhelpers undermake_fx(..., tracing_mode='fake'), wrap mutatingOpOverloads inflare::storage_callonly when_mutated_tensorsseesalias_info.is_writeon the op schema (compilation.py:728-735), and serialize/reload the op viaimportlib.import_module(definition._init_fn.__module__)(aot.py:361-364,539-542). The PR's GPU check only ran eagerPreparedSampling.__call__in a rawtorch.cuda.CUDAGraphand skippedtests/components/test_sampling_flashinfer.py(whoseCapturedSamplertestscompile_forward=[False, True, 'aot']at:145,compiled in (False, True)slot/capacity invariance at:183-205, invalid/stale/disabled rows at:208-260, and workspace reuse at:112-142). Any missing fake kernel, missingmutates_argsannotation onsamples/valid, or lazy op-registration failure during AOT restore would break real exports silently or at export time. - Fix: After
flashinfer#208lands, runFLARE_RUN_CUDA_TESTS=1ontests/components/test_sampling_flashinfer.py(rebuildingflare-heliopausewith--features qualificationsoGraphReplayWorkeris available perignition/preparation/graphs.py:115-116, or at minimum verifyingcompile_forward+aot_forwardround-trip serialization/deserialization and all slot-invariance/edge-case tests on GPU) and report the results in the PR description.
- Verified behavior & impact: Production core exports compile forwards via
Should Fix
-
Update the stale RNG contract in
PreparedSamplingand design docs (ignition/components/sampling.py:467-472,docs/core-design.md:1289-1294,docs/mtp-design.md:486-491)- Verified behavior & impact: All three places still document the deleted one-row loop as the active contract:
ignition/components/sampling.py:467-472: "Each row uses a separate FlashInfer call with device seed and offset=4*counter. CUDA's Philox subsequence is therefore zero regardless of packed row or physical slot. ... FlashInfer's temporary outputs remain inside the captured graph." — Both claims are now false (_filter_scoresissues one batched launch directly into prepared scratch).docs/core-design.md:1290-1292: "Each request uses a one-row draw with Philox subsequence zero and word offset4 * counter" — now false as written.docs/mtp-design.md:486-491: Explicitly permits this substitution ("unless a library API supplies an equally qualified request-keyed stream"), but its opening sentence ("The ordinary decode sampler (ignition/components/sampling.py) uses one-row FlashInfer calls") is now stale.
- Fix: Update all three passages to state the present-state mechanism: a single batched FlashInfer
sampling_from_probs_outlaunch writing directly into prepared scratch withrow_independent_rng=True, preserving per-request(seed, offset)RNG independence across packed rows and physical slots.
- Verified behavior & impact: All three places still document the deleted one-row loop as the active contract:
-
Provide served-workload or complete-graph A/B performance evidence (
docs/performance-work.md:37-47,docs/core-design.md:1276-1279,docs/design-review.md:109-112)- Verified behavior & impact: The charter (
#210),docs/design-review.md:109-112, anddocs/performance-work.md:45-47require performance PRs to demonstrate before/after results on a complete exported core (flare run CORE --embedding-table-storage ram), anddocs/core-design.md:1277-1278states "Measure sampler cost inside the complete graph before changing it". The PR currently reports only a component graph node count (192→1launch,23total nodes) and leaves whole-model decode latency unmeasured. - Fix: Measure before/after re-export decode step latency / throughput on an exported core with
flare run(especially at higher concurrency where the old 192-node loop is largest), or — if project owner@lukealonsoexplicitly accepts graph-node reduction as sufficient justification — record that scope explicitly on the PR rather than claiming an unmeasured serving speedup.
- Verified behavior & impact: The charter (
Subtract / Simplify
-
Hardcode
row_independent_rng=Trueinsample_probabilities_out(ignition/components/flashinfer_sampling.py:42-47)- The new keyword-only parameter defaults to
row_independent_rng=False, which no Flare caller can validly use without breaking batch-slot RNG invariance (tests/components/test_sampling_flashinfer.py:183-205). Matchverify_chainright below it (ignition/components/flashinfer_sampling.py:50-54): drop therow_independent_rng=Falseparameter, passTruedirectly, and carry the invariant in a one-line comment (# Each row draws from its own seed and offset only, so its tokens do not depend on its batch slot.).
- The new keyword-only parameter defaults to
-
Delete
sample_probabilitiesif unused by external recipes (ignition/components/flashinfer_sampling.py:34-38)- After switching
sampling.pytosample_probabilities_out, a repo-wide search confirmssample_probabilitieshas zero in-tree callers, yet this PR expands its signature (+3/−1). Becauseflashinfer_samplingis a retained Helios-ABI interface module (tests/preparation/test_core_boundary.py:16) that external recipes inlocal-inference-lab/hyperflare-recipesmay import (as withverify_chainat:50-54), confirm whether any external recipe callssample_probabilities; if none does, delete lines 34-38 outright instead of carrying an untested dead wrapper.
- After switching
Nits
ignition/components/flashinfer_sampling.py:44-47: Add a brief comment explaining the op-registration side effect ofsampling.get_sampling_module()and naming the positional literals (None, True, seed, 0, offset, 0) intorch.ops.flashinfer.sampling_from_probs_out(...)so reviewers do not have to cross-reference FlashInfer source to audit the call.ignition/components/sampling.py:512-513(pre-existing, optional):from flashinfer import sampling/self._flashinfer = samplingis unread anywhere in the repository (search_codefor_flashinfer\bfinds only line 513) and can be deleted cleanly while in this file.
Dropped on verification
- "Major — unvalidated positional binding hardcoding PDL instead of
device_support_pdl(probabilities.device)" (Correctness & Contracts 1.1): Dropped as inaccurate/speculative. Positional calls totorch.ops.flashinfer.*_outare the established convention in this exact file (ignition/components/flashinfer_sampling.py:27,30-31fortop_k_mask_logits_outandtop_p_renorm_probs_out), anddevice_support_pdlat:29is only an argument tomodule.softmax(...), not to the*_outcustom ops. Downgraded the opaque-literals readability concern to a Nit. - "Drop
sampling.get_sampling_module()if unused" (Subtraction & Simplicity 4a): Dropped. In FlashInfer,get_sampling_module()performs lazy module load /torch.ops.flashinfercustom-op registration; removing it would break any standalone call tosample_probabilities_outinvoked beforefilter_probabilities_out. Kept only a Nit to comment its registration purpose. - "Major — out-buffer dtype/shape contract no longer absorbed by
copy_(), add_check_tensorinprepare()" (Correctness & Contracts 1.2): Dropped as false/redundant.bind_scratch(ignition/preparation/scratch.py:291-308) andrun()(ignition/components/sampling.py:662-664) already enforce exact contiguous(rows,)torch.int32/torch.boolon the target device fromscratch_layout(:475-482), andprepare()already warms_filter_scores(self.scratch_tensors)(:564) prior to capture. Redundant_check_tensorcalls on Flare's own scratch would not detect an upstream FlashInfer op schema change anyway. - "Minor — fixed-seed token streams change for every request on re-export" (
Correctness & Contracts 1.3): Dropped as false. The whole point ofrow_independent_rng=Trueis preserving thesubsequence=0Philox stream previously achieved via 1-row launches (bx=0), which the PR verified as bit-exact against single-row launches. - "Add a CPU unit test mocking
torch.ops.flashinfer" (Correctness & Contracts 4.1): Dropped as low-signal and contrary todocs/design-review.md:187-189("avoid mocks or source-text checks that bypass runtime behavior") anddocs/verification.md:48. The real gap is executing the existing GPU test suite (tests/components/test_sampling_flashinfer.py), captured in Blocker 2. - "Process anomaly — no Autobot case file on #684" (
Discovery Dossier&Value Proposition Summary): Dropped as stale;pr_commentsconfirmsflare-autobotopened the case file on2026-12-02 16:55. - "Unconditionally delete
sample_probabilitiesbecause repo-wide search found 0 callers" (Subtraction & Simplicity 1,Discovery Dossier 7): Softened to a conditional check in## Subtract / Simplifybecauseflashinfer_samplingis a core-to-external-recipe ABI module (AGENTS.md:388-396,tests/preparation/test_core_boundary.py:16), just likeverify_chain(:50-54) which also has zero in-tree callers.