Conventions report · NVIDIA/hyperflare-inference #581

Raw Markdown for agents: https://autobot.eidonix.com/p/2b767a0d-c8df-404e-9eb5-21591dd5ec89.md

Report — PR #581 "ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs" (lens: conventions and duplication)

Key findings

Every changed file was read in context (ignition/preparation/runtime_core.py, tests/preparation/test_capture_graph_metadata.py, tests/preparation/test_recorded_export_graph_cuda.py), with its only production caller (ignition/preparation/capture.py:190-197), its closest in-repo precedents (ignition/preparation/scratch.py, heliopause/src/export/capture.rs) and the governing docs (AGENTS.md:180-199, docs/design-review.md:180-194, charter). Two should-fix findings, four nits, nothing blocking. The change is architecturally aligned: the 9-bit mask it introduces is the same mask the Rust consumers already enforce.


Should fix

1. The new PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS constant is bypassed by the one other validator in the same module — the mask and its message now exist three times

ignition/preparation/runtime_core.py:192-197 introduces CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH = 1, CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY = 8, PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS = 9, and record_export_graph correctly uses the constant twice (:227 instantiation_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS; :240 the executable-derived check).

The pre-existing validator in _graphs is left on the bare literal and repeats the identical message verbatim (runtime_core.py:284-285):

if type(flags) is not int or flags < 0 or flags & ~9:
    raise ValueError("graph instantiation flags may only select automatic free and node priority")

which duplicates record_export_graph:224-229 character for character. After this PR the permitted mask and its error text each exist in three places in one module (:192-197, :224-229, :284-285), and the new named constant is not used by the one function that re-validates the value record_export_graph produces (serialized as instantiate_flags at :286).

Why it matters: both validators enforce the same exported contract, so they can drift as soon as a bit is added or removed — the very class of duplicate the PR is fixing elsewhere. The precedent is set inside the changed function: all mask validation there goes through PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS.

Fix: use ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS in _graphs:284, and hoist the type/range/mask check and message into one private validator (or one module-level message constant) called by both record_export_graph and _graphs.

2. Executable-derived flag rejection runs after the graph is already mutated, contradicting the PR's own stated contract

record_export_graph (ignition/preparation/runtime_core.py:208-243) order of operations:

The PR description claims the tests cover "rejecting unsupported bits on either source before mutating graph state". That holds for the requested-flags source and fails for the executable-derived source: a graph whose executable carries an unsupported bit is left instantiated with owners retained and no _flare_instantiation_flags.

The tests hide the gap. The new case at tests/preparation/test_capture_graph_metadata.py:244-248 asserts only pytest.raises(ValueError, match="unsupported CUDA instantiation flags"), while the adjacent rejection case at :250-255 asserts no partial mutation (assert bad.instantiations == 0 and not bad._retained.objects); tests/preparation/test_capture_graph_metadata.py:305+ (test_export_graph_retains_external_owners_until_release) documents that retained owners survive until reset/collection. docs/design-review.md:187-189 requires tests that "validate rejection without partial mutation"; AGENTS.md:194-196 requires tests to exercise the affected contract.

Fix, one of:


Nits

3. The new CUDA entrypoint bypasses the repository's pinned cuda.bindings driver API and re-hardcodes the flag values it names

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

def _executable_instantiation_flags(graph) -> int:
    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)

Two departures from established pattern:

The Rust side already reads these flags through a single typed helper — heliopause/src/export/capture.rs:517-527 fn executable_flags(...) wrapping cuGraphExecGetFlags — the same shape a bindings call would give here.

Fix: from cuda.bindings import driver as cuda; status, flags = cuda.cuGraphExecGetFlags(executable); check cuda.CUresult.CUDA_SUCCESS; return int(flags); take the bit values from cuda.CUgraphInstantiate_flags where available, otherwise keep the named constants.

4. Nothing exercises the real cuGraphExecGetFlags call except the opt-in GPU test, which the PR reports as skipped

The fixture at tests/preparation/test_capture_graph_metadata.py:113 does monkeypatch.setattr(runtime_core, "_executable_instantiation_flags", lambda graph: graph.exec_flags), replacing the helper wholesale. The one line that actually calls cuGraphExecGetFlags (runtime_core.py:204) and the _Cuda path are executed by no test at all, except tests/preparation/test_recorded_export_graph_cuda.py (gated on FLARE_RUN_CUDA_TESTS), reported among the 15 skipped and listed as open GPU qualification. AGENTS.md:194-196 ("source-text checks and mocks that bypass the behavior cannot establish runtime correctness") and docs/design-review.md:187-189 apply.

Related: the fixture's default Graph.exec_flags bakes in the real-world PyTorch value, so the mocked tests prove the prior | requested arithmetic but not that a Torch-instantiated graph reports 1 — exactly what the GPU assertion flags_by_name == {"decode": 9, "tune": 1} at test_recorded_export_graph_cuda.py:86 depends on. Disclosed as open qualification, hence a nit; only the GPU run settles it.

5. The instantiation_flags keyword has no production caller, and the PR describes a path it does not serve

record_export_graph(..., instantiation_flags=...) (runtime_core.py:213, branch :238-242) adds a switch; the only production caller is ignition/preparation/capture.py:193, record_export_graph(graph, warmup_storage, owners=(function,)), which always takes the default. The None path appears only at tests/preparation/test_capture_graph_metadata.py:240 and the 0 path only at :234. The PR sentence "Passing instantiation_flags=None keeps executable-derived flags for startup tuning graphs" describes nothing in this repository: tuning graphs are built through capture_graph + instantiate_graph (runtime_core.py:246-269; test_recorded_export_graph_cuda.py:62-65,70), which never reach record_export_graph.

AGENTS.md:188-193 rejects "configuration switches without a concrete requirement" and "speculative compatibility"; AGENTS.md:198-199 asks each PR to describe its behaviour accurately. Optional keywords are this module's own style (capture_graph(*, retain_graphs=False)), so this is a scope nit rather than a pattern departure. Fix: drop the parameter (always combine the priority bit with the executable-derived permitted bits) or name the caller that needs None and correct the tuning-graph sentence and the docstring at :219-222.

6. The new capture_forwards test clones the existing mocked capture harness, while the same fact is already asserted end to end

tests/preparation/test_capture_graph_metadata.py:258-302 (test_capture_forwards_export_sets_node_priority_instantiation_flag) repeats almost line for line the harness of the neighbouring test_shared_capture_records_after_all_warmups_without_reinstantiation (:165-194): same stream = SimpleNamespace(wait_stream=..., synchronize=...), same torch.cuda.{current_stream,stream,synchronize,graph,mem_get_info,memory_allocated,memory_reserved} monkeypatch loop, same capture._warmup_stream / capture._seed_warmup_workspaces stubs, same capture.capture_forwards(..., compile_decoder=False, retain_graphs=True) call. It differs only by adding pool=/warmup_storage= and by asserting on _graphs(graphs). The end-to-end claim (a serving graph exports with 9) is already asserted against a real CUDA graph at tests/preparation/test_recorded_export_graph_cuda.py:85-87.

The precedent cuts both ways — inline setup is this file's norm (tests/preparation/test_preparation_reclamation.py (not opened)), while tests/preparation/test_capture_stream_isolation.py:22-51 shows a shared-fixture alternative. Nit: a small _capture_forwards-style helper would carry the new case without the clone; nothing here is incorrect, only duplicated.


Checked and clean

Open questions / not verifiable from the code