Skip to content

Preserve inherited CUDA_HOME in ignition.cli.environment - #690

Merged
lukealonso merged 1 commit into
NVIDIA:mainfrom
jcartu:fix/ignition-preserve-cuda-home
Dec 3, 2026
Merged

lukealonso merged 1 commit into
NVIDIA:mainfrom
jcartu:fix/ignition-preserve-cuda-home

Conversation

@jcartu

@jcartu jcartu commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #636

Why

Issue #636 reports that ignition no longer respects an inherited CUDA_HOME environment variable. On non-Windows hosts where /usr/local/cuda exists, ignition.cli.environment.apply fell back to /usr/local/cuda whenever [paths] cuda was unset in config.toml, unconditionally overwriting CUDA_HOME and pointing unset TRITON_PTXAS_PATH and CPATH entries at /usr/local/cuda. On systems with multiple CUDA toolkits installed, preparation runs that select a non-default toolkit through CUDA_HOME were silently redirected to /usr/local/cuda.

Preserving a non-empty inherited CUDA_HOME before the /usr/local/cuda fallback falls within Principle 10's documented CUDA device selection and dependency setup policy exception (docs/design-review.md): CUDA_HOME selects the native CUDA toolkit dependency rather than toggling Flare behavior, while explicit [paths] cuda configuration retains top precedence and existing TRITON_PTXAS_PATH and CPATH handling remain unchanged.

What changed

  • ignition/cli/environment.py: Defined _DEFAULT_LINUX_CUDA = Path("/usr/local/cuda") and updated apply on non-Windows hosts to resolve the CUDA toolkit in order:
    1. Explicit [paths] cuda from Flare configuration (configuration.directory("cuda")), overriding inherited CUDA_HOME.
    2. Non-empty inherited CUDA_HOME from os.environ (whitespace stripped), preserved without falling back to /usr/local/cuda.
    3. /usr/local/cuda (_DEFAULT_LINUX_CUDA) when that directory exists.
    4. Unset otherwise, removing any blank/whitespace CUDA_HOME from os.environ so native build libraries perform their own toolkit discovery cleanly.
      Previously, the non-Windows branch checked only whether [paths] cuda was absent and /usr/local/cuda existed, overwriting any inherited CUDA_HOME and leaving whitespace-only CUDA_HOME values in os.environ when /usr/local/cuda was absent. TRITON_PTXAS_PATH (if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ), CPATH prepending, and Windows (os.name == "nt") behavior are unchanged.
  • docs/cli-design.md, AGENTS.md, and docs/model-preparation.md: Reconciled the normative environment-variable and precedence statements in docs/cli-design.md and AGENTS.md with Principle 10 and the CUDA toolkit configuration table in docs/cli-design.md, and kept docs/model-preparation.md as a brief summary pointing to docs/cli-design.md as the canonical specification.
  • tests/cli/test_environment.py: Added unit tests with a module-level POSIX pytestmark and a leak-free clean_environment fixture (restoring both originally present and originally absent environment variables after every test) covering explicit [paths] cuda overrides (with both unset and pre-set TRITON_PTXAS_PATH), inherited CUDA_HOME preservation (including whitespace-padded paths, pre-set TRITON_PTXAS_PATH and existing CPATH entries, and paths without local toolkit files), empty/whitespace CUDA_HOME fallback to _DEFAULT_LINUX_CUDA, and removing empty/whitespace CUDA_HOME when no toolkit source exists.

Claimed result

On non-Windows hosts with /usr/local/cuda present, ignition preserves a caller-supplied CUDA_HOME (normalizing surrounding whitespace) and derives unset TRITON_PTXAS_PATH and CPATH entries from that toolkit when [paths] cuda is unset, without altering TRITON_PTXAS_PATH or CPATH precedence. Explicit [paths] cuda overrides inherited CUDA_HOME, hosts without [paths] cuda or a non-empty CUDA_HOME retain the /usr/local/cuda fallback, and blank CUDA_HOME values are cleared when no toolkit source exists.

Supporting evidence and limitations

  • Executed on Linux x86_64 with CUDA_VISIBLE_DEVICES="":
    • pytest tests/cli -v: 148 passed, including all 12 cases in tests/cli/test_environment.py.
    • Verified post-session os.environ snapshot restoration across tests/cli/test_environment.py: every managed variable in _ENV_KEYS matched its pre-session value (or absence) after pytest completed.
  • Unit tests in tests/cli/test_environment.py redirect ignition.cli.environment._DEFAULT_LINUX_CUDA to temporary directories and stub ignition.cli.environment.runtime_patches.apply so environment selection is tested without requiring /usr/local/cuda or pinned PyTorch/Triton patch versions.
  • Windows (os.name == "nt") execution and end-to-end GPU model preparation were not run.

Discord: jcartu

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 690.
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.

@flare-autobot flare-autobot added bug Something isn't working priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 2, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The ignition/cli/environment.py fix is small, well-placed, and directly addresses the #636 regression without re-introducing #71's pip-bundle bug. Two items need resolving first: normative policy statements in AGENTS.md:461 and docs/cli-design.md:46-53 still contradict the text this PR adds, and an unrequested TRITON_PTXAS_PATH behavior change ships with an untested blank-value branch and understated docs.

  • Blockers: 0 · Should fix: 2 · Subtract/Simplify: 2 · Nits: 3
Walkthrough
  • ignition/cli/environment.py: Adds _DEFAULT_LINUX_CUDA = Path("/usr/local/cuda") (:22) and updates non-Windows toolkit resolution (:58-69) to [paths] cuda → non-empty stripped inherited CUDA_HOME → _DEFAULT_LINUX_CUDA when that directory exists → os.environ.pop("CUDA_HOME", None). Also updates POSIX TRITON_PTXAS_PATH assignment (:78-81) to set <cuda>/bin/ptxas whenever configured_cuda is not None or ambient TRITON_PTXAS_PATH is unset/whitespace.
  • tests/cli/test_environment.py: Adds the first direct unit suite for environment.apply() (6 POSIX test functions / 10 parametrized cases) with a leak-free clean_environment fixture (:45-58) covering configured override, inherited preservation, preset TRITON_PTXAS_PATH/existing CPATH, missing local toolkit files, fallback to _DEFAULT_LINUX_CUDA, and clearing blank CUDA_HOME.
  • docs/cli-design.md, docs/model-preparation.md, AGENTS.md: Updates the CUDA toolkit row (docs/cli-design.md:1480), preparation setup paragraph (docs/model-preparation.md:123-132), and configuration bullet (AGENTS.md:466-473) to document the new non-Windows precedence.
Merge Risk: Low · up to 682152b
  • Bounded startup blast radius: ignition.cli.environment.apply runs synchronously once per process before PyTorch/Triton/b12x imports across five CLI entry points (ignition/cli/serve.py:210, 291, 436, 545 and ignition/cli/bench.py:205). It introduces no concurrency, runtime hot-path, schema, core-format, or Helios changes, and leaves Windows (os.name == "nt", ignition/cli/environment.py:70-75) untouched.
  • User-visible default-path behavior change: Because paths.cuda defaults to "" (ignition/cli/config.py:51, 172-175), every non-Windows user without an explicit [paths] cuda now inherits a non-empty CUDA_HOME instead of falling back to /usr/local/cuda, and users with [paths] cuda configured now have ambient TRITON_PTXAS_PATH overridden when <cuda>/bin/ptxas exists.
  • Process/policy sensitivity: This four-line policy has now changed three times in six weeks (#71 → c9935887 → #690), issue ignition no longer respects the CUDA_HOME environment variable #636 carries triage:design-review with no maintainer decision recorded yet, and head 682152b has no CI check results.
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings
  • ✅ Security / malicious screen: No suspicious code, credential access, command execution, or prompt-injection content found in the diff or PR description.
  • ⚠️ Charter & value fit: Fixes a real reproducible regression (ignition no longer respects the CUDA_HOME environment variable #636) in preparation tooling with minimal footprint, and Principle 10 (docs/design-review.md:89-92) exempts documented CUDA dependency setup policies, but AGENTS.md:461 and docs/cli-design.md:46-53 still contradict the new policy and ignition no longer respects the CUDA_HOME environment variable #636 (triage:design-review) lacks maintainer sign-off.
  • ✅ Related / duplicate / conflict check: No duplicate, superseding, or conflicting PRs; does not re-introduce Preserve native CUDA toolkit selection with cuTile dependencies #71's automatic pip-bundle selection.
  • ⚠️ Tests & verification evidence: All 10 unit cases in tests/cli/test_environment.py are well-isolated and exercise the real environment.apply() and Configuration.load(), but results are author-reported with no CI run on 682152b, Windows is skipped across all tests, and the new blank/whitespace TRITON_PTXAS_PATH and padded-non-empty CUDA_HOME branches are untested.

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.

Fixes issue NVIDIA#636. On non-Windows hosts where `/usr/local/cuda` exists,
`ignition.cli.environment.apply` fell back to `/usr/local/cuda` whenever
`[paths] cuda` was unset in `config.toml`, unconditionally overwriting an
inherited `CUDA_HOME` environment variable and pointing unset
`TRITON_PTXAS_PATH` and `CPATH` entries at `/usr/local/cuda` instead of the
caller's selected toolkit. On systems with multiple CUDA toolkits installed,
preparation runs that select a non-default toolkit through `CUDA_HOME` were
silently redirected to `/usr/local/cuda`. Preserving a non-empty inherited
`CUDA_HOME` before the `/usr/local/cuda` fallback falls within Principle 10's
documented CUDA device selection and dependency setup policy exception while
keeping `[paths] cuda` as the highest-precedence explicit configuration and
leaving `TRITON_PTXAS_PATH` and `CPATH` handling unchanged.

Changed `ignition/cli/environment.py` to define `_DEFAULT_LINUX_CUDA = Path("/usr/local/cuda")`
and resolve the non-Windows CUDA toolkit in precedence order: explicit
`[paths] cuda` from Flare configuration, then a non-empty stripped inherited
`CUDA_HOME`, then `_DEFAULT_LINUX_CUDA` when that directory exists; when none
of these applies, any blank `CUDA_HOME` entry is removed so native build
libraries perform their own toolkit discovery cleanly. Previously, the
non-Windows branch checked only whether `[paths] cuda` was unset and
`/usr/local/cuda` existed, ignoring any inherited `CUDA_HOME` and leaving
blank `CUDA_HOME` values in `os.environ` when `/usr/local/cuda` was absent.
`TRITON_PTXAS_PATH` (`if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ`),
`CPATH` prepending, and Windows (`os.name == "nt"`) behavior remain unchanged.
Updated `docs/cli-design.md` (normative environment-variable/precedence
principles and configuration table), `AGENTS.md` (configuration policy), and
`docs/model-preparation.md` (summary pointing to `docs/cli-design.md`) so all
three documents consistently reflect this non-Windows toolkit dependency setup
policy. Added `tests/cli/test_environment.py` with a module-level POSIX
`pytestmark` and a leak-free `clean_environment` fixture covering explicit
`[paths] cuda` overrides (with unset and pre-set `TRITON_PTXAS_PATH`),
inherited `CUDA_HOME` preservation (including whitespace-padded values,
pre-set `TRITON_PTXAS_PATH`/`CPATH`, and paths without local toolkit files),
blank/unset fallback to `_DEFAULT_LINUX_CUDA`, and clearing blank `CUDA_HOME`
when no toolkit source exists.

Result: on non-Windows hosts with `/usr/local/cuda` present, `ignition`
preserves a caller-supplied `CUDA_HOME` (normalizing surrounding whitespace)
and derives unset `TRITON_PTXAS_PATH` and `CPATH` entries from it when
`[paths] cuda` is unset, while preserving existing `TRITON_PTXAS_PATH`
precedence. Explicit `[paths] cuda` overrides inherited `CUDA_HOME`, and hosts
without `[paths] cuda` or a non-empty `CUDA_HOME` retain the `/usr/local/cuda`
fallback (or leave `CUDA_HOME` unset when `/usr/local/cuda` is absent).

Validation: on Linux x86_64 with `CUDA_VISIBLE_DEVICES=""`, `pytest tests/cli -v`
passed 148/148 tests, including all 12 cases in `tests/cli/test_environment.py`,
and a post-session `os.environ` snapshot check across all 12 managed variables
in `_ENV_KEYS` confirmed exact restoration after `tests/cli/test_environment.py`
completed. Unit tests redirect `environment._DEFAULT_LINUX_CUDA` to temporary
directories and stub `environment.runtime_patches.apply`. Windows
(`os.name == "nt"`) execution and end-to-end GPU model preparation were not run.

Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com>
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
@jcartu
jcartu force-pushed the fix/ignition-preserve-cuda-home branch from 682152b to 39796ea Compare December 2, 2026 21:45
@jcartu

jcartu commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@flare-autobot Addressed all review items in 39796ea4:

  • Env-var policy consistency: Updated the normative environment-variable and precedence statements in AGENTS.md and docs/cli-design.md so they align with Principle 10 (docs/design-review.md) and the CUDA toolkit configuration row in docs/cli-design.md (covering CUDA_VISIBLE_DEVICES plus non-Windows CUDA_HOME fallback, pre-set TRITON_PTXAS_PATH, and CPATH preservation).
  • Strict ignition no longer respects the CUDA_HOME environment variable #636 scope: Removed configured_cuda from ignition/cli/environment.py and kept main's "TRITON_PTXAS_PATH" not in os.environ check unchanged so this PR modifies only non-Windows CUDA_HOME fallback precedence. Updated tests/cli/test_environment.py to cover both unset and pre-set TRITON_PTXAS_PATH with [paths] cuda.
  • Simplifications and nits:
    • Replaced the duplicated toolkit rules in docs/model-preparation.md with a brief summary pointing to docs/cli-design.md.
    • Tightened the ignition/cli/environment.py comment to keep the cuTile note and point to docs/cli-design.md.
    • Replaced the per-test POSIX skipif decorators in tests/cli/test_environment.py with a single module-level pytestmark.
    • Added test_whitespace_padded_inherited_cuda_home_is_normalized covering whitespace-padded non-empty CUDA_HOME.

Validation on Linux x86_64 with CUDA_VISIBLE_DEVICES="": pytest tests/cli -v passed 148/148 tests (including 12/12 in tests/cli/test_environment.py), and a post-session os.environ snapshot check confirmed exact restoration across all 12 keys in _ENV_KEYS. Windows (os.name == "nt") execution and GPU model preparation were not run.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Head 39796ea cleanly resolves both prior Round 1 review items and keeps the change to 10 added lines in one startup function with well-isolated unit coverage. Maintainers should only confirm they endorse issue #636's policy premise and that PR CI passes on 39796ea.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 1 · Nits: 1
Walkthrough
  • ignition/cli/environment.py: Adds _DEFAULT_LINUX_CUDA = Path("/usr/local/cuda") (:22) and updates non-Windows toolkit resolution (:54-64) to [paths] cuda → non-empty whitespace-stripped inherited CUDA_HOME → _DEFAULT_LINUX_CUDA when that directory exists → os.environ.pop("CUDA_HOME", None). Leaves Windows (:67-72), POSIX TRITON_PTXAS_PATH (:74-76, identical to main:66-68), and CPATH prepending (:77-81, identical to main:69-73) unchanged.
  • tests/cli/test_environment.py: Adds 8 POSIX test functions (12 parametrized cases, module-level pytestmark at :15-18) with a leak-free clean_environment fixture (:50-63, covering all 12 variables in _ENV_KEYS) exercising [paths] cuda override with unset and pre-set TRITON_PTXAS_PATH, inherited CUDA_HOME preservation (including whitespace normalization, pre-set TRITON_PTXAS_PATH/existing CPATH, and paths without local toolkit files), fallback to _DEFAULT_LINUX_CUDA on unset/blank CUDA_HOME, and clearing blank CUDA_HOME when no toolkit source exists.
  • docs/cli-design.md, AGENTS.md, docs/model-preparation.md: Aligns the normative environment-variable policy (docs/cli-design.md:46-62, AGENTS.md:461-474) and configuration ownership table (docs/cli-design.md:1489) with Principle 10 (docs/design-review.md:89-92) and replaces duplicated prose in docs/model-preparation.md:123-126 with a brief pointer to docs/cli-design.md.
Merge Risk: Low · up to 39796ea
  • Bounded startup blast radius: ignition.cli.environment.apply executes synchronously once per process before flare_heliopause/torch imports across five CLI entry points (ignition/cli/serve.py:210, 291, 436, 545 and ignition/cli/bench.py:205). No Helios runtime, concurrency, hot-path, schema, core-format, or Windows (ignition/cli/environment.py:67-72) paths are affected.
  • Default-path behavior shift for inherited CUDA_HOME: Because paths.cuda defaults to "" (ignition/cli/config.py:51, 172-175), non-Windows runs without [paths] cuda now preserve any non-empty inherited CUDA_HOME verbatim rather than overwriting it with /usr/local/cuda. That fixes multi-toolkit selection (ignition no longer respects the CUDA_HOME environment variable #636), with the expected trade-off that a host carrying a stale/nonexistent CUDA_HOME in its shell profile will keep that value instead of silently falling back to /usr/local/cuda (leaving TRITON_PTXAS_PATH and CPATH unset, matching [paths] cuda behavior).
  • Governance / verification context: Issue ignition no longer respects the CUDA_HOME environment variable #636 still carries triage:design-review with zero maintainer comments, and while the new unit suite runs in .github/workflows/python-cpu.yml:30-33, CI check results for 39796ea and GPU/Windows runs were not observable here.
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings
  • ✅ Security / malicious screen: No suspicious code, credential access, command execution, or prompt-injection content in the diff or PR conversation.
  • ⚠️ Charter & value fit: Minimal, well-placed fix for a reproducible regression (ignition no longer respects the CUDA_HOME environment variable #636) within Principle 10's documented CUDA dependency setup exception (docs/design-review.md:89-92), but ignition no longer respects the CUDA_HOME environment variable #636 (triage:design-review) still lacks a recorded maintainer sign-off.
  • ✅ Related / duplicate / conflict check: No duplicate, superseding, or conflicting open PRs touch ignition/cli/environment.py or tests/cli/test_environment.py, and Preserve native CUDA toolkit selection with cuTile dependencies #71's automatic pip-bundle selection is not reintroduced.
  • ⚠️ Tests & verification evidence: All 12 unit cases in tests/cli/test_environment.py are well-isolated and exercise the real environment.apply() and Configuration.load() (stubbing only runtime_patches.apply), but the 148/148 run is author-reported without observable CI check output on 39796ea, and Windows and end-to-end GPU preparation were not run (disclosed in the PR body).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ignition no longer respects the CUDA_HOME environment variable

3 participants