Subtractive report · NVIDIA/hyperflare-inference #581

Raw Markdown for agents: https://autobot.eidonix.com/p/080b2995-e4ae-40b2-904d-c43c4b4ef4f1.md

Key findings

PR #581 lands the right one-line fact — exported serving graphs must be instantiated with CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY (8) — but wraps it in ~104 lines of code and tests that are not needed: a keyword parameter with one real value (instantiation_flags), a 6-line validation block that duplicates checks already performed in _graphs() and twice in Rust, a 7-line cuGraphExecGetFlags FFI helper whose only purpose is to carry bit 1 onto a template that contains no memory-allocation nodes, and 79 test lines that re-prove assertions the existing tests already make. Of the +137/−7 diff, roughly 104 added lines (≈72%) can go; the production change reduces to one constant plus one assignment.

Ranked by lines saved:

# Severity Where Lines saved
1 Blocking ignition/preparation/runtime_core.py:213, 219–229, 238–243 + tests/preparation/test_capture_graph_metadata.py:222–255 ~14 prod + ~34 test
2 Should fix ignition/preparation/runtime_core.py:192–197, 200–205, 239–242 (+ CUDA test expectation) ~11 prod, ~10 test
3 Should fix tests/preparation/test_capture_graph_metadata.py:258–302 45 test
4 Nit runtime_core.py:192–197 vs _graphs() 284 ~5 prod
5 Nit runtime_core.py:201, 219–222 (docstrings) ~5 prod

Charter citations used below: "Be explicit and pin everything. No magic defaults", "No per-model special cases or flags", "Look for the smallest footprint in shared code, or a way to solve it without new code at all" (read_charter).


1. Blocking: instantiation_flags is a parameter with one real value; its None/0 branches serve only its own tests (~48 lines)

ignition/preparation/runtime_core.py:208–229, 238–243 — the new keyword instantiation_flags=CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY (line 213), its 6-line type/range/mask validation (224–229), and the if instantiation_flags is not None: wrapper (238) that gates the whole flag write.

The only production caller is ignition/preparation/capture.py:193:

graph = record_export_graph(graph, warmup_storage, owners=(function,))

It never passes the keyword, and a repo-wide search for record_export_graph( finds only capture.py:193, tests, and a test double in tests/preparation/test_capture_rank_readiness.py:61 (not opened). Of the parameter's three accepted states (8, None, 0) only the default is reachable in production.

The stated rationale for None — PR description, "Passing instantiation_flags=None keeps executable-derived flags for startup tuning graphs" — points at graphs that never reach this function: tuning graphs go through capture_graph(retain_graphs=True) + instantiate_graph (capture.py:171, 194–197; runtime_core.py:246–260, 263–269). Reviewer voipmonitor reached the same conclusion independently (#581 review, Minor item 3: "startup tuning graphs do not call record_export_graph at all"). With the keyword gone, graph._flare_instantiation_flags is simply always set, so the "flags or executable" fork in _graphs() (runtime_core.py:282–292) keeps only the branch the export path actually uses.

Nothing is lost by deleting the validation either: the identical rule and the identical error message already live in _graphs() (runtime_core.py:284–285: type(flags) is not int or flags < 0 or flags & ~9 → "graph instantiation flags may only select automatic free and node priority") and twice in Rust (heliopause/src/export/capture.rs:589, capture.rs:2823, helios/src/runtime_core/format.rs:495). Validating the same mask at a third layer is the duplication the charter's "smallest footprint" line asks against.

Smaller version (production diff for this whole PR becomes +2 lines):

CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY = 8

def record_export_graph(graph, storage, *, owners=()):
    """... existing docstring, unchanged ..."""
    pools = (storage.pool, storage.graph_pool)
    ...
    graph.retain_object((pools, tuple(owners)), synchronize_before_release=True)
    instantiate_graph(graph)
    graph._flare_instantiation_flags = CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY
    return graph

Tests: tests/preparation/test_capture_graph_metadata.py:222–255 (four scenarios no_autofree, preserved_only, plain, unsupported_exec, bad) exist only to exercise exec_flags/instantiation_flags values 0, None, 2 that no caller passes; the exec_flags constructor parameter and the runtime_core._executable_instantiation_flags monkeypatch added at test_capture_graph_metadata.py:31, 113 go with them. ~34 test lines.

2. Should fix: the cuGraphExecGetFlags query plus prior_flags | … join exist to carry AUTO_FREE_ON_LAUNCH, which cannot affect an exported core (~21 lines)

ignition/preparation/runtime_core.py:192–197, 200–205, 239–242. _executable_instantiation_flags (7 lines including docstring) opens libcuda to call cuGraphExecGetFlags, and the result is used only to OR bit 1 into the recorded flags (prior_flags | instantiation_flags).

Replay never reuses that executable: Helios builds a fresh one from the exported template with cuGraphInstantiateWithFlags(&mut executable, handle, graph.flags) (helios/src/runtime_core/mod.rs:1215–1219). Bit 1 (CU_GRAPH_INSTANTIATE_AUTO_FREE_ON_LAUNCH) frees memory-allocation nodes owned by that executable; the exported template carries none — the Heliopause recorder handles exactly node kinds 0 kernel, 1 copy, 2 memset (heliopause/src/export/capture.rs:607–665, node_kind at capture.rs:229–239), and the wire/proto message has exactly those three node kinds. So preserving bit 1 changes nothing at replay; it only costs an FFI call per graph, an int join, a validation branch, the 5-line docstring justification, and the {"decode": 9, "tune": 1} expectation.

The same query is already performed, and validated against the same mask, by the layer that owns the flags: heliopause/src/export/capture.rs:517–527 (executable_flags) with flags & !9 != 0 rejection at capture.rs:589, capture.rs:2823, and helios/src/runtime_core/format.rs:495. Re-doing it in Python duplicates work downstream code already does — and note the Rust side prefers the supplied instantiate_flags over re-reading the executable (capture.rs:788–794), so the Python OR is the only thing that would carry the bit.

Smaller version — one line, no helper, no query:

graph._flare_instantiation_flags = CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY

Saves ~11 production lines (helper + docstring, prior_flags read, its validation, the OR); the CUDA qualification test then asserts flags_by_name == {"decode": 8, "tune": 1} (tests/preparation/test_recorded_export_graph_cuda.py:85–86), still inside the !9 masks Heliopause and Helios accept.

3. Should fix: the new capture_forwards test re-proves what three existing tests already prove (45 lines)

tests/preparation/test_capture_graph_metadata.py:258–302 — test_capture_forwards_export_sets_node_priority_instantiation_flag re-installs the same eight torch.cuda monkeypatches already installed by test_shared_capture_records_after_all_warmups_without_reinstantiation (test_capture_graph_metadata.py:179–185) and by tests/preparation/test_preparation_reclamation.py / test_capture_stream_isolation.py, then asserts _graphs(graphs) yields the combined flags for two graphs.

That mapping is already asserted twice:

The one extra fact — "capture_forwards calls record_export_graph" — is a bare pass-through at capture.py:192–193 already covered by the existing tests above. Delete the test; nothing regresses.

4. Nit: three constants for one literal, and _graphs() still hardcodes the same mask (~5 lines)

ignition/preparation/runtime_core.py:192–197 adds CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH, CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY, and PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS (6 lines for the value 9). CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH and the permitted mask are then unused once findings 1 and 2 land (their only remaining consumers are the tests' expected_combined), while _graphs() still hardcodes the mask as ~9 at line 284 — the same literal twice in one file, plus !9 three times in Rust (capture.rs:589, 2823, format.rs:495). Reviewer voipmonitor flagged the ~9 duplication too (#581 review, Nit 4). Keep one constant (..._USE_NODE_PRIORITY = 8), or, if the mask is kept, use it in _graphs() instead of ~9.

5. Nit: docstring additions restate the assignment and the PR description (~5 lines)

ignition/preparation/runtime_core.py:219–222 explain in four lines that export "combines those flags with any permitted flags already carried by the instantiated executable ... so Helios instantiates the graph with matching flags while honoring per-node stream priorities" — a prose restatement of one OR, largely copied from the PR description's "After" paragraph, and describing a bit (AUTO_FREE_ON_LAUNCH) that has no effect on the exported template. Line 201's helper docstring restates its signature. The pre-existing docstring (lines 215–218) already covers the retention invariants that matter. Deleting these loses nothing once the logic is one assignment.


Left behind / dead elsewhere

Nothing else in the repository references the names this PR adds: record_export_graph is called only at ignition/preparation/capture.py:193, _flare_instantiation_flags is read only in _graphs() (runtime_core.py:282), and instantiate_flags is already part of the wire contract (heliopause/src/export/mod.rs:114, validated at capture.rs:2823, stored by Helios at format.rs:495). No Rust, docs, or fixture changes are needed or made dead. The only cleanup the PR owes is updating the two existing expectations it touched (test_capture_graph_metadata.py:207–218, test_recorded_export_graph_cuda.py:85–86) to the flag value it finally records.

Open questions

Worked totals: diff +137/−7 across 3 files; removals identified ≈ 25 production lines and ≈ 79 test lines (~104 of the 144 added lines, ~72%), leaving a +2 line production change and two updated assertions.