PR #684: perf(sampling): collapse per-row PreparedSampling loop to 1 row-independent FlashInfer launch

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/e53df29e-d79e-4f86-bf58-5219143e3fbb

Opened by a workflow run, Dec 2, 2026 11:51 AM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: lukealonso (COLLABORATOR; one of the three charter "priority contributors", and the project owner named in AGENTS.md; Discord: lukealonso) Motivation: The decode sampler used to launch one tiny FlashInfer kernel per batch row, plus two single-element copies, because FlashInfer mixed the thread-block index into its RNG seed — so batching rows would have made a request's sampled token depend on its batch slot. FlashInfer upstream can now key the RNG to seed+offset only, so all rows can be sampled in one launch, cutting the captured decode graph from 192 extra nodes to 1. Scale: +19 / −9 lines in 2 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #684 (perf(sampling): collapse per-row PreparedSampling loop to 1 row-independent FlashInfer launch)

Charter alignment: good. Both edited modules sit in the runtime interface layer of core ignition; the change adds no per-model branch, no user-facing flag, and no recipe. It cuts graph nodes and writes into preallocated scratch, consistent with the ban on eager fallbacks/steady-state allocation, and it uses FlashInfer's own out-variant rather than a local kernel. docs/mtp-design.md:486-490 explicitly permits a library API supplying "an equally qualified request-keyed stream" in place of one-row calls. No protobuf, graph-kind, or wire change, so no new captured-graph op contract is implied.

Novelty & status: genuinely additive. No open PR competes for _filter_scores (#658 touches a different hunk; #673 is logprobs.py), main has not moved on either file since the branch point, and nothing on main already fixes this. It is the beneficiary of merged #555 (batch capacities 6/12/24), which multiplied the number of captured decode graphs paying the old 192-node loop.

But the charter's evidence bar is not met. "Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)." The PR reports a component node count (192 → 1 launch; 23 total nodes at SM120, C=64, vocab=16384) from an ad-hoc torch.cuda.CUDAGraph and explicitly declines flare run latency — contrary to docs/performance-work.md:37-47 and docs/core-design.md:1276-1279 ("Measure sampler cost inside the complete graph before changing it"). The property it relies on is guarded only by a test that never runs in CI (test_native_flashinfer_rng_is_invariant_to_capacity_packing_and_physical_slot, skipped without FLARE_RUN_CUDA_TESTS), and slot-invariance was checked on 7 of 64 slots, one SM120 GPU.

Maintenance exposure. Correctness rides on unmerged local-inference-lab/flashinfer#208, yet the declared "update the pin" step has no artifact: pyproject.toml:47 tracks FlashInfer main by branch and there is no uv.lock, so merge order is enforced by nothing. The PR also leaves sample_probabilities dead and leaves the PreparedSampling docstring, docs/core-design.md:1289-1294, and docs/mtp-design.md:486-490 asserting a one-row/Philox-subsequence-zero rule the code now violates.

The author is a priority contributor and the designated approver for this change class, and the footprint is small (+19/−9, runtime-side, no ABI change). Before merge: (1) a flare run measurement on an exported core vs main (#210); (2) flashinfer#208 landed plus an exact-commit/version pin (#215); (3) docstring and doc updates reframing the Philox contract as library-supplied; (4) drop the dead sample_probabilities. Process note: no CI checks and no Autobot case file on this head, unlike #658/#673 — resolve before investing further. No instruction-like content was found in the PR material.

Verdict: Worth it with changes.

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

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +performance

Subtraction and simplicity

Subtraction/Simplicity lens on PR #684 — verdict: keep the core edit, but three pieces of the added surface should be cut.

The central change is a real net simplification: a 5-line per-row loop with four slice copies becomes one 2-line batched out-write, with no new flag, knob, env var, or fallback branch. Five items, three of them in the file the PR adds to:

  1. ignition/components/flashinfer_sampling.py:34-38 — the PR spends +3/−1 adding row_independent_rng to sample_probabilities while simultaneously deleting its only caller. A tree-wide search at head finds only the definition. Delete the function outright.
  2. flashinfer_sampling.py:41-42 — row_independent_rng=False is a keyword default no caller can legally use: the sole call site passes True, rows is the batch dimension on both the captured (sampling.py:599-607) and functional (:656-674) paths, and False would break tests/components/test_sampling_flashinfer.py:183-205. The same file's verify_chain (:50-54) hardcodes True with a comment instead — copy that.
  3. ignition/components/sampling.py:467-472 — the class docstring still asserts "Each row uses a separate FlashInfer call … temporary outputs remain inside the captured graph", false 128 lines below at :596-597. Also stale: docs/core-design.md:1289-1294 and docs/mtp-design.md:486-490.
  4. flashinfer_sampling.py:44-46 — a bare sampling.get_sampling_module() whose return is discarded (contrast :26, which uses it) plus six unexplained positional arguments (None, True, 0, 0) whose schema is upstream-only.
  5. sampling.py:512-513 — self._flashinfer = sampling is an unread dead alias in the hunk region the PR touches; one-line removal.

Not findings: no duplication of an existing helper — only three torch.ops.flashinfer sites exist and there is no shared out-op wrapper; the new wrapper's placement in flashinfer_sampling.py is fixed by the 12-module ABI boundary.

Open questions: whether local-inference-lab/flashinfer#208 is merged (unverifiable here); whether the get_sampling_module() call in item 4 is a required registration side effect or removable; the meaning of sampling_from_probs_out's positional fields.

Full report · Notes

Correctness and contracts

Review of PR #684 (per-row PreparedSampling loop → one batched FlashInfer call), correctness/contracts/system-consequences lens. The mechanism is sound; the problems are unenforced contracts and missing evidence.

Most important findings:

  1. Major — stale contract text everywhere: the PreparedSampling docstring still says "Each row uses a separate FlashInfer call … subsequence is therefore zero" (ignition/components/sampling.py:459-473) while the body now does one batched call (sampling.py:596-597); same false claim in docs/core-design.md:1289-1294 and docs/mtp-design.md:486-490. PR body never mentions docs.
  2. Major — sample_probabilities_out binds 10 positional args to an out-of-tree op schema with opaque literals None, True, seed, 0, offset, 0, row_independent_rng (flashinfer_sampling.py:41-47); the sibling filter_probabilities_out computes its PDL flag (:28-29). Schema drift rebinds silently instead of raising.
  3. Major — the declared prerequisite ("update the FlashInfer pin") is unenforceable: pyproject.toml:47 tracks upstream main, no uv.lock exists, and CPU CI (python-cpu.yml:25-33) cannot exercise the changed path.
  4. Major — out-buffer contract (int32 samples, bool valid, sampling.py:482) is no longer absorbed by copy_() and is not checked, though _check_tensor exists (sampling.py:416-418).
  5. Major (charter #210) — no served-workload A/B; qualify.gpu_replay / flare run CORE (docs/performance-work.md:37-47, docs/core-design.md:1276-1279) not run; 192→23 nodes has no reproducible artifact.
  6. Major (tests) — the only invariant test is CI-skipped (tests/components/test_sampling_flashinfer.py:28-31, no workflow sets FLARE_RUN_CUDA_TESTS) and unrun by author; covers rows≤4/vocab 154880-248320, not C=64/16384; no test covers the new call path.
  7. Minor: fixed-seed token streams change on re-export with no opt-in and no note. Sound: dead/invalid rows, ordering, streams, no memory growth, placement, no ABI change.

Open: is flashinfer#208 merged and what is the exact out-op schema; meaning of the literal args; any GPU CI planned.

Full report · Notes

Final review

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

Walkthrough

Pre-merge Checks

Blockers

  1. 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_out calls torch.ops.flashinfer.sampling_from_probs_out with 10 positional arguments including row_independent_rng, which does not exist until local-inference-lab/flashinfer#208 lands. Contrary to the PR description's instruction to "update the FlashInfer pin before merging", pyproject.toml:47 tracks branch = "main" (flashinfer-python = { git = "https://github.com/local-inference-lab/flashinfer.git", branch = "main" }) and there is no uv.lock in the repository, so nothing enforces merge order and CPU CI (.github/workflows/python-cpu.yml:29-33 (not opened)) passes even against a FlashInfer main lacking #208.
    • Fix: Merge local-inference-lab/flashinfer#208 into FlashInfer main first, verify this PR against the merged FlashInfer main commit (and update the PR description to remove the nonexistent pin-update step or pin the exact revision per charter #215).
  2. Compiled/AOT preparation paths and tests/components/test_sampling_flashinfer.py are 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_forward and aot_forward, which trace @torch.compiler.allow_in_graph helpers under make_fx(..., tracing_mode='fake'), wrap mutating OpOverloads in flare::storage_call only when _mutated_tensors sees alias_info.is_write on the op schema (compilation.py:728-735), and serialize/reload the op via importlib.import_module(definition._init_fn.__module__) (aot.py:361-364,539-542). The PR's GPU check only ran eager PreparedSampling.__call__ in a raw torch.cuda.CUDAGraph and skipped tests/components/test_sampling_flashinfer.py (whose CapturedSampler tests compile_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, missing mutates_args annotation on samples/valid, or lazy op-registration failure during AOT restore would break real exports silently or at export time.
    • Fix: After flashinfer#208 lands, run FLARE_RUN_CUDA_TESTS=1 on tests/components/test_sampling_flashinfer.py (rebuilding flare-heliopause with --features qualification so GraphReplayWorker is available per ignition/preparation/graphs.py:115-116, or at minimum verifying compile_forward + aot_forward round-trip serialization/deserialization and all slot-invariance/edge-case tests on GPU) and report the results in the PR description.

Should Fix

  1. Update the stale RNG contract in PreparedSampling and 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_scores issues 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 offset 4 * 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_out launch writing directly into prepared scratch with row_independent_rng=True, preserving per-request (seed, offset) RNG independence across packed rows and physical slots.
  2. 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, and docs/performance-work.md:45-47 require performance PRs to demonstrate before/after results on a complete exported core (flare run CORE --embedding-table-storage ram), and docs/core-design.md:1277-1278 states "Measure sampler cost inside the complete graph before changing it". The PR currently reports only a component graph node count (192 → 1 launch, 23 total 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 @lukealonso explicitly accepts graph-node reduction as sufficient justification — record that scope explicitly on the PR rather than claiming an unmeasured serving speedup.

Subtract / Simplify

  1. Hardcode row_independent_rng=True in sample_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). Match verify_chain right below it (ignition/components/flashinfer_sampling.py:50-54): drop the row_independent_rng=False parameter, pass True directly, 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.).
  2. Delete sample_probabilities if unused by external recipes (ignition/components/flashinfer_sampling.py:34-38)

    • After switching sampling.py to sample_probabilities_out, a repo-wide search confirms sample_probabilities has zero in-tree callers, yet this PR expands its signature (+3/−1). Because flashinfer_sampling is a retained Helios-ABI interface module (tests/preparation/test_core_boundary.py:16) that external recipes in local-inference-lab/hyperflare-recipes may import (as with verify_chain at :50-54), confirm whether any external recipe calls sample_probabilities; if none does, delete lines 34-38 outright instead of carrying an untested dead wrapper.

Nits

Dropped on verification

Full report

Classify triage

Selected: (none)

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (99%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.