Code review summary report · NVIDIA/hyperflare-inference #581

Raw Markdown for agents: https://autobot.eidonix.com/p/a70fb03f-3f50-4335-8956-f5de4a338ecc.md

CANDIDATE BRIEF — PR #581 "ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs"

PR: #581, FujitsuPolycom (CONTRIBUTOR), perf/ignition-export-use-node-priority → main, head 61f64f18e06cdcb9de76c33765584a97752f3953, base main 167f22c8. Open, "ready for review", 3 files, +137/−7 (ignition/preparation/runtime_core.py +38/−1, tests/preparation/test_capture_graph_metadata.py +96/−3, tests/preparation/test_recorded_export_graph_cuda.py +3/−3). No CI checks configured. Priority reviewer voipmonitor = CHANGES_REQUESTED (2026-11-28 22:13) with a live SM120 run: CPU suite 12 passed; FLARE_RUN_CUDA_TESTS=1 CUDA test 1 passed (3.29 s), flags_by_name == {"decode": 9, "tune": 1}. Only other comment is a flare-autobot case-file notice (not a finding, no injection attempt).

This brief merges six lenses (Architecture, Conventions, Simplicity, Correctness, Prose, Subtractive), keeps the subtractive option wherever a lens wanted to expand what another wanted to delete, and quotes verified code under each surviving candidate.


Key findings

  1. One real production change. record_export_graph now queries cuGraphExecGetFlags on the freshly instantiated executable and records prior_flags | 8, so _graphs emits {name, graph(template), instantiate_flags} instead of {name, graph, executable}. Helios genuinely consumes it — cuGraphInstantiateWithFlags(&mut executable, handle, graph.flags) (helios/src/runtime_core/mod.rs:1215-1219) — and heliopause already accepted bit 8 on main (flags & !9 at heliopause/src/export/capture.rs:589, :2823; helios/src/runtime_core/format.rs:495, all verified at ref: main). So the wire value is not new and pre-existing flags=1 cores still load.
  2. The disputed judgment call is scope, not correctness: bit 8 is enabled for every exported serving graph by a Python default, with no served-workload measurement (charter #210; "No magic defaults"). The only in-repo source of non-default priority is the TP overlap stream (ignition/preparation/scratch.py:88-101), so most graphs get a scheduling mode they never asked for.
  3. Around that one line the PR ships ~104 of its 144 added lines as removable surface: an unused keyword (instantiation_flags) with unreachable None/0 modes, a 6-line record-side guard that duplicates _graphs:284 and three Rust validators, an FFI helper + OR whose only purpose is carrying bit 1 that cannot matter at replay, and ~79 duplicated test lines. The subtractive version is one assignment.
  4. The PR description misstates its own behaviour in two places (executable-derived rejection happens after mutation; the None mode's "startup tuning graphs" caller does not exist), both confirmed by voipmonitor independently.
  5. Evidence that survives: the real FFI and the {decode: 9, tune: 1} mapping were verified on SM120 by voipmonitor. Lenses calling that assertion "skipped/unverified" are stale; the residual fact is only that CI never runs it (opt-in FLARE_RUN_CUDA_TESTS=1, tests/preparation/test_recorded_export_graph_cuda.py:14).

Candidate Blockers

B1 — USE_NODE_PRIORITY is default-on for every exported serving graph, with no served-workload evidence

Sources merged: Architecture B1 (blocking), voipmonitor Major 1, Correctness #3 (unmeasured half), Subtractive #1 (partial). Framed as architecture/policy rather than test nit.

ignition/preparation/runtime_core.py:208-214

208  def record_export_graph(
209      graph,
210      storage,
211      *,
212      owners=(),
213      instantiation_flags=CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY,
214  ):

ignition/preparation/runtime_core.py:236-243

236      graph.retain_object((pools, tuple(owners)), synchronize_before_release=True)
237      instantiate_graph(graph)
238      if instantiation_flags is not None:
239          prior_flags = _executable_instantiation_flags(graph)
240          if prior_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS:
241              raise ValueError("captured graph executable carries unsupported CUDA instantiation flags")
242          graph._flare_instantiation_flags = prior_flags | instantiation_flags
243      return graph

Blast radius — ignition/preparation/capture.py:168-171 and :192-197:

170              exporting = retain_graphs and warmup_storage is not None
171              graph = torch.cuda.CUDAGraph(keep_graph=True) if exporting else capture_graph(retain_graphs=retain_graphs)
...
192                  if exporting:
193                      graph = record_export_graph(graph, warmup_storage, owners=(function,))

i.e. every graph of every recipe on every parallel layout that goes through the serving-catalog export path — because the value is the default, not a per-graph decision.

The only in-repo source of non-default priority — ignition/preparation/scratch.py:88-101:

 88              from cuda.bindings import driver as cuda
 90              # PyTorch's round-robin stream pool can alias a later capture stream.
 91              # Highest stream priority lets small collective kernels preempt main-stream GEMMs.
 93                  pstatus, _least, greatest = cuda.cuCtxGetStreamPriorityRange()
 95                      status, handle = cuda.cuStreamCreateWithPriority(
 96                          cuda.CUstream_flags.CU_STREAM_NON_BLOCKING, greatest
 97                      )

Verified: a grep over ignition/ finds no other priority usage (no CU_LAUNCH_ATTRIBUTE_PRIORITY, no cuLaunchKernelEx). So the flag selects a scheduling mode most captured graphs never asked for, on a TP-overlap-only construct.

A data-driven trigger is already available: heliopause serializes kernel-node attribute id 8 and Helios replays it (heliopause/src/export/capture.rs:544-569; helios/src/runtime_core/mod.rs:984-1013), so "enable node priority only when a recorded node carries a priority attribute" is derivable at export time and satisfies design-review principle 1 ("express differences through prepared layout metadata") without a constant default.

Governing text: charter "Bring real evidence. Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)"; "Be explicit and pin everything. No magic defaults"; docs/design-review.md:109-114 ("Performance claims require equivalent baselines … actual Helios service measurements … disclose unrun checks").

Adjudication question (D1): blocking, or acceptable as a disclosed follow-up given (i) bit 8 is already accepted by main's validators, (ii) voipmonitor's export test passes on SM120, (iii) the PR's own limitations paragraph discloses unrun flare run replay? Charter #210 / "no magic defaults" argue block; backward compatibility and the honest disclosure argue follow-up. A priority reviewer has already returned CHANGES_REQUESTED partly on this point.


B2 — ~104 of 144 added lines are an unused switch plus a duplicated guard; the intended change is one assignment

Sources merged: Subtractive #1 (blocking there), Architecture S1, Conventions 1 & 5, Simplicity F1/F2, Correctness #3, Prose #2. Per the dedup rule, the subtractive option is kept over any lens asking to expand the same code.

Unused modes — ignition/preparation/runtime_core.py:224-229:

224      if instantiation_flags is not None and (
225          type(instantiation_flags) is not int
226          or instantiation_flags < 0
227          or instantiation_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS
228      ):
229          raise ValueError("graph instantiation flags may only select automatic free and node priority")

The guard already exists in the same module — ignition/preparation/runtime_core.py:282-292:

282          flags = getattr(graph, "_flare_instantiation_flags", None)
283          if flags is not None:
284              if type(flags) is not int or flags < 0 or flags & ~9:
285                  raise ValueError("graph instantiation flags may only select automatic free and node priority")
286              result.append(dict(name=name, graph=int(graph.raw_cuda_graph()), instantiate_flags=flags))
287              continue
288          executable = int(graph.raw_cuda_graph_exec())

Verified facts: (a) the only production call site is capture.py:193, which passes no kwarg; (b) None is passed only at tests/preparation/test_capture_graph_metadata.py:240 and 0 only at :234; (c) the new constant is introduced but _graphs:284 still hardcodes ~9 with the identical message text; (d) the record-side guard cannot catch anything _graphs misses, because it stores prior | requested and _graphs re-validates the stored word on every export; (e) tests/preparation/test_runtime_core.py:18-37 already covers that surviving guard:

 18  @pytest.mark.parametrize("flags", [0, 1, 8, 9])
 19  def test_template_export_declares_flags_without_an_executable(flags):
...
 31  @pytest.mark.parametrize("flags", [-1, True, 2, 4, 16, 1.0])
 32  def test_template_export_rejects_unsupported_flags(flags):
 36      with pytest.raises(ValueError, match="instantiation flags"):
 37          _graphs({"decode": SimpleNamespace(_flare_instantiation_flags=flags)})

AGENTS.md:188-193: "Reject unsupported abstractions and churn. Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement."

Target shape (verified equivalent for the only caller, since _graphs:282-292 is the sole reader of the attribute):

def record_export_graph(graph, storage, *, owners=()):
    ...
    graph.retain_object((pools, tuple(owners)), synchronize_before_release=True)
    instantiate_graph(graph)
    graph._flare_instantiation_flags = (
        _executable_instantiation_flags(graph) | CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY
    )
    return graph

plus _graphs:284 using ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS. Deletes: signature kwarg (:213), validation (:224-229), the is not None wrapper (:238), the duplicate prior_flags guard (:240-241), the 4-line docstring paragraph (:219-222), and the tests that only exercise the deleted modes.

Adjudication question (D2): blocking churn vs. defensive validation at the record boundary (a capture-time error is earlier and has a distinct message than an export-time one). If an external caller (hyperflare-recipes) passes non-default instantiation_flags, B2 collapses to the constant-reuse half (T4). Not verifiable from this repo; the description names no such caller.


Candidate Should Fix

S1 — Rejection of unsupported executable bits happens after the graph is mutated, contradicting the description

Sources merged: Conventions 2, Correctness 1, Prose 3, Architecture N1, voipmonitor Minor 3 (first bullet).

ignition/preparation/runtime_core.py:224-243 (requested-flag check is before mutation; the executable-derived check is after):

224      if instantiation_flags is not None and (
...
229          raise ValueError("graph instantiation flags may only select automatic free and node priority")
...
236      graph.retain_object((pools, tuple(owners)), synchronize_before_release=True)
237      instantiate_graph(graph)
238      if instantiation_flags is not None:
239          prior_flags = _executable_instantiation_flags(graph)
240          if prior_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS:
241              raise ValueError("captured graph executable carries unsupported CUDA instantiation flags")

The new test documents the asymmetry — tests/preparation/test_capture_graph_metadata.py:244-255:

244      unsupported_exec = Graph(keep_graph=True, exec_flags=2)
247      with pytest.raises(ValueError, match="unsupported CUDA instantiation flags"):
248          record_export_graph(unsupported_exec, storage, owners=(kernel_owner,))
...
250      bad = Graph(keep_graph=True)
253      with pytest.raises(ValueError, match="instantiation flags"):
254          record_export_graph(bad, storage, instantiation_flags=2)
255      assert bad.instantiations == 0 and not bad._retained.objects

The bad (requested-flag) case asserts no partial mutation; the unsupported_exec case asserts nothing about post-failure state — the graph stays instantiated, owners stay retained, _flare_instantiation_flags is unset. docs/design-review.md:187-189 requires tests that "validate rejection without partial mutation"; AGENTS.md:103-109 requires claims tied to the behaviour tested.

Refutation to keep the adjudicator honest: this is not a new failure mode. Pre-PR, bit 2 was already rejected downstream — heliopause/src/export/capture.rs:589 (if graph == 0 || context == 0 || flags & !9 != 0) inside record_graph, reached via capture.rs:788-794 when instantiate_flags is None. Correctness #1's "export regression on drivers that set bit 2" is therefore overstated; the real defect is the ordering claim plus the missing assertions.

Fix: assert the post-failure contract (mirroring :255) and/or document it; or reset on that path.


S2 — _flare_instantiation_flags has no invalidation path (stale flag word survives re-record/reset)

Source: Correctness 2 (should-fix, unreachable today); corroborated by voipmonitor Minor 2.

State that is invalidated on executable death — ignition/preparation/runtime_core.py:153-158:

153      def release(self, executable):
154          try:
155              self.recorder.release_graph(executable)
156          finally:
157              if self.executable == executable:
158                  self.executable = 0

versus the new attribute, runtime_core.py:238-243 (quoted in B2), which _graphs:282-287 prefers over the live executable.

Two holes: (a) re-recording with None leaves the old attribute in place — the test at :241 only asserts absence on a fresh graph; (b) after graph.reset() + re-capture (tests/preparation/test_recorded_export_graph_cuda.py:88-90 calls graph.reset() twice), _graphs still emits the stale word rather than the new executable's flags. Heliopause cannot detect it: (g.executable == 0) == g.instantiate_flags.is_none() holds by construction (heliopause/src/export/capture.rs:2820-2824), so the mismatch is erased from the wire.

Should-fix rather than blocking only because the sole caller allocates a fresh torch.cuda.CUDAGraph(keep_graph=True) per capture (capture.py:171). Fix: graph.__dict__.pop("_flare_instantiation_flags", None) at function entry, plus drop it from the destroy callback registered at runtime_core.py:166.


S3 — record_export_graph accepts a keep_graph=False / _flare_graph_metadata graph, failing only later in _graphs

Source: voipmonitor Major 2 — no lens covered this (Architecture explicitly declined it); carried on his authority plus my own verification, so the adjudicator does not lose it.

The metadata path it must reject — ignition/preparation/runtime_core.py:251-260:

251      if not retain_graphs:
252          return torch.cuda.CUDAGraph()
253      images = ModuleImages.current()
254      if images is None:
255          return torch.cuda.CUDAGraph(keep_graph=True)
256      graph = torch.cuda.CUDAGraph(keep_graph=False)
257      metadata = _RecordedGraphMetadata(images.native)
258      graph._flare_graph_metadata = metadata
259      graph.register_post_instantiate_hook(metadata.record)

The new write it feeds — runtime_core.py:238-242 + :286 graph=int(graph.raw_cuda_graph()) — raises once the template is released (tests/preparation/test_capture_graph_metadata.py:124-125, RuntimeError: template was released). Reachability: capture.py:171 uses keep_graph=True on the exporting branch and the keep_graph=False graphs only reach instantiate_graph (capture.py:194-197), so no in-repo caller hits it today — a latent public-API hazard that fails late instead of up front. Note B2's rewrite does not add the guard by itself.

Adjudication question (D4): Major (latent API contract) vs. should-fix given unreachability.


S4 — The preserve/combine path is proven only through a monkeypatched helper; the one real-driver test is opt-in and outside CI

Sources merged: Conventions 4, Architecture S3, Correctness #3 (test caveat) — downgraded because voipmonitor ran the real test and it passed.

The monkeypatch — tests/preparation/test_capture_graph_metadata.py:107-114:

107  @pytest.fixture
108  def recorder(monkeypatch):
...
113      monkeypatch.setattr(runtime_core, "_executable_instantiation_flags", lambda graph: graph.exec_flags)

so the only line that calls the driver, ignition/preparation/runtime_core.py:200-205, is exercised solely by tests/preparation/test_recorded_export_graph_cuda.py, gated at :14 by @pytest.mark.skipif(os.environ.get("FLARE_RUN_CUDA_TESTS") != "1", ...). Real assertion:

 85              flags_by_name = {value.name: value.flags for value in index.ranks[0].graphs}
 86              assert flags_by_name == {"decode": 9, "tune": 1}

which voipmonitor reports passing on SM120. Residual risk is the CI gap only: nothing regresses the FFI signature or the assumption that a Torch-instantiated graph reports 1. AGENTS.md:194-199: "mocks that bypass the behavior cannot establish runtime correctness". Low-cost fix: a CPU test that stubs _Cuda.call and asserts the driver name/argument shape, or a GPU CI lane.


S5 — The new driver call bypasses the pinned cuda.bindings pattern and re-opens libcuda per graph

Sources merged: Conventions 3, Simplicity F3, Correctness 4, voipmonitor Nit 4.

ignition/preparation/runtime_core.py:200-205:

200  def _executable_instantiation_flags(graph) -> int:
201      """Read the CUDA instantiation bitmask recorded on a live ``CUgraphExec`` handle."""
202      executable = int(graph.raw_cuda_graph_exec())
203      flags = C.c_uint64(0)
204      _Cuda().call("cuGraphExecGetFlags", C.c_void_p(executable), C.byref(flags))
205      return int(flags.value)

Repo pattern is the typed bindings — cuda-python==13.3.1 pinned (pyproject.toml:26), used as from cuda.bindings import driver as cuda in ignition/preparation/capture.py:43-47 and scratch.py:88-102. Handles are normally long-lived (core_storage.py:76 (not opened), virtual_storage.py:27 (not opened)); _Cuda.__init__ does CDLL/WinDLL (runtime_core.py:77-78), so this adds one dlopen per exported graph. _Cuda.call raises instead of returning a status. Heliopause already has the same query typed (heliopause/src/export/capture.rs:517-527, fn executable_flags).

Unverified, do not assert: whether cuda.bindings 13.3.1 exposes cuGraphExecGetFlags/CUgraphInstantiate_flags under those names — the lens cited the repo pattern, not the installed package. If absent, keep the ctypes call and fix only the handle reuse. Nit-grade if B2/T2 deletes the helper entirely.


Candidate Subtract / Simplify

T1 — Delete the instantiation_flags kwarg, its None/0 branches and the record-side guard

Source: Subtractive #1; merges Architecture S1, Conventions 5, Simplicity F1/F2. Target shape and deletions are in B2; ~14 production lines plus ~34 test lines (tests/preparation/test_capture_graph_metadata.py:222-255 scenarios no_autofree, preserved_only, plain, unsupported_exec, bad, plus the fixture at :31/:113). Dissent to weigh: the guard is the only capture-time error with a distinct message, and the author may want it as boundary validation; voipmonitor asked only for constant reuse, not deletion.

T2 — Delete _executable_instantiation_flags and the prior | … join: bit 1 cannot matter for an exported template

Source: Subtractive #2 — strongest subtractive argument; its premise is verified.

Replay never reuses the exported executable — helios/src/runtime_core/mod.rs:1215-1219:

1215                  let mut executable = null_mut();
1216                  driver.check(
1217                      "cuGraphInstantiateWithFlags",
1218                      (driver.graph_instantiate)(&mut executable, handle, graph.flags),
1219                  )?;

and the export recorder rejects allocation/free node kinds — heliopause/src/export/capture.rs:607-679: accepted kinds are 0 kernel, 1 copy, 2 memset, 5 empty, 6 event-wait, else return Err(invalid(format!("unsupported CUDA graph node type {kind}"))). Kinds 3/4 can never appear in an exported template, so AUTO_FREE_ON_LAUNCH (=1) has no allocation node to free at replay. Result: _flare_instantiation_flags = 8 suffices; the FFI call (:200-205), the join (:242) and S5 vanish; the CUDA assertion becomes {"decode": 8, "tune": 1}, still inside every !9 validator.

Correction to Subtractive: node kinds 5 and 6 do reach export, so "exactly three node kinds" is wrong; only the "no allocation/free nodes" conclusion holds. Counter-argument: preserving bit 1 is the PR's stated purpose and costs nothing at runtime if the helper stays. Adjudication question (D3).

T3 — Delete test_capture_forwards_export_sets_node_priority_instantiation_flag (45 lines)

Sources merged: Subtractive 3, Simplicity F5, Conventions 6.

tests/preparation/test_capture_graph_metadata.py:276-302 re-installs the same eight torch.cuda monkeypatches used by the neighbouring test (:277-283), stubs capture._warmup_stream/_seed_warmup_workspaces, and asserts:

299      assert _graphs(graphs) == [
300          dict(name="prefill", graph=11, instantiate_flags=expected_combined),
301          dict(name="decode", graph=11, instantiate_flags=expected_combined),
302      ]

The same value is asserted right after the only writer (:216-218) and end-to-end on real CUDA (test_recorded_export_graph_cuda.py:86, passing on SM120). Its only unique fact is "capture.py:193 omits the kwarg" — a pass-through that disappears with T1. Dissent: it is the only test proving the capture→export plumbing reaches the attribute; keep one line of it if T1 is rejected. Adjudication question (D5).

T4 — Collapse the three new constants and use the mask at _graphs:284

Sources merged: Subtractive 4, Conventions 1, Prose 5, voipmonitor Nit 4, Simplicity F2.

ignition/preparation/runtime_core.py:192-197:

192  CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH = 1
193  CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY = 8
194  PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS = (
195      CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH
196      | CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY
197  )

versus the surviving hardcoded flags & ~9 at :284 and the message duplicated verbatim at :229 and :285. After T2, AUTO_FREE_ON_LAUNCH and the mask lose their last production readers. Keep one constant with a one-line comment naming Helios's accepted set (helios/src/runtime_core/format.rs:495), and use it at :284.


Candidate Nits

N1 — PR description accuracy (one combined prose item, four sub-points)

Per the "at most 1 mechanical prose item" rule, merged instead of four separate notes. (a) "rejecting unsupported bits on either source before mutating graph state" is false for the executable-derived source (runtime_core.py:236-241; see S1). (b) "Passing instantiation_flags=None keeps executable-derived flags for startup tuning graphs" describes no caller: the only call site is capture.py:193 (default), and tuning graphs go through capture_graph + instantiate_graph (runtime_core.py:246-269; tests/preparation/test_recorded_export_graph_cuda.py:62-65) and export via the plain executable form at runtime_core.py:288-292 — which is exactly why the CUDA test expects tune: 1. (c) "Before:" describes an implementation that never shipped — on main record_export_graph recorded no flags and _graphs emitted {graph, executable} (verified at ref: main), and its parenthetical "(or replaced the whole flag word …)" is an abandoned alternative. (d) "Candidate 61f64f1… on main" mislabels this PR's own head commit (branch perf/ignition-export-use-node-priority) and uses an undefined lifecycle label. Cited: AGENTS.md:88-94, :103-112, :129-132; docs/design-review.md:153-155. voipmonitor Minor 3 covers (a) and (b). Checked clean, do not raise: the four-part order (Why / What changed / Claimed benefit / Supporting evidence and limitations), the Discord: Dooner line, and the honest disclosure of unrun live checks all satisfy the rules.


Dropped as noise (considered, deliberately not passed downstream)

Verified non-findings (checked, no defect)

Open questions / not verifiable from the code

  1. D1–D5 in the summary — the five judgment calls for the frontier adjudicator (B1 severity; B2 vs defensive validation; whether to demand T2; S3 severity; T3 deletion).
  2. Whether any external caller (hyperflare-recipes) passes a non-default instantiation_flags — unverifiable here; the description names none.
  3. Whether cuda.bindings 13.3.1 exposes cuGraphExecGetFlags/CUgraphInstantiate_flags under those names (S5) — repo pattern cited, not the installed package.
  4. Whether node priority actually helps on the served workload — needs the flare run measurement the PR defers; no number exists in the PR or the repo.
  5. Whether a priority-stream-only trigger matches intent for non-TP layouts: the auxiliary priority stream is verifiably TP-overlap-only (scratch.py:88-101), but not that every such graph needs the flag, nor that no other capture path wants it — an author design call.
  6. Whether any supported driver/Torch combination sets an instantiation bit outside 1|8 on a captured exec — a target-matrix run printing cuGraphExecGetFlags for both the serving and tuning graphs would settle S1's reachability.