#1 [high] Lens findings: subtraction/simplicity for PR #684
Repo state at PR head (6991986) vs main (2acc3f3); only 2 files changed, +19/-9.
- DEAD CODE ADDED TO: ignition/components/flashinfer_sampling.py:34-38
@torch.compiler.allow_in_graph
def sample_probabilities(probabilities, seed, offset, return_valid=False, *, row_independent_rng=False):
return sampling.sampling_from_probs(probabilities, seed=seed, offset=offset,
deterministic=True, check_nan=False, return_valid=return_valid,
row_independent_rng=row_independent_rng)
Repo-wide grep (sample_probabilities, whole tree + tests + docs, and at ref=main): only the definition; the single caller (sampling.py:592-597 on main) is deleted by this PR. So the PR not only leaves dead code, it extends a dead function with a new kwarg and a sampling.get_sampling_module-style path that never runs. Suggest deleting lines 34-38 entirely.
-
SPECULATIVE FLAG: ignition/components/flashinfer_sampling.py:41-47
row_independent_rng=Falsedefault; the only call site (sampling.py:596-597) always passes True. Same file's precedent verify_chain :50-54 hardcodes True in the call, no flag. With batching inherent (rows are the batch dim on both the captured and functional paths), False is never a legal call. Drop the kwarg, hardcode True. -
STALE DOCSTRING (contradicts new code 130 lines below): ignition/components/sampling.py:467-472 says "Each row uses a separate FlashInfer call ... FlashInfer's temporary outputs remain inside the captured graph", while :596-597 is one batched out-written launch. repo-prose SKILL.md:26-29 requires present-state spec, replace stale claims. Also docs/core-design.md:1289-1294 and docs/mtp-design.md:486-490 encode the one-row rule.
-
UNEXPLAINED SIDE-EFFECT CALL: flashinfer_sampling.py:44
sampling.get_sampling_module()bare call (filter_probabilities_out:26 uses the return value; this discards it). No comment; docstring only says "Sample every row in one launch...". AGENTS.md:45-50 + repo-prose:38-39 require comments to explain non-obvious constraints. -
Pre-existing dead alias, same file this PR edits: sampling.py:512-513
from flashinfer import sampling/self._flashinfer = sampling; grep showsself._flashinferhas no reader. Optional one-line removal. -
No generic out-wrapper helper exists to reuse (only 3 torch.ops.flashinfer calls: :27, :30, :45), so the new wrapper itself is not duplication; keeping it in flashinfer_sampling.py matches the file's convention. Diff otherwise lean.
#3 [high] Final report: 5 simplification items for PR #684
Final lens report (Subtraction, Simplicity & Conventions) for PR #684 at head 6991986, base main 2acc3f3.
Verdict: core edit is a genuine net simplification and should be kept. 5 high-value items, no nitpicks:
- [HIGH] flashinfer_sampling.py:34-38 — sample_probabilities is now dead (only its definition matches a tree-wide grep; its one caller sampling.py:592-595 is deleted by this PR), yet the PR spends +3/-1 adding
row_independent_rngto it. Delete lines 34-38 including the/, i.e. nosampling_from_probswrapper. File then exposes only the three ops that have callers. - [HIGH] flashinfer_sampling.py:41-42 —
row_independent_rng=Falsekeyword default is speculative: sole call site sampling.py:596-597 always passes True,Falseis illegal on both__call__(:599-607) and functionalrun(:656-674) because rows is the batch dim, and it would break tests/components/test_sampling_flashinfer.py:183-205. Precedent in the same file: verify_chain :50-54 hardcodes True with an explanatory comment. Hardcode True, drop the kwarg, hoist the invariant comment from :52. - [HIGH] sampling.py:467-472 — class docstring still says "Each row uses a separate FlashInfer call ... temporary outputs remain inside the captured graph", contradicted by :596-597. repo-prose SKILL.md:26-29 + AGENTS.md:45-50 require present-state replacement. Also docs/core-design.md:1289-1294 and docs/mtp-design.md:486-490 still state the one-row rule as the contract; stale.
- [MEDIUM] flashinfer_sampling.py:44-46 — bare
sampling.get_sampling_module()(return discarded; contrast :26 which uses it) plus six unexplained positional args (None, True, 0, 0) whose schema is upstream-only (flashinfer#208). Needs either deletion or a comment naming the registration side effect and the field mapping. - [LOW] sampling.py:512-513 —
from flashinfer import sampling/self._flashinfer = sampling;self._flashinferhas no reader anywhere (grep of whole tree yields only :513), and after :596 nothing needs the local name. Delete both lines.
Non-findings: no duplication (only 3 torch.ops.flashinfer sites, no shared out-op helper; new wrapper belongs in flashinfer_sampling.py, one of the 12 ABI modules fixed by tests/preparation/test_core_boundary.py:11-25); no new flag/knob/env/fallback; no correct-workaround-that-should-be-deleted.
#4 [high] Research summary
Subtraction/Simplicity review of PR #684 complete. The core change is a genuine 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), so the diff should be kept. Five high-value items, three in the file the PR adds to:
flashinfer_sampling.py:34-38— the PR spends +3/−1 extendingsample_probabilitieswithrow_independent_rngwhile simultaneously deleting its only caller (sampling.py:592-595); a tree-wide grep at head finds only the definition. Delete the function outright.flashinfer_sampling.py:41-42—row_independent_rng=Falseis a keyword default no caller can legally use: the sole call site passesTrue,rowsis the batch dimension on both the captured and functional paths, andFalsewould breaktests/components/test_sampling_flashinfer.py:183-205. The same file'sverify_chain(:50-54) hardcodesTruewith a comment instead. Hardcode and hoist the comment.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;repo-proseSKILL.md:26-29 andAGENTS.md:45-50require replacing stale present-state claims, anddocs/core-design.md:1289-1294plusdocs/mtp-design.md:486-490encode the same now-stale rule.flashinfer_sampling.py:44-46— a baresampling.get_sampling_module()whose return is discarded (contrast:26) and six unexplained positional arguments (None, True, 0, 0) whose schema exists only upstream; needs a comment or deletion.sampling.py:512-513—self._flashinfer = samplingis an unread dead alias in the region the PR touches; one-line removal.
Not findings: no duplication of an existing helper (only three torch.ops.flashinfer sites exist, no shared out-op wrapper, and the new wrapper's placement in flashinfer_sampling.py is mandated by the 12-module ABI boundary), and no bug-patching workaround that should be deleted instead of fixed. Full evidence and quotes in scratchpad entries 1-3.
#5 [high] Verbatim quote bank for the report
Verbatim quotes still needed by the final report (all read at PR head 6991986 unless noted).
A. New call site — ignition/components/sampling.py:596-597:
sample_probabilities_out(probabilities, scratch["sampled_tokens"], scratch["sample_valid"],
seed=scratch["packed_seed"], offset=scratch["packed_offset"], row_independent_rng=True)
B. Code it replaced — same file at ref=main, sampling.py:592-597:
for row in range(self._rows):
sampled, valid = sample_probabilities(probabilities[row:row + 1],
seed=scratch["packed_seed"][row:row + 1], offset=scratch["packed_offset"][row:row + 1],
return_valid=True)
scratch["sampled_tokens"][row:row + 1].copy_(sampled)
scratch["sample_valid"][row:row + 1].copy_(valid)
C. Stale class docstring — 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. One word is drawn per generated token;
the logical counter advances once. FlashInfer's temporary outputs remain
inside the captured graph. ``scratch_tensors``
enumerates mutable storage retained through graph replay.
D. Flag precedent to copy — ignition/components/flashinfer_sampling.py:50-54:
@torch.compiler.allow_in_graph
def verify_chain(draft_probs, draft_ids, target_probs, accepted, emitted, seed, offset):
# Each row draws from its own seed and offset only, so its tokens do not depend on its batch slot.
return sampling.chain_speculative_sampling(draft_probs, draft_ids, target_probs,
accepted, emitted, deterministic=True, seed=seed, offset=offset, row_independent_rng=True)
E. Contrast for the discarded return in item 4 — flashinfer_sampling.py:26-27:
module = sampling.get_sampling_module()
torch.ops.flashinfer.top_k_mask_logits_out(logits, logits, top_k, 0, row_states)
F. Both paths that call _filter_scores, proving rows is the batch dim and False illegal: sampling.py:599-607 (__call__: self._scores(); self._filter_scores(self.scratch_tensors); ...) and sampling.py:656-674 (run(...) -> self._filter_scores(scratch, local=True, row_inputs=row_inputs)).
G. Boundary test fixing the module set — tests/preparation/test_core_boundary.py:11-25 (RETAINED_IGNITION_COMPONENTS includes both flashinfer_sampling and sampling), so the wrapper cannot move out of ignition/components/.
#2 [medium] Quotes and lean-diff assessment
Verified quotes at PR head (6991986):
sampling.py:512-513:
from flashinfer import sampling
self._flashinfer = sampling
self._flashinfer appears nowhere else (grep whole tree): dead pre-existing alias, on unchanged lines of the same file/hunk region the PR touches. Nothing uses sampling locally either since line 596 uses sample_probabilities_out.
flashinfer_sampling.py:44-47 bare call:
sampling.get_sampling_module()
torch.ops.flashinfer.sampling_from_probs_out(
probabilities, samples, valid, None, True, seed, 0, offset, 0, row_independent_rng
)
Compare filter_probabilities_out:26 module = sampling.get_sampling_module() (return value used for module.softmax). Here the return is discarded with no comment; the 10 positional args have no in-tree schema (upstream only), and None, True, 0, 0 are unexplained. Suggest one comment line citing upstream schema/PR #208, or drop the call if the op registers itself.
Only 3 torch.ops.flashinfer sites in the repo (:27, :30, :45) and no shared out-op helper, so the new wrapper is not duplication; it is 2 lines and matches the file's module convention. Core change in sampling.py is a genuine net simplification (5-line loop with 4 substring copies -> 2-line batched call). No config knob, no graph/protobuf/recipe surface added. Diff is otherwise lean.