Skip to content

[build] Expose common build options as PEP 517 config-settings - #200651

Open
Skylion007 wants to merge 1 commit into
pytorch:mainfrom
Skylion007:build/typed-config-settings
Open

Skylion007 wants to merge 1 commit into
pytorch:mainfrom
Skylion007:build/typed-config-settings

Conversation

@Skylion007

@Skylion007 Skylion007 commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
  • Passes lint (spin fixlint)
  • Added/updated tests
  • Updated documentation
  • Included benchmark results (not applicable)

BC-breaking?

Agent details: compatibility (AI-generated)

Raises the scikit-build-core minimum from 1.0 to 1.1 in build requirements and the dev dependency group; updates the CI pin to 1.1.1. Existing environment variables remain supported and take precedence over their corresponding torch.* aliases. Unset settings preserve CMake defaults.

Summary (human written only)

Could you draft how the custom config settings could bring back some of the args on the old setup py installer?

Agent details (AI-generated)

Authored with OpenAI Codex in response to the quoted author request. This is a draft for the author to review; it is not ready for maintainer review.

Motivation and use cases

The goal is to make common source-build choices discoverable and checked at the Python build frontend, especially for contributors iterating on local editable builds and scripts invoking PEP 517 builds. This does not add new compiler capabilities; it gives a small set of existing controls a declared interface with names, types, and help.

  • Catch mistakes before an expensive build. A typo such as USE_CUAD=0 is just an unused environment variable, so a contributor can inadvertently start a CUDA build instead of the CPU-only build they intended. A declared option such as -Ctorch.cuda=false lets the backend validate the setting name and boolean value during settings resolution. This validation applies to config-settings; it does not detect arbitrary misspelled environment variables.
  • Discover options without reading build internals. python -m scikit_build_core settings list exposes the declared settings and their help. The declarations make the supported names, types, environment bindings, and CMake mappings explicit in pyproject.toml.
  • Express build choices through the frontend's standard interface. Contributors and build automation can pass the options in the PEP 517 config_settings mapping, or via pip's -C flags, without constructing shell-specific environment assignments. For example, a CPU-only debug editable build can put its choices directly in the pip invocation below.
  • Validate common options more narrowly than arbitrary CMake defines. -Ccmake.define.NAME=value remains useful for advanced configuration, but it is intentionally open-ended. Declaring common PyTorch options gives the backend enough information to check their names and boolean types; the string settings do not by themselves validate CUDA architecture or BLAS values.

Why aliases are worth considering

Existing environment variables and native backend options already provide these capabilities, including -Ccmake.build-type=Debug and -Ccmake.fresh=true. The benefit being proposed is earlier feedback and discoverability, rather than functionality that cannot otherwise be expressed.

The cost is an additional public spelling to document, test, and support. This proposal keeps the implementation declarative and limits it to common options instead of wrapping the backend or exposing every CMake variable. Whether every alias merits that cost—particularly aliases for already discoverable native backend settings—is part of the review.

Existing environment variables remain supported. In the current implementation, a bound environment variable wins over the corresponding -Ctorch.* option, so a command is not independent of the surrounding environment. Unset aliases leave the existing defaults in place.

Implementation

Adds discoverable, typed torch.* PEP 517 options for debug/RelWithDebInfo builds, CUDA/ROCm/XPU, distributed support, C++ tests, CUDA architecture lists, BLAS selection, and fresh CMake configuration. Declarations, CMake references, and overrides live in pyproject.toml; no backend wrapper is added. The torch.cmake-fresh declaration binds CMAKE_FRESH to the backend's existing cmake.fresh control. Documents the new aliases, precedence, and existing backend controls for verbosity and parallelism.

Example:

python -m pip install -e . -v --no-build-isolation \
  -Ctorch.cuda=false -Ctorch.build-test=false -Ctorch.debug=true

Split libtorch/Python-wheel aliases are deferred because they also need integration with dynamic wheel metadata. Configure-only support is deferred because the backend has no equivalent to CMAKE_ONLY.

Validation

Previously reported local validation with scikit-build-core 1.1.1 (not rerun for this description update):

  • Settings-resolution checks passed for every CMake alias, boolean spellings, unset defaults, environment precedence, build types, raw CMake defines, and fresh configuration.
  • python -m scikit_build_core settings list lists the aliases and help.
  • A small pip-built CMake smoke wheel using the new settings and PyTorch's actual EnvVarForwarding.cmake passed; it checks booleans, Debug, semicolon-separated CUDA architectures, and conflicting environment/config values.
  • git diff --check passed.

The validation harness is local and uncommitted. Full PyTorch compilation, GPU builds, lint, and committed regression coverage are pending.

Outstanding review items

This motivation does not resolve the implementation concerns raised in review: the scikit-build-core bump is being handled separately in #200913; the branch needs rebasing; committed regression coverage is missing; environment/config-setting precedence and legacy boolean spellings need agreement and verification; and torch.cuda-arch-list must account for consumers that read TORCH_CUDA_ARCH_LIST directly from the environment before the two interfaces can be described as equivalent.

@pytorch-bot

pytorch-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

PR Status: in progress

A maintainer requested changes. Please address their feedback before the PR returns to maintainer review.

To become ready for review, please address automated review on your PR either with a code/PR description change. If a review comment is irrelevant, react with 👎 on that specific comment to reject it, and leave a short reply explaining why. The change must pass any running CI and existing failures must be classified as unrelated (see status below in this comment).

Passing automated review does not guarantee that this PR will be merged. It still requires maintainer review and may be closed if its design or direction does not align with the project.

To minimize iteration time, feel free to run the pr-review skill from the repo locally. To trigger a fresh automated review, make a new push or comment @pytorchbot review. To bypass automated review, please add the "no automated review" label.

🟡 AUTOMATED REVIEW - Changes requested:

The PR adds typed `torch.*` PEP 517 config-settings in pyproject.toml as aliases
for common build env vars (DEBUG, USE_CUDA, TORCH_CUDA_ARCH_LIST, BLAS,
CMAKE_FRESH, ), raises the scikit-build-core floor to 1.1 (CI pin 1.1.1) and
documents the settings in CONTRIBUTING.md. Recommendation: Request Changes. The
blockers are zklaus's open requests (split out the version bump, hold the
merge), the lack of committed tests, and `torch.cuda-arch-list` diverging from
`TORCH_CUDA_ARCH_LIST`. The env-over-CLI precedence also needs explicit
agreement.

Findings (6):

[major] pyproject.toml:10
Unaddressed maintainer comment (zklaus): zklaus asked to move the
scikit-build-core bump to # 200913, rebase this PR on top of it once it lands so
it reduces to only the config-settings proposal, and hold off on merging until
they finish a proper review. At HEAD the PR still carries the bump
(.ci/docker/requirements-ci.txt:433, pyproject.toml:10,26,380,
requirements-build.txt:4). Drop those hunks and rebase onto # 200913 once it
lands. zklaus's review is also still pending.

[major] pyproject.toml:68
`torch.cuda-arch-list` is not equivalent to `TORCH_CUDA_ARCH_LIST`. The alias
only becomes `-DTORCH_CUDA_ARCH_LIST=...`, but CMakeLists.txt:1167 decides
`USE_MSLK_DEFAULT` from `"$ENV{TORCH_CUDA_ARCH_LIST}" MATCHES "10.0"`, reading
the environment directly. So `-Ctorch.cuda-arch-list="10.0"` with the env var
unset leaves USE_MSLK off by default, while `TORCH_CUDA_ARCH_LIST=10.0` turns it
on. The docs say the two are interchangeable, but they give different builds.
Fix: switch that check to the CMake variable, resolved env-then-cache the same
way cmake/public/utils.cmake:315 does, then audit an

[major] pyproject.toml:33
No committed tests. The PR body says the validation harness is "local and
uncommitted". Nothing in the tree guards against regressions in: the alias
`cmake.define` mapping; unset settings leaving the CMake defaults alone;
env-over-config precedence; `REL_WITH_DEB_INFO` winning over `DEBUG` (this now
relies on the order of the `[[tool.scikit-build.overrides]]` entries);
`cmake.fresh` wiring. Add a test under `tools/test/` that runs
scikit-build-core's settings reader against pyproject.toml with representative
`config_settings`/env combinations and asserts the resolved `cmake.define`,
`cmak

[minor] CONTRIBUTING.md:258
The environment silently overrides an explicit `-C` flag (see also
pyproject.toml:146). Many dev shells, conda envs and CI images export USE_CUDA,
BUILD_TEST or DEBUG, and in those `-Ctorch.cuda=false` is quietly ignored. Most
CLIs work the other way: the explicit flag beats ambient environment. Part of
the cause is that EnvVarForwarding.cmake FORCE-overrides `-D` values for
USE_*/BUILD_* from the environment, so the order can't be flipped just by
removing the `env =` binding. Either make the explicit setting win (warn on
conflict, or skip forwarding when a matching `-D` was given), or at leas

[minor] CONTRIBUTING.md:241
(Low confidence) The CLI name in the docs may be wrong. This line tells users to
run `scikit-build settings list`, but the PR description validated `python -m
scikit_build_core settings list`. The reviewer couldn't check offline whether
scikit-build-core 1.1 ships a `scikit-build` console script. If it doesn't, the
documented command fails. Use the form that was actually validated.

[minor] pyproject.toml:34
(Low confidence) Existing env vars may now be parsed more strictly. DEBUG,
REL_WITH_DEB_INFO, USE_CUDA, USE_ROCM, USE_XPU, USE_DISTRIBUTED, BUILD_TEST and
CMAKE_FRESH are now parsed by scikit-build-core's `type = "bool"` reader.
Before, the USE_*/BUILD_* values went to CMake unchanged, and CMake accepts
YES/NO/Y/N/TRUE/numbers, while DEBUG went through `if.env` truthiness.
CONTRIBUTING.md documents only true/false, on/off, 1/0. If the bool reader
rejects or misreads other spellings, existing scripts with `USE_CUDA=yes` could
fail or change meaning. So could unrelated tools that set DEBUG to an

Reviewed commit: 2e25ea5

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/200651

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 2e25ea5 with merge base c81fc20 (image):
💚 Looks good so far! There are no failures yet. 💚

🟡 GREEN LIGHT - PR requires human review:

  • Correctness
    • torch.cuda-arch-list only sets -DTORCH_CUDA_ARCH_LIST, but CMakeLists.txt:1167 reads $ENV{TORCH_CUDA_ARCH_LIST} for the MSLK default
    • So the alias and env var yield different builds, contrary to the equivalence CONTRIBUTING.md documents
  • User-facing surface
    • Adds ten new user-set torch.* config-settings in pyproject.toml, a new public build-config spelling
    • Re-parses existing DEBUG, USE_CUDA, BUILD_TEST etc. via scikit-build-core type = "bool" bindings, changing how they are read
  • Build requirements
    • Raises the scikit-build-core floor to 1.1 in pyproject.toml and requirements-build.txt, and moves the CI pin to 1.1.1
  • Review state
    • PR body calls it a draft not ready for review; zklaus asked to hold the merge and split the bump into #​200913

reason: possible_regression
Reviewed commit: 2e25ea5

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added ciflow/docker release notes: releng release notes category labels Oct 12, 2026
@Skylion007
Skylion007 requested review from albanD, atalman, ezyang, malfet and zklaus and removed request for malfet October 12, 2026 16:51
pytorchmergebot pushed a commit that referenced this pull request Oct 12, 2026
… images (#200653)

- [ ] Passes lint (`spin fixlint`)
- [ ] Added/updated tests (Dockerfile deletions; local structural checks only)
- [ ] Updated documentation (not applicable)
- [ ] Included benchmark results (not applicable)

## BC-breaking?

### Agent details: compatibility (AI-generated)

Uses CPython 3.15/3.15t already supplied by the current manylinux base images, replacing the redundant locally compiled 3.15.0rc2 builds.

## Summary (human written only)

> Make a PR that fixes everything

## Agent details (AI-generated)

Prepared with OpenAI Codex at the author's request to cover every Docker image affected by the Python 3.15 installation collision. Draft for human review.

Fresh manywheel Docker builds fail in `install_cpython.sh` with:
```text
ln: failed to create symbolic link '/opt/_internal/cpython-3.15.0/bin/python': File exists
```
The manylinux base images now provide both CPython 3.15 and free-threaded 3.15. Rebuilding into those existing prefixes is unnecessary. Upstream [pypa/manylinux#2001](pypa/manylinux#2001) updates both variants to 3.15.0 final.

Remove the redundant installer `COPY` and `RUN` from:
- `Dockerfile_2_28`: covers x86-64 CPU, CUDA, ROCm and XPU derived images.
- `Dockerfile_2_28_aarch64`: covers the standard AArch64 builder.
- `Dockerfile_cuda_aarch64`: covers CUDA AArch64 builders.

This extends the scope of #200595, which removes only the standard AArch64 block. The s390x image intentionally deletes the base image's Python installation before rebuilding for its development requirements, so its existing rebuild path is retained.

Observed failure: [CPU builder job](https://github.com/pytorch/pytorch/actions/runs/38279825663/job/114914161885) from #200651. The other five failed manywheel image jobs hit the same symlink collision.

Validation: `git diff --check` passed; an ad hoc local comparison confirmed that the only logical instruction removals are the three installer COPY/RUN pairs; all remaining RUN shell commands passed `bash -n`; s390x is unchanged. Docker is unavailable in the local environment, so full image builds and lint are pending. Changes under `.ci/docker` intentionally trigger image rebuilds.
Pull Request resolved: #200653
Approved by: https://github.com/malfet
@Skylion007

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Tried to rebase and push PR #200651, but it was already up to date. Try rebasing against main by issuing:
@pytorchbot rebase -b main

@Skylion007

Copy link
Copy Markdown
Collaborator Author

@pytorchbot rebase -b main

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

Use scikit-build-core 1.1 declarations and overrides to expose existing build knobs without a Python backend wrapper, preserving bound environment variable priority and CMake defaults. Restore CMAKE_FRESH via the backend fresh-configure setting.

Authored with assistance from OpenAI Codex; submitted as a draft for human review.

Test Plan:
```bash
PYTHONPATH=/tmp/sbk11 python agent_space/check_config_settings.py
PYTHONPATH=/tmp/sbk11 python agent_space/check_config_settings.py --wheel
PYTHONPATH=/tmp/sbk11 python -m scikit_build_core settings list
git diff --check
```
The uncommitted local harness checks setting resolution and builds a small smoke wheel using the new configuration and EnvVarForwarding.cmake. No full PyTorch build or lint run.
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased build/typed-config-settings onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout build/typed-config-settings && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the build/typed-config-settings branch from b49a110 to 2e25ea5 Compare October 12, 2026 22:33
@Skylion007
Skylion007 marked this pull request as ready for review October 13, 2026 16:01
@Skylion007
Skylion007 requested a review from a team as a code owner October 13, 2026 16:01
Comment thread CONTRIBUTING.md
| --- | --- |
| `torch.debug` | `DEBUG` |
| `torch.rel-with-deb-info` | `REL_WITH_DEB_INFO` |
| `torch.cuda` | `USE_CUDA` |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This can be changed to use_cuda etc if you want more disambiguation

atalman pushed a commit that referenced this pull request Oct 13, 2026
… images (#200681)

[CD] Remove redundant CPython 3.15 builds from all affected manylinux images (#200653)

- [ ] Passes lint (`spin fixlint`)
- [ ] Added/updated tests (Dockerfile deletions; local structural checks only)
- [ ] Updated documentation (not applicable)
- [ ] Included benchmark results (not applicable)

## BC-breaking?

### Agent details: compatibility (AI-generated)

Uses CPython 3.15/3.15t already supplied by the current manylinux base images, replacing the redundant locally compiled 3.15.0rc2 builds.

## Summary (human written only)

> Make a PR that fixes everything

## Agent details (AI-generated)

Prepared with OpenAI Codex at the author's request to cover every Docker image affected by the Python 3.15 installation collision. Draft for human review.

Fresh manywheel Docker builds fail in `install_cpython.sh` with:
```text
ln: failed to create symbolic link '/opt/_internal/cpython-3.15.0/bin/python': File exists
```
The manylinux base images now provide both CPython 3.15 and free-threaded 3.15. Rebuilding into those existing prefixes is unnecessary. Upstream [pypa/manylinux#2001](pypa/manylinux#2001) updates both variants to 3.15.0 final.

Remove the redundant installer `COPY` and `RUN` from:
- `Dockerfile_2_28`: covers x86-64 CPU, CUDA, ROCm and XPU derived images.
- `Dockerfile_2_28_aarch64`: covers the standard AArch64 builder.
- `Dockerfile_cuda_aarch64`: covers CUDA AArch64 builders.

This extends the scope of #200595, which removes only the standard AArch64 block. The s390x image intentionally deletes the base image's Python installation before rebuilding for its development requirements, so its existing rebuild path is retained.

Observed failure: [CPU builder job](https://github.com/pytorch/pytorch/actions/runs/38279825663/job/114914161885) from #200651. The other five failed manywheel image jobs hit the same symlink collision.

Validation: `git diff --check` passed; an ad hoc local comparison confirmed that the only logical instruction removals are the three installer COPY/RUN pairs; all remaining RUN shell commands passed `bash -n`; s390x is unchanged. Docker is unavailable in the local environment, so full image builds and lint are pending. Changes under `.ci/docker` intentionally trigger image rebuilds.
Pull Request resolved: #200653
Approved by: https://github.com/malfet

(cherry picked from commit a139ef7)

Co-authored-by: Aaron Gokaslan <[email protected]>
@zklaus

zklaus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks for picking this up!

As you perhaps know scikit-build-core 1.1.1 specifically addresses a few bumps we hit in PyTorch, so upgrading is definitely a good idea. In fact, I had started preparing that already, but was waiting on #195587, which got reverted twice due to meta internal breakage. It is landed again and now the scikit-build-core bump PR is up as #200913, so I'd suggest keeping it there and rebasing this PR on top once it lands; this one then reduces to the config-settings proposal.

I'd like to take a closer look at that part before it goes in, so if it's ok, I'd like to ask you to hold off on merging for a bit. I'll come back with a proper review.

@ezyang ezyang added the in progress PR is being worked on by the author, until the automated review accepts it label Oct 19, 2026
Comment thread pyproject.toml

[tool.scikit-build.cmake.define]
USE_CUDA = { config-setting = "torch.cuda" }
USE_ROCM = { config-setting = "torch.rocm" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Posted by Astra, an AI assistant, on behalf of @ezyang. @ezyang reviewed this request and asked that it be posted.

The Windows override replaces the entire cmake.define table with {"CMAKE_GENERATOR": "Ninja"} before alias references are resolved, silently discarding all seven aliases added here. Consequently, options such as -Ctorch.cuda=false and -Ctorch.build-test=false have no effect on Windows. Please add inherit.cmake.define = "append" to that override and regression coverage for Windows settings resolution.

Verified using scikit-build-core 1.1.1’s merge function; no full build was run.

@ezyang

ezyang commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Human here. I'd probably suggest test driving it by hand to see if it's actually useful. Since agents are doing a lot of the builds these days I am not sure how much complexity I want to actually add for this

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of 2e25ea5: changes requested before human review.

The PR adds typed torch.* PEP 517 config-settings in pyproject.toml as aliases for common build env vars (DEBUG, USE_CUDA, TORCH_CUDA_ARCH_LIST, BLAS, CMAKE_FRESH, ), raises the scikit-build-core floor to 1.1 (CI pin 1.1.1) and documents the settings in CONTRIBUTING.md. Recommendation: Request Changes. The blockers are zklaus's open requests (split out the version bump, hold the merge), the lack of committed tests, and torch.cuda-arch-list diverging from TORCH_CUDA_ARCH_LIST. The env-over-CLI precedence also needs explicit agreement.

🔴 3 blocking findings are attached to the code below.

⚪ 3 non-blocking findings

Boolean settings accept `true`/`false`, `on`/`off`, or `1`/`0`. The bound environment

The environment silently overrides an explicit -C flag (see also pyproject.toml:146). Many dev shells, conda envs and CI images export USE_CUDA, BUILD_TEST or DEBUG, and in those -Ctorch.cuda=false is quietly ignored. Most CLIs work the other way: the explicit flag beats ambient environment. Part of the cause is that EnvVarForwarding.cmake FORCE-overrides -D values for USE_/BUILD_ from the environment, so the order can't be flipped just by removing the env = binding. Either make the explicit setting win (warn on conflict, or skip forwarding when a matching -D was given), or at leas


Use `scikit-build settings list` to discover the available settings and their help.

(Low confidence) The CLI name in the docs may be wrong. This line tells users to run scikit-build settings list, but the PR description validated python -m scikit_build_core settings list. The reviewer couldn't check offline whether scikit-build-core 1.1 ships a scikit-build console script. If it doesn't, the documented command fails. Use the form that was actually validated.


type = "bool"

(Low confidence) Existing env vars may now be parsed more strictly. DEBUG, REL_WITH_DEB_INFO, USE_CUDA, USE_ROCM, USE_XPU, USE_DISTRIBUTED, BUILD_TEST and CMAKE_FRESH are now parsed by scikit-build-core's type = "bool" reader. Before, the USE_/BUILD_ values went to CMake unchanged, and CMake accepts YES/NO/Y/N/TRUE/numbers, while DEBUG went through if.env truthiness. CONTRIBUTING.md documents only true/false, on/off, 1/0. If the bool reader rejects or misreads other spellings, existing scripts with USE_CUDA=yes could fail or change meaning. So could unrelated tools that set DEBUG to an

Please address the findings and push; a new commit normally gets a fresh automated review.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

Comment thread pyproject.toml
# 1.1 is required for the custom config-setting declarations below. CI pins the
# exact patch we test against in .ci/docker/requirements-ci.txt.
"scikit-build-core>=1.0",
"scikit-build-core>=1.1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Unaddressed maintainer comment (zklaus): zklaus asked to move the scikit-build-core bump to # 200913, rebase this PR on top of it once it lands so it reduces to only the config-settings proposal, and hold off on merging until they finish a proper review. At HEAD the PR still carries the bump (.ci/docker/requirements-ci.txt:433, pyproject.toml:10,26,380, requirements-build.txt:4). Drop those hunks and rebase onto # 200913 once it lands. zklaus's review is also still pending.

Comment thread pyproject.toml
env = "BUILD_TEST"
help = "Build C++ tests."

[tool.scikit-build.config-setting."torch.cuda-arch-list"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 torch.cuda-arch-list is not equivalent to TORCH_CUDA_ARCH_LIST. The alias only becomes -DTORCH_CUDA_ARCH_LIST=..., but CMakeLists.txt:1167 decides USE_MSLK_DEFAULT from "$ENV{TORCH_CUDA_ARCH_LIST}" MATCHES "10.0", reading the environment directly. So -Ctorch.cuda-arch-list="10.0" with the env var unset leaves USE_MSLK off by default, while TORCH_CUDA_ARCH_LIST=10.0 turns it on. The docs say the two are interchangeable, but they give different builds. Fix: switch that check to the CMake variable, resolved env-then-cache the same way cmake/public/utils.cmake:315 does, then audit an

Comment thread pyproject.toml

# Optional aliases for common build knobs; unset values leave CMake defaults intact.

[tool.scikit-build.config-setting."torch.debug"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 No committed tests. The PR body says the validation harness is "local and uncommitted". Nothing in the tree guards against regressions in: the alias cmake.define mapping; unset settings leaving the CMake defaults alone; env-over-config precedence; REL_WITH_DEB_INFO winning over DEBUG (this now relies on the order of the \[\[tool.scikit-build.overrides\]\] entries); cmake.fresh wiring. Add a test under tools/test/ that runs scikit-build-core's settings reader against pyproject.toml with representative config_settings/env combinations and asserts the resolved cmake.define, `cmak

@zklaus

zklaus commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for pushing on this, Aaron. Looking at it closely together with the underlying scikit-build-core changes settled the precedence inconsistency for me, which is now put in #201664 and #201666, so thanks again.

On the settings themselves I lean similar to Ed. Each one is a second spelling for something that already works, including inline on the command: USE_CUDA=0 pip install -e . reaches every consumer, and -Ccmake.fresh=true or SKBUILD_CMAKE_FRESH=1 already cover the CMAKE_FRESH case; the header line calling that removed is just stale. Two spellings per knob means twice the docs, tests and support questions for no new capability, and I would rather not take that on.

Suggestion: once #200913 has landed, the bump drops out of this PR and I think we can close it. Happy to discuss if you see a knob that genuinely needs a typed setting now.

@Skylion007

Copy link
Copy Markdown
Collaborator Author

Sigh, much bigger fan of typed setting because they are easier since misspelled env variables are rejected. I think CMake.debug is one thing not currently supported by env flags should we enable it?

@pytorchgreenlight pytorchgreenlight Bot added the GL/human GreenLight marked as needing human review label Oct 27, 2026
@jbschlosser jbschlosser added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 29, 2026
@atalman

atalman commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

hi @Skylion007 could you please add a PR description of what is the use case we are trying to solve here ? Also please rebase

zklaus added a commit to zklaus/pytorch that referenced this pull request Nov 9, 2026
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)
pytorchmergebot pushed a commit that referenced this pull request Nov 9, 2026
Go through the following checklist
- [x] Passes lint (`spin fixlint`)
- [x] Added/updated tests
- [x] Updated documentation (if applicable)
- [ ] Included benchmark results (for PRs impacting perf)

---

## Linked issue or supporting maintainer

Part of #201664

## BC-breaking?

No. One behavior change for existing build directories: a `BLAS`, `MKL_THREADING` or `CUDNN_*` value exported in the shell now re-applies on every build and overwrites a ccmake edit of that entry, as `USE_*` and `BUILD_*` 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.

```
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)

Pull Request resolved: #201666
Approved by: https://github.com/atalman
@Skylion007

Copy link
Copy Markdown
Collaborator Author

hi @Skylion007 could you please add a PR description of what is the use case we are trying to solve here ? Also please rebase

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase --onto refs/remotes/origin/viable/strict c81fc20d37d2827588ee5f204c72e2d6883d98ab pull/200651/head returned non-zero exit code 1

Rebasing (1/1)
Auto-merging .ci/docker/requirements-ci.txt
CONFLICT (content): Merge conflict in .ci/docker/requirements-ci.txt
Auto-merging CONTRIBUTING.md
Auto-merging cmake/EnvVarForwarding.cmake
Auto-merging pyproject.toml
CONFLICT (content): Merge conflict in pyproject.toml
Auto-merging requirements-build.txt
CONFLICT (content): Merge conflict in requirements-build.txt
error: could not apply 2e25ea599b0... Expose common build options as PEP 517 config-settings
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 2e25ea599b0... # Expose common build options as PEP 517 config-settings

Raised by https://github.com/pytorch/pytorch/actions/runs/43749550277

This branch was previously deployed

1 inactive deployment
bedrock — 2e25ea59 Deployed Oct 13, 2026 by Skylion007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/docker GL/human GreenLight marked as needing human review in progress PR is being worked on by the author, until the automated review accepts it open source release notes: releng release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants