Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #684

Raw Markdown for agents: https://autobot.eidonix.com/p/d9a74033-8afd-4235-befc-5d438d0d0d6e.md

#1 [high] Contract prose left contradicting the new mechanism (docstring + 2 design docs)

The PR replaces the loop but leaves the invariant it deletes written down in three places as the contract.

  1. ignition/components/sampling.py:459-473 (class PreparedSampling docstring, unchanged by the diff): "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." The body now does the opposite at 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) i.e. one call for all rows, NUL subsequence no longer zero.

  2. docs/core-design.md:1289-1294: "Keep explicit per-request seeds and counters in server-owned device state. Pass device seed and offset tensors to FlashInfer's sampler. Each request uses a one-row draw with Philox subsequence zero and word offset 4 * counter, so batch packing cannot change its random stream." Now false as written; the guarantee now rests on FlashInfer's row_independent_rng flag (external), not on the one-row construction.

  3. docs/mtp-design.md:486-490: "The ordinary decode sampler (ignition/components/sampling.py) uses one-row FlashInfer calls so Philox subsequence zero is independent of packed lane position. Preserve this property for speculative requests: use per-request one-row chain invocations ... unless a library API supplies an equally qualified request-keyed stream." The unless clause authorises the change (mtp-design is satisfied), but its description of the ordinary sampler is stale.

PR body does not mention documentation at all. Severity: Major (contract prose is the only in-repo statement of the RNG invariant; reviewers/export authors read it). Fix: update the docstring and both doc paragraphs to state "one launch, row-keyed Philox via row_independent_rng=True, verified invariant", or drop the claim.

#2 [high] New op call is an unvalidated positional binding to an out-of-tree schema; literal 0 fields vs device_support_pdl sibling

ignition/components/flashinfer_sampling.py:41-47:

@torch.compiler.allow_in_graph
def sample_probabilities_out(probabilities, samples, valid, seed, offset, *, row_independent_rng=False):
    """Sample every row in one launch directly into caller-owned output buffers."""
    sampling.get_sampling_module()
    torch.ops.flashinfer.sampling_from_probs_out(
        probabilities, samples, valid, None, True, seed, 0, offset, 0, row_independent_rng
    )

Nothing in this repository defines sampling_from_probs_out; the schema lives only in FlashInfer (pyproject.toml:47 tracks its main branch). The call is fully positional, so a schema difference (order, added/removed arg, kwarg-only) silently rebinds values instead of raising: e.g. None (workspace), True, 0, 0 are three opaque literals and the two 0s are exactly where a PDL / stream / check_nan slot would sit.

Contrast inside the same file: filter_probabilities_out computes PDL rather than hardcoding it — flashinfer_sampling.py:28-29 probabilities = module.softmax(softmax_workspace, logits, None, 1., device_support_pdl(logits.device)) and flashinfer_sampling.py:30-31 top_p_renorm_probs_out(probabilities, output, top_p, 0., True, top_p_workspace). The old path went through the Python wrapper sampling.sampling_from_probs(...) (flashinfer_sampling.py on main, lines 34-37), which is the place that owns deterministic/check_nan/workspace/PDL defaults. The new path bypasses the wrapper and re-states them by hand.

Severity: Major. Concrete impact: if upstream's out-op has deterministic or check_nan in a different slot than assumed, the captured graph samples with different semantics (non-deterministic draws or NaN checks) with no in-repo failure; if the 0 is the PDL slot, the batched sampler runs without programmatic dependent launch, a divergence from the neighbouring FlashInfer calls that is neither measured nor documented. Fix: call the op with keywords (torch.ops.flashinfer.sampling_from_probs_out(probs=..., samples=..., ...)) or route through an upstream wrapper, and state in a comment which FlashInfer commit/schema the positional layout belongs to; document/justify each None/0. Related: PR declares "Merge local-inference-lab/flashinfer#208 and update the FlashInfer pin" but there is no pin artifact — see the dependency note.

#3 [high] Declared merge prerequisite is unenforceable: no pin, no lock, and CI skips the only code that needs it

The PR body says: "Requires local-inference-lab/flashinfer#208 ... Merge local-inference-lab/flashinfer#208 and update the FlashInfer pin before merging this PR."

Verified there is nothing in this tree to update and nothing that would fail if the order is violated:

#5 [high] No served-workload A/B evidence; the docs' prescribed measurement path was not run

Charter How We Work: "Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)." This PR deliberately does not supply one ("whole-model flare run latency was not measured in this PR"; "Full-model core export and flare run serving benchmarks were not run").

In-repo measurement rules this PR does not follow:

Substitute evidence is a component-level node count (192 -> 23) measured ad hoc with torch.cuda.CUDAGraph(keep_graph=True); no script, test, or fixture in the tree reproduces it (repo-wide search for node-count assertions finds them only for exported cores, e.g. tests/preparation/test_runtime_core.py:149-161, not component graphs).

Note the node count is a host-side launch graph metric for a graph whose cost at decode is dominated by weight traffic — the sampler kernels are on the order of tens of microseconds on a vocab-sized tensor. So the served-workload effect is plausible but unmeasured; the PR's own "Expected serving effect" wording is honest about that. Severity: Major for charter compliance (#210), not a code defect. Also relevant: pre-existing cores keep the old 192-node graph, so the benefit only appears on re-export — the PR says "on newly exported decode cores", which is accurate.

#6 [high] The invariant test that would catch a regression never executes, and no test covers the new call path

The only test that asserts the property this PR now depends on cannot run in CI, and no new test was added for the new call path.

#8 [high] Research summary

Reviewed PR #684 (Correctness, Contracts & System-Level Consequences) by opening both changed files in full context, their callers (__call__, functional, run, record_completion), the sibling FlashInfer wrapper, the two design docs that state the RNG contract, the CI workflow, and the CUDA test module.

Findings, all with verified file:line citations, saved to scratchpad:

  1. Contract prose left contradicting the code — Major. ignition/components/sampling.py:459-473 still says "Each row uses a separate FlashInfer call … Philox subsequence is therefore zero regardless of packed row or physical slot", while sampling.py:596-597 now issues one batched call. Same stale contract in docs/core-design.md:1289-1294 and docs/mtp-design.md:486-490. PR body mentions no docs.

  2. Unvalidated positional binding to an out-of-tree schema — Major. flashinfer_sampling.py:41-47 calls torch.ops.flashinfer.sampling_from_probs_out(...) with 10 positional args, three of them bare None/True/0/0; nothing in-repo defines that schema (pyproject.toml:47 tracks upstream main). A rebinding would silently change sampling semantics. The neighbouring filter_probabilities_out computes device_support_pdl(...) (:28-29) instead of hardcoding a 0.

  3. Declared merge prerequisite is unenforceable — Major. The PR says to "update the FlashInfer pin", but there is no pin (pyproject.toml:47 is branch-tracking) and no uv.lock in the tree, so ordering is enforced by nothing and only fails on a user's GPU at capture.

  4. Out-buffer contract unvalidated now that copy_ is gone — Major. The removed code converted dtypes via .copy_(); the new call writes directly into int32/bool scratch fixed by scratch_layout (sampling.py:482), with no _check_tensor guard.

  5. No served-workload A/B evidence — Major (charter #210). Substitutes a 192→23 component node count for the qualify.gpu_replay + flare run CORE measurement mandated by docs/performance-work.md:37-47 and docs/core-design.md:1276-1279.

  6. The invariant test never runs — Major. tests/components/test_sampling_flashinfer.py:28-31 skips without FLARE_RUN_CUDA_TESTS=1, which no workflow sets (python-cpu.yml:25-33 runs CPU-only with CUDA_VISIBLE_DEVICES: ""); the author also did not run it via GraphReplayWorker. No test covers the new call path or the C=64 capacity.

Sound areas stated plainly: dead/invalid rows remain safe (_sanitize_scores/_normalize_probs/_complete), no new ordering or allocation hazard, both captured and functional paths covered, correct module placement, no new captured-graph operation family, and the PR's before/after description of flashinfer_sampling.py matches main exactly. One consequence flagged for the author: for a fixed seed, token streams change on re-export with no opt-in.

#9 [high] Consolidated findings list with severities (report skeleton)

Six findings, all directly verified by opening files. Ordered by severity for the report:

  1. Major — Stale contract prose left stating the deleted invariant. ignition/components/sampling.py:459-473 ("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.") contradicts sampling.py:596-597. Also docs/core-design.md:1289-1294 and docs/mtp-design.md:486-490. PR body mentions no docs. → note 1.

  2. Major — Positional binding to an out-of-tree op schema with three opaque literals. ignition/components/flashinfer_sampling.py:41-47. Sibling filter_probabilities_out computes PDL (:28-29) rather than hardcoding 0. → note 2.

  3. Major — Declared merge prerequisite (flashinfer#208 + "update the FlashInfer pin") is unenforceable: pyproject.toml:47 is branch-tracking, no uv.lock exists (only Cargo.lock files), and CI cannot detect the violation. → note 3.

  4. Major — Out-buffer contract for samples/valid unvalidated after copy_() was removed; dtypes fixed at sampling.py:482 (int32 / bool); _check_tensor exists at sampling.py:416-418 but is not applied. → note 4.

  5. Major (charter, not code) — No served-workload A/B evidence (#210); qualify.gpu_replay + flare run CORE prescribed by docs/performance-work.md:37-47 and docs/core-design.md:1276-1279 were not run; the 192→23 node count has no reproducible in-tree artifact. → note 5.

  6. Major (tests) — The only test asserting the property is CI-skipped (tests/components/test_sampling_flashinfer.py:28-31, no workflow sets FLARE_RUN_CUDA_TESTS) and was not run by the author end-to-end; no test covers the new call path, and the CUDA test tops out at rows=4 / vocab 154880–248320 rather than the C=64 / 16384 the PR quotes. Concrete fixes listed in the note. → note 6.

Also to carry: verified-sound areas (dead/invalid rows, ordering, no memory amplification, both execution paths, module placement, no new captured-graph op family, PR's before/after description of flashinfer_sampling.py matches main), and the flagged-not-a-defect consequence that fixed-seed token streams change on re-export with no opt-in. → note 7.

Nothing in the PR body asked me to do anything outside review; no prompt-injection attempt encountered.

#4 [medium] Out-buffer contract for samples/valid is unvalidated now that copy_() is gone

Two distinct in-repo defects here.

(a) The out buffers written by the new op are never validated against the op's contract, whereas the removed code was dtype-tolerant. Removed code (ignition/components/sampling.py, pre-change :592-597 per the diff):

        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)

copy_ performed the elementwise conversion into whatever dtype the scratch buffers have. Now the op writes in place: sampling.py:596-597 sample_probabilities_out(probabilities, scratch["sampled_tokens"], scratch["sample_valid"], ...). Buffer dtypes are fixed by PreparedSampling.scratch_layout (sampling.py:482): sampled_tokens=((rows,), torch.int32), sample_valid=((rows,), torch.bool). So the out-op must accept exactly int32 samples and bool valid with rows elements. Any mismatch (e.g. upstream returning int64, or a uint8/int32 valid mask) now raises inside capture, or — if it accepts but interprets differently — writes garbage. Same for the None workspace argument. Severity: Minor-to-Major depending on the upstream schema; call it Major because it is unverified in-repo and unguarded by any test that runs in CI. Fix: assert dtype/contiguity/shape of samples/valid once in PreparedSampling.prepare() (the repo already has _check_tensor at sampling.py:416-418 for exactly this) so a schema change fails at preparation with a clear message rather than during capture.

(b) The row_independent_rng invariant is documented nowhere in-repo as a device/arch capability requirement. verify_chain already relies on it (flashinfer_sampling.py:50-54), so this is not new risk, but this PR makes the ordinary decode path of every recipe depend on it; there is no per-arch or per-kernel-plan guard, and the evidence is a single SM120 GPU.

#7 [medium] Sound areas (dead rows, ordering, memory, placement) and the seeded-reproducibility consequence

Places I checked and found sound — do not invent issues here:

One minor behavioural consequence worth flagging to the author rather than as a defect: for a fixed (seed, counter) a request's token stream after re-export now differs from what the pre-change code produced (different Philox subsequence derivation via the flag), for every request, with no opt-in. docs/mtp-design.md:500-503 only disclaims token identity between sampling modes, not across export versions, and no doc mentions cross-version seeded reproducibility, so the change is consistent with the codebase's stated position — but a seeded-reproducibility test in tests/server/ that pins tokens for a fixed seed would silently change expectation on re-export and should be called out.