Correctness and contracts report · NVIDIA/hyperflare-inference #642

Raw Markdown for agents: https://autobot.eidonix.com/p/62260174-add7-4a10-a0bb-6a799315a408.md

Correctness, Contracts & System-Level Consequences — PR #642

PR: NVIDIA/hyperflare-inference#642, ignition(preparation): skip unreferenced epilogue candidates in relocate_inductor, jcartu, head 5f6e6a6, 3 files (+414/−10). Reviewed in full at head: ignition/preparation/device_binding.py (212 lines), ignition/preparation/inductor_tuning.py (350 lines), tests/preparation/test_inductor_prepared_winners.py (665 lines), plus aot.py (_load_inductor 46–87, deserialize_compile_artifacts 500–548, _prepare_ranks 1213–1282), compilation.py:290–315, scripts/inspect_forward_kernels.py:36–99, and the same functions on main.

Key findings

Verdict: the core fix is correct and I found no blocker. The KeyError is structurally eliminated, the pre-mutation ordering fix is real on both functions, and the duplicate-key collapse bug is genuinely fixed. What remains is: (a) a widened failure surface on the frozen reload path that reaches a diagnostic tool which never called register before (Minor), (b) an undisclosed extra full-AST-parse cost on every frozen reload (Minor), (c) a bundle-identity change (Minor, no defect proven), (d) a degraded error message on the newly-first-firing path (Minor), and (e) one Major claim-accuracy problem: the hardware evidence was produced by a different, weaker, uncommitted guard at a commit that is not in this repository.

# Area Severity One line Citation
1 Correctness (sound) — KeyError gone; ordering and no-partial-mutation verified device_binding.py:189–211
2 Correctness/compat Minor Frozen no-relocate load now raises where main loaded; inspect_forward_kernels.py regresses to uncaught traceback device_binding.py:182–188; scripts/inspect_forward_kernels.py:85–98
3 System-level (cost) Minor 1–2 unconditional full ast.parse of the generated module per frozen reload; main parsed nothing device_binding.py:184, :105–114, :92–102
4 Aliasing/identity Minor graph._triton_bundle replaced instead of mutated; entry kernels still shared device_binding.py:185–187, :194–196, :209–211
5 Diagnostics Minor New ValueError names no kernel/key/count while register's message names all three device_binding.py:129 vs inductor_tuning.py:159–162
6 Claim accuracy Major "Claimed Result" hardware run used a different (substring) guard at non-repo commit 99339606 PR description, "Hardware reproduction provenance"
7 Test coverage Minor The GPU test asserting this exact contract was not updated or run; ≥2-rank test unrun tests/preparation/test_inductor_tuning_cuda.py:490–536, :553+
8 Concurrency/memory/parity/contracts — Cleared, no findings see "Cleared areas"
9 Test-count claims — Accurate: 18 pre-existing + 9 new = 27 tests/preparation/test_inductor_prepared_winners.py:317, :399–400, :471–472, :529, :606

1. Correctness — the central fix is sound (say so plainly)

The reported failure mode (kernel_keys[entry_kernel.cache_key] raising KeyError on an unfrozen peer load) is now impossible by construction. At head, the key map is built first and the filter's retained set is defined as the keys present in it:

   189      kernel_keys = {}
   190      rebound_source = _device_source(graph.source_code, original.index, target.index, kernel_keys)
   191      if bundle := graph._triton_bundle:
   192          retained = _filter_static_autotuners(bundle, rebound_source, kernel_keys)
   193          if freeze_tuning:
   194              retained_bundle = replace(bundle, static_autotuners=retained)
   195              _freeze_tuning_winners(retained_bundle)
   196              retained = retained_bundle.static_autotuners
   197      graph.source_code = rebound_source
   198      graph.cache_key = code_hash(rebound_source)
   199      graph.device_idxs = OrderedSet((target.index,))

(ignition/preparation/device_binding.py:189–199)

with the retention predicate at device_binding.py:122–125:

    for entry_kernel in bundle.static_autotuners:
        if entry_kernel.cache_key in bound_keys:
            retained.append(entry_kernel)
            continue

so kernel_keys[entry_kernel.cache_key] at device_binding.py:208 is reached only for keys known to be in kernel_keys. main did the opposite order — wrote graph.source_code/cache_key/device_idxs at :146–148 before the indexing loop at :151–157, and froze at :141–142 before validating anything — so the change is a genuine ordering fix, not a reshuffle.

Three further correctness claims verified:

Nothing in this area needs changing.

2. Minor — the frozen reload path now fails on artifacts main loaded, reaching a caller that never calls register

   182      if not relocate:
   183          if bundle := graph._triton_bundle:
   184              retained = _filter_static_autotuners(bundle, graph.source_code, _source_kernel_keys(graph.source_code))
   185              retained_bundle = replace(bundle, static_autotuners=retained)
   186              _freeze_tuning_winners(retained_bundle)
   187              graph._triton_bundle = retained_bundle
   188          return

(ignition/preparation/device_binding.py:182–188)

main's equivalent branch was device_binding.py:141–144 on main:

    if freeze_tuning and graph._triton_bundle is not None:
        _freeze_tuning_winners(graph._triton_bundle)
    if not relocate:
        return

So a frozen artifact (any prepared artifact, since InductorSelections.freeze sets backend._tuning_frozen = True at inductor_tuning.py:330, round-tripped through deserialize_compile_artifacts → frozen=fn._tuning_frozen → _load_inductor) whose bundle holds an entry that is module-referenced by identifier but has no async_compile.triton definition now raises ValueError("compiled forward has unbound static Inductor kernels") inside _load_inductor, where main loaded it and only failed later in InductorSelections.register.

For the preparation path this is intended and beneficial (it is tested — test_relocate_inductor_rejects_referenced_unbound_kernel_without_partial_mutation[(0, True), …] at test_inductor_prepared_winners.py:471–472 is the target == original, freeze_tuning=True case). The problem is the one production-adjacent caller that never reaches register:

    84                  bind_device('cuda:0'), _guard_code_cache(path.parent / 'guards')):
    85                  artifact, _ = _load_inductor(compiled, torch.device('cuda', ordinal), frozen=frozen)
...
    90              try:
    93                  InductorSelections('cuda:0').register(BoundForward(holder, None, True))
    95              except Exception as error:
    96                  report['registered'] = False
    97                  report['error'] = f'{type(error).__name__}: {error}'
    98                  failures += 1

(scripts/inspect_forward_kernels.py:84–98; frozen comes from the artifact at :62)

The try starts after line 85, so the new ValueError escapes as an uncaught traceback, aborting the whole multi-artifact sweep instead of emitting the JSON report with registered: false. The tool's stated purpose — auditing already-exported cores — is exactly the population that can hold such an entry.

Impact: diagnostic regression on scripts/inspect_forward_kernels.py --load for frozen artifacts; no runtime-serving impact. Fix: either (a) move the try to wrap _load_inductor as well and record the load failure into report, or (b) thread a drop_only=True flag through _filter_static_autotuners for the pure-reload branch at device_binding.py:184 (drop, don't raise), since that branch has no bindings to compare against and its caller cannot act on the ValueError.

3. Minor — undisclosed AST-parse cost added to the frozen reload path

device_binding.py:184 calls _source_kernel_keys(graph.source_code), which does its own full parse:

   105  def _source_kernel_keys(source):
...
   109      for node in ast.walk(ast.parse(source)):

and if any key is unbound, _filter_static_autotuners lazily pays a second full parse (device_binding.py:126–127 → _referenced_kernel_names → ast.parse(source) at :95). main's no-relocate branch (:141–144 on main) parsed nothing.

Impact: one or two extra full ast.parse passes of the entire generated Python module per forward on every frozen reload — i.e. every prepared-artifact load at matching device, not a rare path. Bounded (tens of ms per forward), unmeasured, and the PR description lists no such cost. Fix: walk the tree once and derive both the key set and the identifier set from it; or reuse the parse that _device_source already performs in the relocate branch.

4. Minor — bundle object identity now changes on freeze paths (reported for completeness, no defect proven)

   185              retained_bundle = replace(bundle, static_autotuners=retained)
   186              _freeze_tuning_winners(retained_bundle)
   187              graph._triton_bundle = retained_bundle

and again at :209–211. main mutated the bundle in place (bundle.static_autotuners[:] = entries.values() at device_binding.py:123). Note the asymmetry this creates: the bundle is now a fresh object while _freeze_tuning_winners still mutates the entry kernels in place (device_binding.py:161–163), so kernel objects remain shared between the pre-filter and post-filter bundles.

I traced the one place where sharing matters — aot.py:79–82 does graph._triton_bundle.kernel_artifacts.clear() on both entry and compiled.serialize(); replace(bundle, kernel_artifacts=[...]) at :209–211 builds a new list, but on the freeze paths neither branch rebuilds it (:194 only passes static_autotuners), so the shared list is still cleared correctly and no live kernel loses its artifacts. I could not construct a failure, so this is flagged only so the next reader does not assume in-place mutation semantics survive.

5. Minor — the new fail-closed error carries no diagnostic detail, and fires earlier than the message-rich one

   128          if entry_kernel.kernel_name in referenced_names:
   129              raise ValueError("compiled forward has unbound static Inductor kernels")

(ignition/preparation/device_binding.py:128–129)

Compare the pre-existing, strictly more informative message it now pre-empts on peer ranks and frozen loads:

   159                  raise TypeError(
   160                      f'generated Inductor kernel {name!r} in graph {graph.cache_key} lacks its static '
   161                      f'autotuner binding: live_type={kind}, source_key={cache_key}, '
   162                      f'bundled={cache_key in entries}, static_entries={len(entries)}')

(ignition/preparation/inductor_tuning.py:159–162)

Impact: on a peer TP rank the operator now sees a bare ValueError inside Load and warm compiled forwards with no kernel name, no cache key and no counts, where register used to name all three. This is not a regression in when preparation fails (_prepare_ranks catches per forward at aot.py:1233–1237 and reports f"{name}: {type(error).__name__}: {error}"), but it is a regression in the operator's ability to identify the offending kernel from a four-rank log, which is the whole reason this bug was hard to diagnose. Fix: one line — include entry_kernel.kernel_name, entry_kernel.cache_key, the number of unbound entries and how many of those were referenced, mirroring register's message.

Also worth recording as a residual (not a regression): _filter_static_autotuners can only raise for entries that exist in the bundle. The opposite direction — a module naming a kernel with no bundle entry at all — is still only caught later by register's TypeError at inductor_tuning.py:157–162, so on the relocate path such a forward passes the filter and fails afterwards. The description says this explicitly ("Not changed although related"), and I agree it is out of scope; but the new message text ("unbound static Inductor kernels") is broader than what the check actually detects.


6. Major — claim accuracy: the hardware evidence was produced by a different, weaker mechanism at a commit outside this repository

The "Claimed Result" paragraph leads with hardware language:

"Separately, on 4x RTX PRO 6000 Blackwell (sm_120, TP4) using a locally patched checkout of Flare v0.4.4 (99339606), skipping unreferenced static_autotuners entries in relocate_inductor unblocked qwen38 TP4 preparation through native core export and flare run health startup across all four ranks"

and only in the later provenance section admits what was actually run:

"On a locally patched checkout of 99339606 with an uncommitted guard in relocate_inductor that skipped static_autotuners entries absent from kernel_keys when entry.kernel_name was not a substring of graph.source_code"

That is the substring mechanism this PR replaces as unsound (the exact-identifier prefix-collision case is the bug it claims to fix, reproduced "in CPU unit tests"). The commit 99339606 is not on main (no history match), and the description also states: "No GPU preparation was run on 0a8c20f4 with this exact submitted diff, and standalone CUDA unit tests (tests/preparation/*_cuda.py (not opened)) were not run".

Impact: the fail-closed AST matcher — the entire behavioral core of the diff — has zero end-to-end evidence; its only support is CPU fixtures that monkeypatch deserialize_bundled_cache_entry, AOTCompiledArtifact, aot_autograd_result, SerializableCompiledFunction and simple_wraps (test_inductor_prepared_winners.py:317–328, 372–381). Under the Charter's "Bring real evidence … Bug fixes need to address the root cause" line, a reader may reasonably read a sm_120 TP4 unblock as validation of this code. It is a disclosure-ordering problem, not dishonesty — the Limitations section is candid. Fix: lead the "Claimed Result" with the CPU-verified statements, and state the hardware result as "a substring-guard prototype of the same policy unblocked TP4 preparation; the submitted exact-identifier implementation was not exercised on GPU, and tests/preparation/test_inductor_tuning_cuda.py was not run." Running the two CUDA test files (or one TP4 prep on the submitted diff) would close this.

7. Minor — the GPU test that asserts this exact contract was neither updated nor run

tests/preparation/test_inductor_tuning_cuda.py:490–536, test_unreferenced_bundled_candidates_are_dropped_and_named_kernels_still_bind (added by merged PR #185), asserts precisely the invariant this PR rewrites. I traced it against the new logic and it looks compatible — the injected candidate uses kernel_name=str(Placeholder.DESCRIPTIVE_NAME) (:514), which can never be an ast.Name id, so it is still dropped, and the second half keeps the original kernel_name (:533–534) and still expects the ValueError (:535) — but "looks compatible by inspection" is exactly the claim class #623/#624 had to repair. The only ≥2-rank torchrun test in the neighbourhood (:553+, test_distributed_catalog_reconciles_real_conflicting_candidates) is the true TP peer-rank regression and was also not run.

Fix: run both files on the submitted diff and report the result; if they pass, add one sentence to the Limitations section naming them.

8. Test-count and behavior claims that I verified as accurate

9. Cleared areas (explicitly no findings)

Open questions / could not verify

  1. Whether the widened frozen-reload failure (finding 2) is intended for non-preparation callers — the PR description scopes the change to _prepare_ranks/_warm and does not mention scripts/inspect_forward_kernels.py --load.
  2. No independent reproduction of the TP4 KeyError exists: no issue, no second report; the PR description is the sole evidence, and the forward name speculative16x5 and checkpoint dc5b8ab2 have no counterpart in this repo.
  3. The actual added cost of finding 3 — neither measured by the author nor measurable here (no CPU fixture timings reported).
  4. Whether #597 (open, same file, import-line overlap) or a #584 re-open lands first; both would conflict textually with this diff.
  5. No CI signal exists for 5f6e6a6, so every test number in the description is self-reported; I verified the counts by reading the file but could not re-run them.