Repository navigation
Preserve inherited CUDA_HOME in ignition.cli.environment - #690
Conversation
|
A case file has been opened for 690. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedThe
Walkthrough
Merge Risk: Low · up to
|
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
682152b to
39796ea
Compare
|
@flare-autobot Addressed all review items in
Validation on Linux x86_64 with |
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeHead
Walkthrough
Merge Risk: Low · up to
|
Fixes #636
Why
Issue #636 reports that
ignitionno longer respects an inheritedCUDA_HOMEenvironment variable. On non-Windows hosts where/usr/local/cudaexists,ignition.cli.environment.applyfell back to/usr/local/cudawhenever[paths] cudawas unset inconfig.toml, unconditionally overwritingCUDA_HOMEand pointing unsetTRITON_PTXAS_PATHandCPATHentries at/usr/local/cuda. On systems with multiple CUDA toolkits installed, preparation runs that select a non-default toolkit throughCUDA_HOMEwere silently redirected to/usr/local/cuda.Preserving a non-empty inherited
CUDA_HOMEbefore the/usr/local/cudafallback falls within Principle 10's documented CUDA device selection and dependency setup policy exception (docs/design-review.md):CUDA_HOMEselects the native CUDA toolkit dependency rather than toggling Flare behavior, while explicit[paths] cudaconfiguration retains top precedence and existingTRITON_PTXAS_PATHandCPATHhandling remain unchanged.What changed
ignition/cli/environment.py: Defined_DEFAULT_LINUX_CUDA = Path("/usr/local/cuda")and updatedapplyon non-Windows hosts to resolve the CUDA toolkit in order:[paths] cudafrom Flare configuration (configuration.directory("cuda")), overriding inheritedCUDA_HOME.CUDA_HOMEfromos.environ(whitespace stripped), preserved without falling back to/usr/local/cuda./usr/local/cuda(_DEFAULT_LINUX_CUDA) when that directory exists.CUDA_HOMEfromos.environso native build libraries perform their own toolkit discovery cleanly.Previously, the non-Windows branch checked only whether
[paths] cudawas absent and/usr/local/cudaexisted, overwriting any inheritedCUDA_HOMEand leaving whitespace-onlyCUDA_HOMEvalues inos.environwhen/usr/local/cudawas absent.TRITON_PTXAS_PATH(if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ),CPATHprepending, and Windows (os.name == "nt") behavior are unchanged.docs/cli-design.md,AGENTS.md, anddocs/model-preparation.md: Reconciled the normative environment-variable and precedence statements indocs/cli-design.mdandAGENTS.mdwith Principle 10 and the CUDA toolkit configuration table indocs/cli-design.md, and keptdocs/model-preparation.mdas a brief summary pointing todocs/cli-design.mdas the canonical specification.tests/cli/test_environment.py: Added unit tests with a module-level POSIXpytestmarkand a leak-freeclean_environmentfixture (restoring both originally present and originally absent environment variables after every test) covering explicit[paths] cudaoverrides (with both unset and pre-setTRITON_PTXAS_PATH), inheritedCUDA_HOMEpreservation (including whitespace-padded paths, pre-setTRITON_PTXAS_PATHand existingCPATHentries, and paths without local toolkit files), empty/whitespaceCUDA_HOMEfallback to_DEFAULT_LINUX_CUDA, and removing empty/whitespaceCUDA_HOMEwhen no toolkit source exists.Claimed result
On non-Windows hosts with
/usr/local/cudapresent,ignitionpreserves a caller-suppliedCUDA_HOME(normalizing surrounding whitespace) and derives unsetTRITON_PTXAS_PATHandCPATHentries from that toolkit when[paths] cudais unset, without alteringTRITON_PTXAS_PATHorCPATHprecedence. Explicit[paths] cudaoverrides inheritedCUDA_HOME, hosts without[paths] cudaor a non-emptyCUDA_HOMEretain the/usr/local/cudafallback, and blankCUDA_HOMEvalues are cleared when no toolkit source exists.Supporting evidence and limitations
CUDA_VISIBLE_DEVICES="":pytest tests/cli -v: 148 passed, including all 12 cases intests/cli/test_environment.py.os.environsnapshot restoration acrosstests/cli/test_environment.py: every managed variable in_ENV_KEYSmatched its pre-session value (or absence) after pytest completed.tests/cli/test_environment.pyredirectignition.cli.environment._DEFAULT_LINUX_CUDAto temporary directories and stubignition.cli.environment.runtime_patches.applyso environment selection is tested without requiring/usr/local/cudaor pinned PyTorch/Triton patch versions.os.name == "nt") execution and end-to-end GPU model preparation were not run.Discord: jcartu