Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201666
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 705c998 with merge base cbee633 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review |
|
Claude finished @atalman's task in 2m 6s —— View job The routing change works as described. The new precedence rule doesn't hold yet for Full reviewPR Review: #201666SummaryThis PR sends the passthrough and alias env vars through API Design
Code Quality
Testing
RecommendationRequest Changes Fix the |
|
Also please verify that |
cmake/EnvVarForwarding.cmake forwarded its variables with two different semantics. Names matched by prefix (BUILD_*, USE_*, CMAKE_*) have overridden the cache on every configure since pytorch#188242, so changing USE_CUDA in the environment takes effect on the next build. The names in the passthrough and alias lists (BLAS, TORCH_CUDA_ARCH_LIST, CUDNN_*, MKL_THREADING, ...) still used the original seed-only loop, guarded by NOT DEFINED, so they were written once and then ignored: changing BLAS in the environment did nothing to an existing build directory, and -D beat the environment for these names while losing to it for the prefixed ones. This change routes the passthrough names and all aliases through the same _envfwd_apply the prefix names use, so one rule holds for every knob: environment variables win over -D / cmake.define, those win over pyproject.toml, and all three win over what the build directory remembers. For developers this means a BLAS, MKL_THREADING or CUDNN_* value exported in the shell now re-applies on every build, overwriting a ccmake edit of that entry, exactly as USE_* and BUILD_* already did. The _ENV_ALIASES and _LOW_PRIORITY_ALIASES lists collapse into one, with a single semantics: an alias applies only when its canonical name is not itself in the environment, and where several aliases name the same variable the first listed one wins. Among the aliases, the only observable difference is that a canonical name now beats its alias when both are set (CUDNN_LIBRARY over CUDNN_LIB_DIR); no CI job sets both. As a consequence of going through _envfwd_apply, the passthrough and alias names are now also recorded in env_forwarded.txt, so the native-AOT stage-2 drift check covers them, as its docstring already claimed. The alternative, restoring flags-over-environment for the prefixed names instead, was rejected: scikit-build-core resolves its own and every declared config-setting as environment > -C > default, and a project cannot invert that, so flags-over-environment could not have been delivered uniformly. pytorch#200651 binds torch.blas and torch.cuda-arch-list to these names and documents that the bound environment variable takes precedence over the setting; that sentence is only true under this rule, so that PR rebases on this one. The README "Adjust Build Options" and CONTRIBUTING "subsequent builds" paragraphs stated the old seed-only behavior and now state the rule; the EnvVarForwarding header carries it too. Test Plan tools/test/test_env_var_forwarding.py configures a NONE-language CMake project that includes the module and asserts the four tiers for a prefix name and for BLAS (environment over -D, environment over cache, cache kept when the environment is silent, -D over cache), plus canonical-over-alias, alias-over-cache, first-listed-alias-wins and the drift-file recording. Against the unmodified module four of the eight tests fail, exactly the BLAS and alias cases. ``` python -m pytest tools/test/test_env_var_forwarding.py -q lintrunner -a cmake/EnvVarForwarding.cmake tools/test/test_env_var_forwarding.py tools/native_aot/build_stage2.py README.md CONTRIBUTING.md ``` Every commit that touched the module since its introduction was traced to its PR and checked against the new semantics; each CMake-side write to a forwarded variable is either a non-FORCE default or a normal-variable shadow, both of which behave the same under either semantics. Authored with an AI assistant; the diff was reviewed by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`_arch_list` said Dependencies.cmake shadows the cache with the
environment even when the variable is unset. It does not: an unset
`$ENV{}` in `set()` unsets the normal variable and the cache value
shows through. `_refuse_settings_drift` named only the alias lists,
but TORCH_CUDA_ARCH_LIST is a passthrough name.
Both pointed out by the review atalman requested on pytorch#201666.
Test Plan: docstrings only.
Authored with an AI assistant.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
d07ba4d to
705c998
Compare
|
Verified the two points.
On the |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
The reference this PR moves into CONTRIBUTING.md kept changing in its old place while the PR waited, so the rebase has to carry those changes over. pytorch#201666 put every forwarded variable under one precedence rule. The "How to set them" subsection described the earlier split, where prefix-matched names overrode the cache and alias and passthrough names only seeded it, and called it provisional. It now states the single rule: the environment wins over -C flags, which win over pyproject.toml, and all three win over the cache; an alias applies only when its canonical name is not set. The annotations no longer say "seeds the cache only", and the forwarding rule no longer names the removed _LOW_PRIORITY_ALIASES list. The module header keeps the short precedence paragraph pytorch#201666 added next to the forwarding rule. Five variables were documented in the old comment block or the old CONTRIBUTING list since the PR's base and are added to the reference: USE_ROCM_CK_SDPA_GFX11, USE_ROCM_CK_SDPA_GFX12, TORCH_CK_GEMM_ARCH_LIST, CAFFE2_CUSTOM_PROTOC_EXECUTABLE and TORCH_NATIVE_AOT. The TORCH_NATIVE_AOT entry is the existing CONTRIBUTING text, moved, with its skip conditions laid out as a list. The wording of each condition is unchanged, since test_native_aot_tools.py checks CONTRIBUTING.md for it. The `spin develop` and `spin install` help texts pointed at the module for the list of variables, like the README did; they now point at the reference too. The reference told readers to delete build/CMakeCache.txt to configure from scratch, as the old comment block did for the removed CMAKE_FRESH. It now names `-C cmake.fresh=true`, which scikit-build-core has had since 1.1, the floor here, and which pytorch#201664 names as the reset to document. Test Plan: Documentation and help-text change only. ``` lintrunner -a git grep -n "_LOW_PRIORITY_ALIASES\|seeds the cache" python -m pytest tools/test/test_native_aot_tools.py -k documented_skip_reasons ``` The grep finds nothing and the test passes. All in-page anchors in CONTRIBUTING.md resolve, checked with a script that compares every `](#...)` link against the headings. `cmake.fresh` was exercised on a toy project with scikit-build-core 1.1.2 and a persistent build-dir, with one cached option MYOPT whose default is "default". It was not run against a PyTorch build tree. ``` python -m build --wheel --no-isolation -Ccmake.define.MYOPT=first # first python -m build --wheel --no-isolation # first python -m build --wheel --no-isolation -Ccmake.fresh=true # default ``` Authored with the help of an AI assistant (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The reference this PR moves into CONTRIBUTING.md kept changing in its old place while the PR waited, so the rebase has to carry those changes over. pytorch#201666 put every forwarded variable under one precedence rule. The "How to set them" subsection described the earlier split, where prefix-matched names overrode the cache and alias and passthrough names only seeded it, and called it provisional. It now states the single rule: the environment wins over -C flags, which win over pyproject.toml, and all three win over the cache; an alias applies only when its canonical name is not set. The annotations no longer say "seeds the cache only", and the forwarding rule no longer names the removed _LOW_PRIORITY_ALIASES list. The module header keeps the short precedence paragraph pytorch#201666 added next to the forwarding rule. Five variables were documented in the old comment block or the old CONTRIBUTING list since the PR's base and are added to the reference: USE_ROCM_CK_SDPA_GFX11, USE_ROCM_CK_SDPA_GFX12, TORCH_CK_GEMM_ARCH_LIST, CAFFE2_CUSTOM_PROTOC_EXECUTABLE and TORCH_NATIVE_AOT. The TORCH_NATIVE_AOT entry is the existing CONTRIBUTING text, moved, with its skip conditions laid out as a list. The wording of each condition is unchanged, since test_native_aot_tools.py checks CONTRIBUTING.md for it. The `spin develop` and `spin install` help texts pointed at the module for the list of variables, like the README did; they now point at the reference too. The reference told readers to delete build/CMakeCache.txt to configure from scratch, as the old comment block did for the removed CMAKE_FRESH. It now names `-C cmake.fresh=true`, which scikit-build-core has had since 1.1, the floor here, and which pytorch#201664 names as the reset to document. Test Plan: Documentation and help-text change only. ``` lintrunner -a git grep -n "_LOW_PRIORITY_ALIASES\|seeds the cache" python -m pytest tools/test/test_native_aot_tools.py -k documented_skip_reasons ``` The grep finds nothing and the test passes. All in-page anchors in CONTRIBUTING.md resolve, checked with a script that compares every `](#...)` link against the headings. `cmake.fresh` was exercised on a toy project with scikit-build-core 1.1.2 and a persistent build-dir, with one cached option MYOPT whose default is "default". It was not run against a PyTorch build tree. ``` python -m build --wheel --no-isolation -Ccmake.define.MYOPT=first # first python -m build --wheel --no-isolation # first python -m build --wheel --no-isolation -Ccmake.fresh=true # default ``` Authored with the help of an AI assistant (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Go through the following checklist
spin fixlint)Linked issue or supporting maintainer
Part of #201664
BC-breaking?
No. One behavior change for existing build directories: a
BLAS,MKL_THREADINGorCUDNN_*value exported in the shell now re-applies on every build and overwrites a ccmake edit of that entry, asUSE_*andBUILD_*already did since #188242.Summary (human written only)
This PR homogenizes the treatment of configure options for the Pytorch build.
It is part of #201664, implementing most of the necessary changes that are not covered in other PRs or dependent on future changes.
Agent details (if applicable)
Drafted with Claude Code; diff and commit message reviewed by hand. The commit message follows.
cmake/EnvVarForwarding.cmake forwarded its variables with two different semantics. Names matched by prefix (BUILD_, USE_, CMAKE_) have overridden the cache on every configure since #188242, so changing USE_CUDA in the environment takes effect on the next build. The names in the passthrough and alias lists (BLAS, TORCH_CUDA_ARCH_LIST, CUDNN_, MKL_THREADING, ...) still used the original seed-only loop, guarded by NOT DEFINED, so they were written once and then ignored: changing BLAS in the environment did nothing to an existing build directory, and -D beat the environment for these names while losing to it for the prefixed ones.
This change routes the passthrough names and all aliases through the same envfwd_apply the prefix names use, so one rule holds for every knob: environment variables win over -D / cmake.define, those win over pyproject.toml, and all three win over what the build directory remembers. For developers this means a BLAS, MKL_THREADING or CUDNN* value exported in the shell now re-applies on every build, overwriting a ccmake edit of that entry, exactly as USE_* and BUILD_* already did. The _ENV_ALIASES and _LOW_PRIORITY_ALIASES lists collapse into one, with a single semantics: an alias applies only when its canonical name is not itself in the environment, and where several aliases name the same variable the first listed one wins. Among the aliases, the only observable difference is that a canonical name now beats its alias when both are set (CUDNN_LIBRARY over CUDNN_LIB_DIR); no CI job sets both. As a consequence of going through _envfwd_apply, the passthrough and alias names are now also recorded in env_forwarded.txt, so the native-AOT stage-2 drift check covers them, as its docstring already claimed.
The alternative, restoring flags-over-environment for the prefixed names instead, was rejected: scikit-build-core resolves its own and every declared config-setting as environment > -C > default, and a project cannot invert that, so flags-over-environment could not have been delivered uniformly. #200651 binds torch.blas and torch.cuda-arch-list to these names and documents that the bound environment variable takes precedence over the setting; that sentence is only true under this rule, so that PR rebases on this one.
The README "Adjust Build Options" and CONTRIBUTING "subsequent builds" paragraphs stated the old seed-only behavior and now state the rule; the EnvVarForwarding header carries it too.
Test Plan
tools/test/test_env_var_forwarding.py configures a NONE-language CMake project that includes the module and asserts the four tiers for a prefix name and for BLAS (environment over -D, environment over cache, cache kept when the environment is silent, -D over cache), plus canonical-over-alias, alias-over-cache, first-listed-alias-wins and the drift-file recording. Against the unmodified module four of the eight tests fail, exactly the BLAS and alias cases.
Every commit that touched the module since its introduction was traced to its PR and checked against the new semantics; each CMake-side write to a forwarded variable is either a non-FORCE default or a normal-variable shadow, both of which behave the same under either semantics.
Authored with an AI assistant; the diff was reviewed by hand.
🤖 Generated with Claude Code
cc @malfet