Skip to content

ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs - #581

Open
FujitsuPolycom wants to merge 1 commit into
NVIDIA:mainfrom
FujitsuPolycom:perf/ignition-export-use-node-priority
Open

FujitsuPolycom wants to merge 1 commit into
NVIDIA:mainfrom
FujitsuPolycom:perf/ignition-export-use-node-priority

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

Serving forwards capture overlap branches on high-priority CUDA streams such as ScratchArena.auxiliary_stream (cuStreamCreateWithPriority at the context's greatest priority), which records CU_LAUNCH_ATTRIBUTE_PRIORITY (id = 8) on those kernel nodes. During native serving startup, Helios must pass CUDA's CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY (8) to cuGraphInstantiateWithFlags so captured per-node priorities are honored instead of inheriting the launch stream's priority, without discarding permitted flags already carried by the captured executable (CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH, 1). In addition, explicit instantiation flags require a retained CUDA graph template (keep_graph=True without post-instantiation release metadata) so invalid callers fail up front rather than serializing a zero template handle into Heliopause.

What changed

  • ignition/preparation/runtime_core.py:
    • Before: record_export_graph retained owners and instantiated the graph without setting USE_NODE_PRIORITY, so exported serving graphs recorded only executable-derived flags (1), and _Cuda() reopened the CUDA driver library on each call.
    • After: When instantiation_flags is an integer bitmask (default 8, CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY), record_export_graph validates instantiation_flags against PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS (9, bits 1 and 8 matching helios/src/runtime_core/format.rs), rejects graphs carrying _flare_graph_metadata (keep_graph=False post-instantiation recording) or a released/zero raw_cuda_graph() handle, and checks CUDA pool ownership before calling retain_object or instantiate_graph. After instantiation, it clears any prior _flare_instantiation_flags attribute, reads prior_flags via cuGraphExecGetFlags through a lazily cached _Cuda wrapper (_cuda_driver), validates prior_flags against PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS, and sets graph._flare_instantiation_flags = prior_flags | instantiation_flags (1 | 8 = 9 when bit 1 was present). Passing instantiation_flags=None clears any pre-existing _flare_instantiation_flags override on graph so _graphs falls back to executable-derived or _flare_graph_metadata flags. _graphs also reuses PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS and rejects zero raw_cuda_graph() handles when _flare_instantiation_flags is present.
  • helios/src/runtime_core/, helios/tests/node_priority_core_fixture.py, and tests/preparation/:
    • Add deterministic CPU unit tests for _flare_graph_metadata / keep_graph=False / raw_cuda_graph() == 0 rejection prior to graph mutation, clearing stale _flare_instantiation_flags on instantiation_flags=None or unsupported prior_flags, _cuda_driver caching across graphs, and Core::validate flag bounds in helios/src/runtime_core/format.rs.
    • Add an end-to-end signed-core CUDA fixture (helios/tests/node_priority_core_fixture.py) and Helios runtime test (helios/src/runtime_core/node_priority_tests.rs, driven from tests/preparation/test_recorded_export_graph_cuda.py) that captures a "decode" graph with both main-stream (priority = 0) and ScratchArena.auxiliary_stream (priority < 0) kernel nodes alongside a "tune" TuningGraph (capture_graph + instantiate_graph, flags = 1), loads the signed payload core through NativeResources::load, verifies via CUPTI (cuGraphInstantiateWithFlags exit callback) that Helios instantiates "decode" with flags = 9 and "tune" with flags = 1 (while cuGraphExecGetFlags retains AUTO_FREE_ON_LAUNCH 1), and verifies bit-exact ReplayWorker execution across poisoned-output replays.
  • Compatibility: Existing signed runtime cores retain their recorded graph flags and load without re-export or re-signing. Startup tuning graphs do not call record_export_graph; they continue to use capture_graph and instantiate_graph directly (flags = 1).

Claimed benefit and result

  • Isolated effect: Helios instantiates newly exported serving graphs with USE_NODE_PRIORITY (8) combined with permitted executable flags (1 | 8 = 9 when AUTO_FREE_ON_LAUNCH is present), honoring captured CU_LAUNCH_ATTRIBUTE_PRIORITY attributes while preserving startup tuning graph flags (1) and existing signed-core compatibility. End-to-end single-GPU signed-core load, cuGraphInstantiateWithFlags verification, and ReplayWorker execution were validated on 1x NVIDIA GeForce RTX 5090 (SM120); multi-GPU serving throughput was not measured in isolation on this PR.

Supporting evidence and limitations

Tested at candidate commit 18312bd04a34df8750637b8500b17e1eca50984a atop main (ba3afb13a7e9836080c23eadf8e1c17ee96e6e7a):

  • Layer 1 — CPU unit & contract tests:
    • python -m pytest -q -rs tests/preparation/test_core_boundary.py tests/test_design_review_hook.py tests/preparation/test_capture_graph_metadata.py tests/preparation/test_runtime_core.py tests/preparation/test_preparation_reclamation.py tests/preparation/test_capture_stream_isolation.py: 70 passed, 14 skipped, 0 failed.
    • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib runtime_core: 182 passed, 11 ignored, 0 failed (0 warnings in touched files).
  • Single-GPU SM120 export, Helios load, and replay (1x NVIDIA GeForce RTX 5090, SM120, CUDA 13):
    • FLARE_RUN_CUDA_TESTS=1 python -m pytest -q -rs tests/preparation/test_recorded_export_graph_cuda.py: 2 passed, 0 skipped, 0 failed. Verifies staged rank sources (flags_by_name == {"decode": 9, "tune": 1}), signed payload core CU_LAUNCH_ATTRIBUTE_PRIORITY (id = 8) node attributes (priority < 0 on ScratchArena.auxiliary_stream and 0 on the main stream), CUPTI-observed cuGraphInstantiateWithFlags arguments (9 on "decode" and 1 on "tune", while CUDA's cuGraphExecGetFlags retains AUTO_FREE_ON_LAUNCH 1 after consuming USE_NODE_PRIORITY 8 at instantiation), and 0-ULP bit-exact ReplayWorker outputs across poisoned-buffer replays.
  • Limitations and unqualified scope:
    • Validated on 1x NVIDIA GeForce RTX 5090 (SM120, single-rank runtime core). Multi-GPU tensor-parallel flare run serving and per-recipe ScratchArena.auxiliary_stream CTA-preemption scheduling qualification across full model checkpoints remain open hardware qualification.
Reproduction commands (plain local NVMe verified)
set -euo pipefail

# 1. Verify plain local NVMe backing for work and staging directories
mkdir -p /var/tmp/flare-work
real=$(realpath /var/tmp/flare-work)
findmnt -T "$real" -o TARGET,SOURCE,FSTYPE,OPTIONS
df -Th "$real"

# 2. Pin exact 40-char repository revision
FLARE_SHA="18312bd04a34df8750637b8500b17e1eca50984a"
git -C /var/tmp/flare-work/hyperflare-inference switch --detach "$FLARE_SHA"
cd /var/tmp/flare-work/hyperflare-inference

# 3. Run Layer 1 CPU Python & Rust runtime_core suites
CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q -rs \
  tests/preparation/test_core_boundary.py \
  tests/test_design_review_hook.py \
  tests/preparation/test_capture_graph_metadata.py \
  tests/preparation/test_runtime_core.py \
  tests/preparation/test_preparation_reclamation.py \
  tests/preparation/test_capture_stream_isolation.py
cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib runtime_core

# 4. Run SM120 CUDA export + Helios NativeResources::load & ReplayWorker suite
FLARE_RUN_CUDA_TESTS=1 .venv/bin/python -m pytest -q -rs tests/preparation/test_recorded_export_graph_cuda.py

Discord: Dooner

@voipmonitor voipmonitor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review & Live SM120 CUDA Test Report (commit 61f64f18)

Verdict: Request changes — end-to-end Heliopause/Helios wiring is already in place (flags & !9 == 0, kernel-node attribute id = 8 CU_LAUNCH_ATTRIBUTE_PRIORITY, forward- and backward-compatible with existing cores) and the live SM120 CUDA export test passes, but two items need attention before merge.

Automated & Live SM120 CUDA Test Results

  • CPU pytest -q tests/preparation/test_capture_graph_metadata.py — 12 passed, 0 failed.
  • Live SM120 CUDA FLARE_RUN_CUDA_TESTS=1 pytest -q tests/preparation/test_recorded_export_graph_cuda.py — 1 passed (3.29s), confirming real cuGraphExecGetFlags Driver API FFI and flags_by_name == {"decode": 9, "tune": 1}.

Findings

  1. [Major] Qualify live exported-core flare run behavior (docs/design-review.md Principle 12):
    Enabling CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY globally activates CTA-level preemption for every kernel captured on ScratchArena.auxiliary_stream (ignition/preparation/scratch.py:83-105) across all recipes. That is desirable for small TP collectives, but any recipe launching heavy compute on auxiliary_stream could see scheduling regressions. Please verify with an end-to-end exported TP core served via flare run (and ideally add a Helios load+replay check asserting cuGraphExecGetFlags == 9 on the Helios-instantiated executable).
  2. [Major] record_export_graph does not validate keep_graph=False / _flare_graph_metadata graphs (ignition/preparation/runtime_core.py:208-242):
    record_export_graph calls instantiate_graph(graph) (which supports _flare_graph_metadata / keep_graph=False) and then unconditionally sets graph._flare_instantiation_flags = prior_flags | instantiation_flags. If a caller passes a keep_graph=False graph, record_export_graph succeeds and fails later in _graphs() / Heliopause (graph=0). When instantiation_flags is not None, validate up front that getattr(graph, "_flare_graph_metadata", None) is None and int(graph.raw_cuda_graph()) != 0. Also consider clearing any pre-existing _flare_instantiation_flags when instantiation_flags=None.
  3. [Minor] PR description inaccuracies (Principle 16):
    • States "rejecting unsupported bits on either source before mutating graph state" — for prior_flags, graph.retain_object(...) and instantiate_graph(graph) have already run before _executable_instantiation_flags(graph) is checked.
    • States "Passing instantiation_flags=None keeps executable-derived flags for startup tuning graphs" — startup tuning graphs do not call record_export_graph at all (they call capture_graph + instantiate_graph).
  4. [Nit] Reuse PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS in _graphs() (runtime_core.py:279) instead of hardcoding flags & ~9, and lazily cache _Cuda() instead of reopening libcuda.so.1 per graph.

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 581.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

Why:
Exported serving graphs capture overlap branches on high-priority CUDA
streams such as `ScratchArena.auxiliary_stream`, which require CUDA's
`USE_NODE_PRIORITY` instantiation flag (`8`) so Helios honors captured
kernel-node priorities during `cuGraphInstantiateWithFlags` without
discarding permitted flags already present on the captured executable.
Explicit instantiation flags also require a retained CUDA graph template
(`keep_graph=True` without post-instantiation release metadata) so export
fails up front instead of producing a zero template handle in Heliopause.

What:
- `ignition/preparation/runtime_core.py`:
  - Before: `record_export_graph` retained owners and instantiated the
    graph without serializing `USE_NODE_PRIORITY`, so exported serving
    graphs kept only executable-derived flags (`1`).
  - After: When `instantiation_flags` is an integer bitmask (default `8`,
    `CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY`), `record_export_graph`
    validates `instantiation_flags` against
    `PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS` (`9`, bits `1` and `8`),
    rejects graphs carrying `_flare_graph_metadata` or a released/zero
    `raw_cuda_graph()` handle, and checks pool ownership before retaining
    owners or instantiating the graph. After instantiation, it queries
    `cuGraphExecGetFlags` via a lazily cached `_Cuda` driver wrapper,
    validates executable flags against
    `PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS`, and records
    `prior_flags | instantiation_flags`. Passing `instantiation_flags=None`
    clears any prior `_flare_instantiation_flags` attribute so callers fall
    back to executable-derived or recorded graph metadata. `_graphs` also
    reuses `PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS` and rejects zero
    template handles when `_flare_instantiation_flags` is present.
- `helios/src/runtime_core/` and `tests/preparation/`:
  - Add CPU unit coverage for template-retention guards, clearing stale
    `_flare_instantiation_flags`, `_Cuda` caching, and Helios flag bounds,
    plus an end-to-end signed-core CUDA fixture and Helios
    `NativeResources::load` + `ReplayWorker` test verifying via CUPTI that
    `cuGraphInstantiateWithFlags` receives `9` on the serving graph and `1`
    on the startup tuning graph (while `cuGraphExecGetFlags` retains
    `AUTO_FREE_ON_LAUNCH` `1`), alongside exact replay of main- and
    auxiliary-stream branches.
- Compatibility: Existing signed cores keep their recorded graph flags and
  load without re-export or re-signing. Startup tuning graphs continue to
  use `capture_graph` and `instantiate_graph` directly (`flags = 1`).

Result:
Expected benefit: Helios instantiates newly exported serving graphs with
`USE_NODE_PRIORITY` (`8`) while preserving `AUTO_FREE_ON_LAUNCH` (`1` ->
`9`) when set on the captured executable. Single-GPU signed-core load,
instantiation-flag verification, and replay were validated on SM120; live
multi-GPU serving throughput was not measured in isolation on this commit.

Evidence:
- `python -m pytest -q -rs tests/preparation/test_core_boundary.py tests/test_design_review_hook.py tests/preparation/test_capture_graph_metadata.py tests/preparation/test_runtime_core.py tests/preparation/test_preparation_reclamation.py tests/preparation/test_capture_stream_isolation.py`: 70 passed, 14 skipped, 0 failed.
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib runtime_core`: 182 passed, 11 ignored, 0 failed.
- `FLARE_RUN_CUDA_TESTS=1 python -m pytest -q -rs tests/preparation/test_recorded_export_graph_cuda.py` on `1x NVIDIA GeForce RTX 5090` (SM120): 2 passed, 0 skipped, 0 failed (verifying `flags_by_name == {"decode": 9, "tune": 1}`, negative auxiliary-stream kernel priority, CUPTI-observed `cuGraphInstantiateWithFlags` flags `9` on Helios-instantiated `"decode"` and `1` on `"tune"`, retained `cuGraphExecGetFlags == 1`, and bit-exact `ReplayWorker` outputs).
- Limitations: Multi-GPU tensor-parallel `flare run` serving and per-recipe `ScratchArena.auxiliary_stream` scheduling qualification remain open hardware qualification.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4); design-review=c3a9
Signed-off-by: FujitsuPolycom <[email protected]>
@FujitsuPolycom
FujitsuPolycom force-pushed the perf/ignition-export-use-node-priority branch from 61f64f1 to 18312bd Compare November 29, 2026 00:12
@FujitsuPolycom

Copy link
Copy Markdown
Contributor Author

@voipmonitor Addressed at 18312bd04a34df8750637b8500b17e1eca50984a (rebased onto main ba3afb13a7e9836080c23eadf8e1c17ee96e6e7a). The PR description has also been updated so the validation order, instantiation_flags=None semantics, SM120 runtime-core proof, and remaining multi-GPU qualification limits stand on their own.

  1. [Major] Qualify Helios runtime load + replay with USE_NODE_PRIORITY (helios/tests/node_priority_core_fixture.py, helios/src/runtime_core/node_priority_tests.rs, tests/preparation/test_recorded_export_graph_cuda.py):

    • Fix: Added an end-to-end signed-core fixture and Helios NativeResources::load + ReplayWorker GPU test (exported_node_priority_core_instantiates_and_replays_in_helios). The fixture captures "decode" via capture_forwards -> record_export_graph with both a main-stream branch (priority = 0) and a ScratchArena(device=0, overlap=True).auxiliary_stream branch (priority < 0) alongside a "tune" TuningGraph (capture_graph + instantiate_graph, flags = 1), and publishes a signed payload core via export_model. Note on cuGraphExecGetFlags: on the live SM120 CUDA 13 driver, cuGraphInstantiateWithFlags(exec, graph, 9) consumes CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY (8) during instantiation and cuGraphExecGetFlags(exec) returns 1 (AUTO_FREE_ON_LAUNCH only; instantiating with flags = 8 alone returns 0). Accordingly, node_priority_tests.rs subscribes CUPTI (cuGraphInstantiateWithFlags exit callback) around NativeResources::load to assert that Helios passes flags == 9 on "decode" and flags == 1 on "tune" for the exact owner.executables handles, verifies decoded CU_LAUNCH_ATTRIBUTE_PRIORITY (id = 8) kernel attributes (< 0 and 0), asserts cuGraphExecGetFlags == 1 on both live CUgraphExec handles, and verifies 0-ULP bit-exact ReplayWorker outputs across poisoned-output replays.
    • Verification (18312bd0): FLARE_RUN_CUDA_TESTS=1 python -m pytest -q -rs tests/preparation/test_recorded_export_graph_cuda.py on 1x NVIDIA GeForce RTX 5090 (SM120) -> 2 passed, 0 skipped, 0 failed; cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib runtime_core -> 182 passed, 11 ignored, 0 failed.
    • Remaining limit: Single-GPU (1x NVIDIA GeForce RTX 5090, SM120) runtime-core export, instantiation, and replay are verified on this commit; multi-GPU tensor-parallel flare run serving and per-recipe ScratchArena.auxiliary_stream CTA-preemption scheduling qualification remain open hardware qualification and are disclosed explicitly in the PR body.
  2. [Major] Validate keep_graph=False / _flare_graph_metadata / raw_cuda_graph() == 0 up front and clear stale _flare_instantiation_flags (ignition/preparation/runtime_core.py:213-266):

    • Fix: When instantiation_flags is not None, record_export_graph now validates requested instantiation_flags bits, getattr(graph, "_flare_graph_metadata", None) is None, and int(graph.raw_cuda_graph()) != 0 (catching released-template RuntimeError as ValueError) before retain_object or instantiate_graph. After instantiation, any pre-existing _flare_instantiation_flags attribute is cleared via delattr, so instantiation_flags=None (or a subsequent failed prior_flags check) never leaves stale _flare_instantiation_flags behind. _graphs() also rejects zero raw_cuda_graph() handles when _flare_instantiation_flags is set.
    • Verification (18312bd0): python -m pytest -q -rs tests/preparation/test_capture_graph_metadata.py tests/preparation/test_runtime_core.py -> 34 passed, 14 skipped, 0 failed, covering _flare_graph_metadata rejection, keep_graph=False released-template rejection, raw_cuda_graph() == 0 rejection without mutating _retained.objects or instantiations, and clearing stale _flare_instantiation_flags when instantiation_flags=None.
    • Remaining limit: None within the declared contract.
  3. [Minor] PR description inaccuracies (Principle 16):

    • Fix: Rewrote both passages in the commit message and PR body to state the exact validation sequence (requested instantiation_flags, template retention, and pool ownership checked before retain_object/instantiate_graph; prior_flags inspected via cuGraphExecGetFlags after instantiation before setting _flare_instantiation_flags) and to explain accurately that instantiation_flags=None clears prior _flare_instantiation_flags overrides on record_export_graph callers, whereas startup tuning graphs call capture_graph + instantiate_graph directly without calling record_export_graph.
    • Remaining limit: None.
  4. [Nit] Reuse PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS in _graphs() and lazily cache _Cuda() (ignition/preparation/runtime_core.py:93-95, 199-210, 305-313):

    • Fix: Replaced flags & ~9 in _graphs() with flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS and added @lru_cache(maxsize=1) _cuda_driver() for _executable_instantiation_flags.
    • Verification (18312bd0): Covered by test_capture_graph_metadata.py::test_executable_instantiation_flags_reuses_cached_cuda_driver and test_runtime_core.py::test_template_export_rejects_unsupported_flags (70 passed, 14 skipped, 0 failed across the preparation/hook CPU suite).
    • Remaining limit: None.

Could you take another look at 18312bd0?

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The downstream Heliopause/Helios pipeline already accepts USE_NODE_PRIORITY (8) and live SM120 export passes, but the PR globally enables CTA-priority scheduling on every exported serving graph with no flare run serving measurement, breaks keep_graph=False graphs, and leaks stale instantiation flags.

  • Blockers: 1
  • Should fix: 3
  • Subtractive suggestions: 2
  • Nits: 1

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@flare-autobot flare-autobot added area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:validation Proposed implementation needs acceptance evidence; no claim that a reported defect is fixed. labels Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:validation Proposed implementation needs acceptance evidence; no claim that a reported defect is fixed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants