Skip to content

Move some pre-build steps from setup.py to CMake - #177641

Closed
zklaus wants to merge 20 commits into
gh/zklaus/35/basefrom
gh/zklaus/35/head
Closed

zklaus wants to merge 20 commits into
gh/zklaus/35/basefrom
gh/zklaus/35/head

Conversation

@zklaus

@zklaus zklaus commented Mar 17, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in #157807.

Adds cmake/PreBuildSteps.cmake, which handles git submodule initialization, replacing the equivalent logic in setup.py's check_submodules().

The submodule check parses .gitmodules to discover submodule paths, verifies they are populated, and runs git submodule update --init --recursive if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

Co-Generated with Claude Code

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 14 New Failures, 7 Cancelled Jobs

As of commit 55f5c4b with merge base d3b8bf0 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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

@pytorch-bot

pytorch-bot Bot commented Mar 17, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

zklaus added a commit to zklaus/pytorch that referenced this pull request Mar 18, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 9a81cee
Pull-Request: pytorch#177641
pytorch-bot Bot pushed a commit that referenced this pull request Mar 21, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 9a81cee
Pull-Request: #177641
pytorch-bot Bot pushed a commit that referenced this pull request Mar 24, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 9a81cee
Pull-Request: #177641
zklaus added a commit to zklaus/pytorch that referenced this pull request Mar 24, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 9a81cee
Pull-Request: pytorch#177641
pytorch-bot Bot pushed a commit that referenced this pull request Mar 26, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 9a81cee
Pull-Request: #177641
[ghstack-poisoned]
zklaus added a commit to zklaus/pytorch that referenced this pull request Mar 28, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: f5e5070
Pull-Request: pytorch#177641
zklaus added 2 commits March 30, 2026 12:30
[ghstack-poisoned]
[ghstack-poisoned]
zklaus added a commit to zklaus/pytorch that referenced this pull request Mar 30, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 2c7c404
Pull-Request: pytorch#177641
@zklaus zklaus added the ciflow/binaries Trigger all binary build and upload jobs on the PR label Mar 31, 2026
@zklaus
zklaus marked this pull request as ready for review March 31, 2026 22:47
@zklaus
zklaus requested review from albanD, atalman and malfet March 31, 2026 22:47
[ghstack-poisoned]
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 1, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: f9f413b
Pull-Request: pytorch#177641
[ghstack-poisoned]
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 2, 2026
Handles git submodule initialization and NCCL checkout from pinned
version, replacing the equivalent logic in setup.py's build_deps().
The module checks for existing state so it is safe to include
unconditionally.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: 7999359
Pull-Request: pytorch#177641
@albanD

albanD commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

Similar tool assisted review as the previous one:

  • Critical: Missing CUDA 12.6 NCCL pin selection. The Python code picks between nccl.txt and
    nccl-cu126.txt based on DESIRED_CUDA/CUDA_VERSION; the CMake version hardcodes nccl.txt. CUDA 12.6
    builds will get the wrong NCCL version.
    • Variable ordering: PreBuildSteps.cmake is included before CMake option() declarations define
      USE_SYSTEM_NCCL, USE_CUDA, etc. Works via env vars but breaks for -D flag users on fresh builds.
    • NCCL clone failure uses WARNING instead of FATAL_ERROR — build continues and fails confusingly
      later.
    • Post-initialization submodule verification (checking for corrupt/partial checkouts) was dropped.

@nWEIdia

nWEIdia commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your continued help, @nWEIdia! I think I found the error. It was with the regular expression used to derive the list of submodule folders from the .gitmodules file. I have added a fix.

You are welcome and thank you for considering our use case into your feature.
I would like to double check on this, as on our end (suppose we don't modify anything), any invocation of "git xxxx" command would fail, because the pytorch src code root is altered (no longer an intact git repo). The only way to avoid that seems to not run "git xxx" at all?
I wonder why regular expression fix helps the case.

@zklaus

zklaus commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator Author

The block from l. 14--31 detected the presence of the .gitmodules file, but because of the broken regex ended with the _submodules_folders variable empty. Because of this, the submodule presence detection (l. 33--42) ended with _all_missing=TRUE, which is why the git checkout fallback block (l.48--61) was tried in the first place.

Now, the correct list of submodules is constructed from .gitmodules, the presence detection works and the code skips over the git fallback.

@nWEIdia

nWEIdia commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

The block from l. 14--31 detected the presence of the .gitmodules file, but because of the broken regex ended with the _submodules_folders variable empty. Because of this, the submodule presence detection (l. 33--42) ended with _all_missing=TRUE, which is why the git checkout fallback block (l.48--61) was tried in the first place.

Now, the correct list of submodules is constructed from .gitmodules, the presence detection works and the code skips over the git fallback.

Thanks for the explanation, makes sense!
How about the NCCL related changes? Is it possible to separate them out (just in case something breaks/happens).

I will import this updated code to test.

[ghstack-poisoned]
@zklaus

zklaus commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for testing it. I have moved the nccl changes to a new PR in the stack, #181450.

@nWEIdia

nWEIdia commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for testing it. I have moved the nccl changes to a new PR in the stack, #181450.

Sure thing. FYI we can now build successfully with this PR at this point.

@nWEIdia nWEIdia 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.

LGTM

Nit: please update PR description to move NCCL related changes out. But make sure you mention the motivation of this PR.

[ghstack-poisoned]
@zklaus

zklaus commented Apr 26, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -f "Failures unrelated"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Apr 28, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in #157807.
It was previously part of #177641, had received approval there and was split off by request to allow more internal testing.

Adds NCCL checkout from the pinned version to `cmake/PreBuildSteps.cmake`, replacing the equivalent logic in `tools/build_pytorch_libs.py`'s NCCL clone block.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: #181450
Approved by: https://github.com/atalman
@github-actions
github-actions Bot deleted the gh/zklaus/35/head branch May 27, 2026 02:29
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
Adds `cmake/PreBuildSteps.cmake`, which handles git submodule initialization and NCCL checkout from the pinned version, replacing the equivalent logic in `setup.py`'s `check_submodules()` and `tools/build_pytorch_libs.py`'s NCCL clone block.

The submodule check parses `.gitmodules` to discover submodule paths, verifies they are populated, and runs `git submodule update --init --recursive` if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#177641
Approved by: https://github.com/atalman, https://github.com/albanD
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in pytorch#157807.

Adds `cmake/PreBuildSteps.cmake`, which handles git submodule initialization, replacing the equivalent logic in `setup.py`'s `check_submodules()`.

The submodule check parses `.gitmodules` to discover submodule paths, verifies they are populated, and runs `git submodule update --init --recursive` if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#177641
Approved by: https://github.com/atalman, https://github.com/albanD, https://github.com/nWEIdia
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in pytorch#157807.
It was previously part of pytorch#177641, had received approval there and was split off by request to allow more internal testing.

Adds NCCL checkout from the pinned version to `cmake/PreBuildSteps.cmake`, replacing the equivalent logic in `tools/build_pytorch_libs.py`'s NCCL clone block.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#181450
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Adds `cmake/PreBuildSteps.cmake`, which handles git submodule initialization and NCCL checkout from the pinned version, replacing the equivalent logic in `setup.py`'s `check_submodules()` and `tools/build_pytorch_libs.py`'s NCCL clone block.

The submodule check parses `.gitmodules` to discover submodule paths, verifies they are populated, and runs `git submodule update --init --recursive` if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#177641
Approved by: https://github.com/atalman, https://github.com/albanD
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in pytorch#157807.

Adds `cmake/PreBuildSteps.cmake`, which handles git submodule initialization, replacing the equivalent logic in `setup.py`'s `check_submodules()`.

The submodule check parses `.gitmodules` to discover submodule paths, verifies they are populated, and runs `git submodule update --init --recursive` if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#177641
Approved by: https://github.com/atalman, https://github.com/albanD, https://github.com/nWEIdia
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in pytorch#157807.
It was previously part of pytorch#177641, had received approval there and was split off by request to allow more internal testing.

Adds NCCL checkout from the pinned version to `cmake/PreBuildSteps.cmake`, replacing the equivalent logic in `tools/build_pytorch_libs.py`'s NCCL clone block.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#181450
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Adds `cmake/PreBuildSteps.cmake`, which handles git submodule initialization and NCCL checkout from the pinned version, replacing the equivalent logic in `setup.py`'s `check_submodules()` and `tools/build_pytorch_libs.py`'s NCCL clone block.

The submodule check parses `.gitmodules` to discover submodule paths, verifies they are populated, and runs `git submodule update --init --recursive` if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#177641
Approved by: https://github.com/atalman, https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in pytorch#157807.

Adds `cmake/PreBuildSteps.cmake`, which handles git submodule initialization, replacing the equivalent logic in `setup.py`'s `check_submodules()`.

The submodule check parses `.gitmodules` to discover submodule paths, verifies they are populated, and runs `git submodule update --init --recursive` if needed. It also validates that expected marker files exist (catches corrupt/partial checkouts) and checks fbgemm's nested asmjit dependency.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#177641
Approved by: https://github.com/atalman, https://github.com/albanD, https://github.com/nWEIdia
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
This PR is part of the work to replace the old setuptools based build system frontend with a modern and easier to maintain scikit-build-core one described in pytorch#157807.
It was previously part of pytorch#177641, had received approval there and was split off by request to allow more internal testing.

Adds NCCL checkout from the pinned version to `cmake/PreBuildSteps.cmake`, replacing the equivalent logic in `tools/build_pytorch_libs.py`'s NCCL clone block.

The NCCL checkout uses `FetchContent` to clone from the tag pinned in `.ci/docker/ci_commit_pins/nccl*.txt`, with support for CUDA-version-specific pin files. It is skipped when `USE_DISTRIBUTED`, `USE_CUDA`, or `USE_NCCL` is explicitly off, or when the checkout already exists.

The corresponding Python code is removed from `setup.py` and simplified in `tools/build_pytorch_libs.py`. The module checks for existing state so it is safe to include unconditionally under both setuptools and scikit-build-core.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#181450
Approved by: https://github.com/atalman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: releng release notes category Reverted suppress-api-compatibility-check Suppresses the failures of API backward-compatibility linter (Lint/bc_linter)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants