Simplicity report · NVIDIA/hyperflare-inference #581

Raw Markdown for agents: https://autobot.eidonix.com/p/bf7f438a-e1a0-4a0a-9741-0fe4509b91d7.md

Simplicity review (lens D) — PR #581, ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs

Head 61f64f18e06cdcb9de76c33765584a97752f3953, base main (167f22c). 3 files, +137/−7. Lens D only: what can be deleted.

The functional core of this patch is right and small: query cuGraphExecGetFlags, OR in 8, and let the existing _graphs path emit instantiate_flags instead of executable. Everything downstream already accepts it — Heliopause validates flags & !9 == 0 (heliopause/src/export/capture.rs:2813-2830) and Helios re-instantiates with the recorded word (helios/src/runtime_core/mod.rs:1217-1218 (not opened), validator helios/src/runtime_core/format.rs:491-495, contract docs/runtime-core-design.md:616-623). The findings below are about the extra surface shipped around that core, not about whether node priority reaches the core.

Key findings

Governing rules

The author (FujitsuPolycom) is a CONTRIBUTOR, not one of the three priority reviewers, so these are framed as concrete smaller versions rather than as grounds for rejection.


F1 — should fix: instantiation_flags kwarg is a configuration switch with one caller

File: ignition/preparation/runtime_core.py:208-243 (signature at :213, validation at :224-229, wrapper at :238)

def record_export_graph(
    graph,
    storage,
    *,
    owners=(),
    instantiation_flags=CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY,
):
    ...
    if instantiation_flags is not None and (
        type(instantiation_flags) is not int
        or instantiation_flags < 0
        or instantiation_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS
    ):
        raise ValueError("graph instantiation flags may only select automatic free and node priority")
    ...
    if instantiation_flags is not None:
        prior_flags = _executable_instantiation_flags(graph)
        ...
        graph._flare_instantiation_flags = prior_flags | instantiation_flags

What is wrong. The parameter has three modes: default 8 (combine), None (skip recording), 0 (record executable bits only). Exactly one production caller exists in the repository — ignition/preparation/capture.py:193, record_export_graph(graph, warmup_storage, owners=(function,)) — and it takes the default. search_code at the PR head for record_export_graph|instantiation_flags returns only that call site, the definition, and tests (tests/preparation/test_capture_graph_metadata.py:206-254, :317, :358, :372); tests/preparation/test_capture_rank_readiness.py:61 replaces the function outright. The None and 0 branches, and the whole validation block, therefore exist only to be tested.

The PR description justifies None with "keeps executable-derived flags for startup tuning graphs", but startup tuning graphs never call record_export_graph: they go through capture_graph() / instantiate_graph() (runtime_core.py:246-269, capture.py:194-197). voipmonitor's review item 3 says the same — the sentence describes a caller that does not exist.

Why it matters. This is the exact shape AGENTS.md:188-193 calls out — an optional path with no concrete requirement — and it forces the validation, the is not None wrapper, and the docstring paragraph (F4) into existence to explain and guard the unused modes. Every mode is an untested-in-production combination that future readers must reason about.

Fix — delete the parameter and the three branches. Verified equivalent for the only caller: _graphs (runtime_core.py:282-292) is the sole consumer of _flare_instantiation_flags, and the unconditional prior | 8 writes the same value the default writes today.

def record_export_graph(graph, storage, *, owners=()):
    """Retain a captured template, its executable and external export resources.

    Owners must not reference the graph: Torch's destruction finalizer retains
    them independently. Native replay callers must drain before resetting graphs.
    Exported flags keep the executable's permitted bits and add node priority.
    """
    pools = (storage.pool, storage.graph_pool)
    owned = {pool.id for pool in pools}
    if not set(graph.pools()) <= owned:
        raise ValueError("export graph uses a CUDA pool without an external owner")
    # Device pointers in captured nodes do not retain their Python resource owners.
    # Release these references only when the graph is reset or collected.
    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

That deletes lines 213, 224-229 and the 238 wrapper (≈12 lines plus 4 docstring lines). The prior_flags guard at 240-241 goes with it (F2).

What would settle it: a caller outside this repository (hyperflare-recipes) passing a non-default instantiation_flags. The PR names none and the description's claimed second caller does not exist.

F2 — should fix: flag validation duplicated, and the new constant is never adopted

File: ignition/preparation/runtime_core.py:192-197 (constants), :224-229 and :240-241 (new guards), :284 (pre-existing guard)

Two guards now reject the same input with the same message:

What is wrong. Two things, in one place:

  1. The record-side guards cannot catch anything _graphs misses. record_export_graph stores prior_flags | instantiation_flags, so any unsupported bit on either source is still set when _graphs re-checks the recorded word; _graphs runs on every export of that graph (RuntimeCore.write, runtime_core.py:122; export_model, :397). The record-side check only changes the message and the moment of failure (capture vs export), at the cost of one more error path.
  2. The PR introduces PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS (:194-197) but _graphs still hardcodes ~9 and repeats the message string verbatim — so the module now has the mask in two forms and one message in two copies. main already had the ~9; this PR added the constant without adopting it. The record-side type and negative checks at :225-226 are likewise literal duplicates of :284.

