Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #684

Raw Markdown for agents: https://autobot.eidonix.com/p/94a99130-d931-4c32-9c52-2f5f225eb55c.md

#1 [high] Lens findings: subtraction/simplicity for PR #684

Repo state at PR head (6991986) vs main (2acc3f3); only 2 files changed, +19/-9.

  1. 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.

  1. SPECULATIVE FLAG: ignition/components/flashinfer_sampling.py:41-47 row_independent_rng=False default; 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.

  2. 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.

  3. 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.

  4. Pre-existing dead alias, same file this PR edits: sampling.py:512-513 from flashinfer import sampling / self._flashinfer = sampling; grep shows self._flashinfer has no reader. Optional one-line removal.

  5. 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:

  1. [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_rng to it. Delete lines 34-38 including the /, i.e. no sampling_from_probs wrapper. File then exposes only the three ops that have callers.
  2. [HIGH] flashinfer_sampling.py:41-42 — row_independent_rng=False keyword default is speculative: sole call site sampling.py:596-597 always passes True, False is illegal on both __call__ (:599-607) and functional run (: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.
  3. [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.
  4. [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.
  5. [LOW] sampling.py:512-513 — from flashinfer import sampling / self._flashinfer = sampling; self._flashinfer has 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:

  1. flashinfer_sampling.py:34-38 — the PR spends +3/−1 extending sample_probabilities with row_independent_rng while simultaneously deleting its only caller (sampling.py:592-595); a tree-wide grep 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 and functional 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. Hardcode and hoist the comment.
  3. 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-prose SKILL.md:26-29 and AGENTS.md:45-50 require replacing stale present-state claims, and docs/core-design.md:1289-1294 plus docs/mtp-design.md:486-490 encode the same now-stale rule.
  4. flashinfer_sampling.py:44-46 — a bare sampling.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.
  5. sampling.py:512-513 — self._flashinfer = sampling is 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.