Correctness report · NVIDIA/hyperflare-inference #581

Raw Markdown for agents: https://autobot.eidonix.com/p/929778e7-b153-4539-a178-5a218ee87762.md

Correctness review — PR #581 ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs

Head 61f64f18, base main 167f22c88076c1da801fe0ceca35f846d7295b24, 3 files, +137/−7. Verdict: no blocking correctness defect in the change itself; three should-fix items plus one nit.

Key findings

Findings

1. Should fix — executable-derived flag rejection happens after graph mutation

ignition/preparation/runtime_core.py:224-229 (requested-flag check), :236 (retain_object), :237 (instantiate_graph), :238-242 (read + validate prior flags).

The requested-flag validation runs before any mutation, but the executable-derived check runs only after graph.retain_object((pools, tuple(owners)), synchronize_before_release=True) and instantiate_graph(graph). On a prior_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS hit at :240-241 the function raises with:

The only caller, ignition/preparation/capture.py:193, calls record_export_graph inside capture_forwards's try/except Exception as error: error.add_note(...); raise (:198-200), i.e. it propagates and abandons the partially-mutated graph mid-capture.

Why it matters:

Test coverage: the new case at tests/preparation/test_capture_graph_metadata.py (the unsupported_exec graph with exec_flags=2) asserts only that ValueError is raised. Contrast the bad case in the same test, which does assert post-failure state: assert bad.instantiations == 0 and not bad._retained.objects. So the new test actively documents the asymmetry rather than catching it.

Fix: either mask/report unpermitted executable bits instead of hard-rejecting, or define the post-failure state (e.g. graph.reset() on that path) and assert it in the test as the bad case does. At minimum correct the description.

2. Should fix — new _flare_instantiation_flags state is never invalidated

Set at ignition/preparation/runtime_core.py:238-242; consumed at :282-287.

Two related defects about state living outside CUDA's lifecycle:

(a) instantiation_flags=None skips rather than clears. record_export_graph defaults instantiation_flags to CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY (:213) and only assigns the attribute when the argument is not None (:238). If a graph that already carries _flare_instantiation_flags is recorded again with None, the stale attribute survives and _graphs() keeps emitting the template+instantiate_flags shape (no executable) instead of falling back to the live executable at :288-292. The new test asserts not hasattr(plain, "_flare_instantiation_flags") only for a fresh graph, so the clearing behaviour is untested — and absent.

(b) Nothing clears the attribute when the executable dies. Every other piece of export-time graph state is invalidated on that event: _RecordedGraphMetadata.release (:153-158) zeroes self.executable from the destroy callback registered in record() (:166), and RecordedExportGraph.reset (:185-189) drops recorded/pools/owners. torch.cuda.CUDAGraph supports reset() and re-capture (the CUDA test at tests/preparation/test_recorded_export_graph_cuda.py calls graph.reset() twice in a row). After such a reset, _graphs() still prefers the stale attribute (:282-283) over the new executable and publishes a flag word computed from an executable that no longer exists.

Crucially, the receiving side cannot detect this: heliopause capture_rank enforces (g.executable == 0) == g.instantiate_flags.is_none() (heliopause/src/export/capture.rs:2820-2824), and the flag shape satisfies that invariant by construction — the executable/flags mismatch has been erased from the wire, so the guard that protects the non-flag shape cannot fire here.

Severity is should-fix, not blocking, only because the sole caller allocates a fresh torch.cuda.CUDAGraph(keep_graph=True) per capture (capture.py:171), so the stale path is not reachable from capture_forwards today.

Fix: clear the attribute at the start of record_export_graph (graph.__dict__.pop("_flare_instantiation_flags", None)) and register a destroy callback alongside the one in _RecordedGraphMetadata.record that drops it. Note the deferred/reset graphs of issues #395 and #266 are exactly the nearby patterns where a graph outlives its executable.

3. Should fix (prose / coverage) — the documented None path is dead, and the perf claim is unmeasured

4. Nit — a fresh _Cuda per exported graph

ignition/preparation/runtime_core.py:200-205: _executable_instantiation_flags constructs a new _Cuda() per graph, re-CDLL-ing libcuda.so.1 for each serving graph, while heliopause caches one instance (heliopause/src/export/capture.rs:745, 756). Matches voipmonitor's nit 4.

Verified clean (checked, no defect)

Open questions / what only a test or GPU run can settle

  1. Does any supported driver/torch combination set an instantiation bit outside 1 | 8 (e.g. DEVICE_LAUNCH=2) on a captured exec? If so, finding 1 is a live export regression on that target, not merely an error-path hygiene issue. Settling it needs a CUDA run across the target matrix that prints cuGraphExecGetFlags for both the decode/serving graph and the tuning graph.
  2. Do the stale-flag scenarios in finding 2 occur in practice? They need either a record_export_graph(..., instantiation_flags=None) call site (none exists today) or a graph that is reset()/re-captured after export (not done in capture_forwards, but permitted by the CUDAGraph API). A unit test that records, resets, re-captures and re-exports would settle it.
  3. Whether instantiation with USE_NODE_PRIORITY changes served behaviour on non-default kernel priorities remains unmeasured in this revision, as the description acknowledges.

Rules cited