Why it matters. Two sources of truth for a CUDA ABI constant (helios/src/runtime_core/format.rs:495, heliopause/src/export/capture.rs:2823) inside one module: a change to the permitted set must be made twice or the two paths disagree. AGENTS.md:188-193 (no fallback layers / speculative compatibility) and design-review 15 apply; a second rejection path for the same violation is redundant surface.

Fix — keep one check, adopt the constant. Either delete :240-241 (recommended, since :284 already runs on every export) or keep the early check and delete the duplicate string in _graphs. In both cases _graphs:284 becomes:

if type(flags) is not int or flags < 0 or flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS:

If F1 is applied, CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH and the composite constant lose their only production reader apart from this line — collapsing them to one documented constant with the two bit meanings in a comment removes a second indirection. voipmonitor's review nit 4 raises the ~9 half of this.

Cross-language copies (heliopause/src/export/capture.rs:2823, helios/src/runtime_core/format.rs:495) are pre-existing and out of scope here.

F3 — nit: _Cuda() reopened for every exported graph

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

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

_Cuda.__init__ does C.CDLL("libcuda.so.1") / WinDLL("nvcuda.dll") (runtime_core.py:77-78), so this adds a fresh driver handle per exported graph. Both storage classes already own one handle for their lifetime (core_storage.py:76, virtual_storage.py:27 (not opened)), and record_export_graph receives the storage object.

Fix: take the handle from the caller instead of constructing one — _executable_instantiation_flags(graph, storage.cuda) — or at minimum hoist a module-level lazily created instance. Note the test doubles (tests/preparation/test_capture_graph_metadata.py:196-260 use a SimpleNamespace storage) would need a cuda attribute; _executable_instantiation_flags is already monkeypatched at :113, so this is one line of fixture change, not new surface. Same point as voipmonitor's nit 4.

F4 — nit: added docstring paragraph restates the assignment and documents an unused mode

File: ignition/preparation/runtime_core.py:219-222

When ``instantiation_flags`` is set, export combines those flags with any
permitted flags already carried by the instantiated executable (such as
``CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH``) so Helios instantiates
the graph with matching flags while honoring per-node stream priorities.

prior_flags | instantiation_flags already says "previous combined with requested". Per .agents/skills/repo-prose/SKILL.md (not opened) ("Comments explain invariants, intent, and non-obvious constraints"; "State the substantive fact … directly") the durable fact worth one sentence is the constraint: Helios accepts only bits 1 and 8 (helios/src/runtime_core/format.rs:491-495) and node priority is what makes captured stream priorities take effect at instantiation. That sentence is in the F1 replacement and is shorter than the paragraph it replaces. The paragraph also documents the None mode, which F1 removes, and its "honoring per-node stream priorities" claim is the part voipmonitor asks to see qualified on live hardware — prose should not assert it ahead of that evidence.

F5 — nit: new tests pin unused kwarg modes and re-implement an existing mock surface

Files: tests/preparation/test_capture_graph_metadata.py:222-255 and :258-302

  1. :258-302 test_capture_forwards_export_sets_node_priority_instantiation_flag rebuilds the entire capture_forwards mock surface (torch.cuda stream/graph/memory patches, capture._warmup_stream, capture._seed_warmup_workspaces, a local ExportGraph subclass overriding pools()) — nearly identical to the existing test_shared_capture_records_after_all_warmups_without_reinstantiation at :165-194 — in order to assert {prefill: 9, decode: 9}, the same value already asserted directly at :215-218. Its only distinct content is that capture.py:193 omits instantiation_flags, i.e. it pins the default of the kwarg. That is a real property today, but it disappears with F1, and this test should go with it.
  2. :222-242 (no_autofree, preserved_only, plain) cover the None and 0 modes, which have no caller (F1). Of the three, only no_autofree (exec flag 0 → recorded 8) adds a distinct checked combination; it can be folded into the first graph by parametrizing exec_flags.
  3. :244-255 (unsupported_exec, bad) assert the record-side rejection that F2 removes; tests/preparation/test_runtime_core.py:31-37 already covers rejection of unsupported flags on the _graphs side, which is the check that survives.

tests/preparation/test_recorded_export_graph_cuda.py:85-87 is fine and not a finding: flags_by_name == {"decode": 9, "tune": 1} is the intended new property (tune stays at the executable's own 1, decode gets 9), and it is the check voipmonitor ran live on SM120 (1 passed, 3.29 s). The all(... node_count > 0 ...) widens node-count checking from graph 0 to both graphs — harmless.

Fix: apply F1/F2 first, then delete the tests that only existed for the deleted modes.


What was checked and is not a finding

Open questions / not verifiable from the code