Skip to content

Install Rust toolchain in PyTorch CI/CD build images (#186302) - #186302

Closed
aorenste wants to merge 1 commit into
pytorch:mainfrom
aorenste:export-D107557726
Closed

aorenste wants to merge 1 commit into
pytorch:mainfrom
aorenste:export-D107557726

Conversation

@aorenste

@aorenste aorenste commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

PyTorch's build now compiles the torch._rust extension via cargo (invoked by the OSS CMake build and by Buck), so cargo/rustc must be present in the build images. This adds a shared common/install_rust.sh (distro-agnostic: apt for the Ubuntu CI images, yum/dnf for the manylinux CD images) plus a ci_commit_pins/rust.txt version pin (rust 1.97.1, matching fbcode's Buck toolchain), installs the toolchain system-wide under /opt/rust (world-writable so the unprivileged build user can use it and write the cargo cache), and wires it into:

  • CI images: ubuntu/, ubuntu-rocm/, ubuntu-xpu/ Dockerfiles
  • CD images: manywheel Dockerfile_2_28, Dockerfile_2_28_aarch64, Dockerfile_cuda_aarch64

The conda feedstock recipe gains a rust build dep so conda-build can compile the extension.

No-op until torch._rust lands. Split out of D106044299 so the feature builds against images that already provide cargo.

Test Plan:
docker-build jobs for the affected images succeed with cargo present; build-osdc jobs find /opt/rust/bin/cargo.

The first CI run pinned rust 1.85.0, which broke every manywheel/CD wheel build: with cargo now on PATH, pip install compiles hypothesis-native from sdist for cpython-3.15t, and that crate requires rustc >= 1.91. Bumped ci_commit_pins/rust.txt to 1.97.1 (current stable; matches fbcode's Buck rust toolchain). Manywheel build re-verification pending on the next CI run.

Authored with Claude.

Reviewed By: bobrenjc93, jathu

Differential Revision: D107557726

@aorenste
aorenste requested review from a team and jeffdaily as code owners June 5, 2026 01:16
@pytorch-bot

pytorch-bot Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ You can merge normally! (5 Unrelated Failures), 1 Unclassified Failure

As of commit 416b792 with merge base e943445 (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • xpu / linux-noble-xpu-n-py3.10 / test (default, 12, 12, linux.idc.xpu) (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    ##[error]User: arn:aws:sts::308535385114:assumed-role/gha_workflow_s3_and_ecr_read_only/gha-ecr-login is not authorized to perform: s3:PutObject on resource: "arn:aws:s3:::gha-artifacts/pytorch/pytorch/30390848605/1/artifact/test-jsons-test-default-12-12-linux.idc.xpu_90390715272.zip" because no identity-based policy allows the s3:PutObject action

    AI verdict: AI verdict: infra issue

    The failure is an AWS IAM permission error preventing S3 artifact upload, not a test or code failure. This same error appears across all trunk commits and shards, indicating a CI infrastructure issue with the gha_workflow_s3_and_ecr_read_only IAM role.

    Full reasoning on HUD →

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

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

@meta-codesync

meta-codesync Bot commented Jun 5, 2026

Copy link
Copy Markdown

@aorenste has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107557726.

@aorenste
aorenste marked this pull request as draft June 18, 2026 22:51
@aorenste
aorenste force-pushed the export-D107557726 branch from 0b34166 to 72a8cff Compare June 18, 2026 22:52
@meta-codesync meta-codesync Bot changed the title Install Rust toolchain in PyTorch CI/CD build images Install Rust toolchain in PyTorch CI/CD build images (#186302) Jul 7, 2026
@aorenste
aorenste force-pushed the export-D107557726 branch from 72a8cff to 850e83d Compare July 7, 2026 03:18
aorenste added a commit to aorenste/pytorch that referenced this pull request Jul 7, 2026
Summary:

PyTorch's build now compiles the torch._rust extension via setup.py (cargo) and Buck, so cargo/rustc must be present in the build images. This adds a shared common/install_rust.sh (distro-agnostic: apt for the Ubuntu CI images, yum/dnf for the manylinux CD images) plus a ci_commit_pins/rust.txt version pin, installs the toolchain system-wide under /opt/rust (world-writable so the unprivileged build user can use it and write the cargo cache), and wires it into:
- CI images: ubuntu/, ubuntu-rocm/, ubuntu-xpu/ Dockerfiles
- CD images: manywheel Dockerfile_2_28, Dockerfile_2_28_aarch64, Dockerfile_cuda_aarch64

install_cache.sh now reuses this persistent toolchain to build sccache (dropping its own throwaway rustup install and self-uninstall). The conda feedstock recipe gains a rust build dep so conda-build can compile the extension.

No-op until torch._rust lands. Split out of D106044299 so the feature builds against images that already provide cargo.

Test Plan:
docker-build jobs for the affected images succeed with cargo present; build-osdc jobs find /opt/rust/bin/cargo. Verified by CI on the stacked torch._rust diff (all build jobs green).

Authored with Claude.

Differential Revision: D107557726
@aorenste
aorenste requested a review from bobrenjc93 July 8, 2026 17:49
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 9, 2026
@aorenste
aorenste force-pushed the export-D107557726 branch from 850e83d to b9f441a Compare July 9, 2026 17:31
aorenste added a commit to aorenste/pytorch that referenced this pull request Jul 9, 2026
Summary:

PyTorch's build now compiles the torch._rust extension via setup.py (cargo) and Buck, so cargo/rustc must be present in the build images. This adds a shared common/install_rust.sh (distro-agnostic: apt for the Ubuntu CI images, yum/dnf for the manylinux CD images) plus a ci_commit_pins/rust.txt version pin, installs the toolchain system-wide under /opt/rust (world-writable so the unprivileged build user can use it and write the cargo cache), and wires it into:
- CI images: ubuntu/, ubuntu-rocm/, ubuntu-xpu/ Dockerfiles
- CD images: manywheel Dockerfile_2_28, Dockerfile_2_28_aarch64, Dockerfile_cuda_aarch64

install_cache.sh now reuses this persistent toolchain to build sccache (dropping its own throwaway rustup install and self-uninstall). The conda feedstock recipe gains a rust build dep so conda-build can compile the extension.

No-op until torch._rust lands. Split out of D106044299 so the feature builds against images that already provide cargo.

Test Plan:
docker-build jobs for the affected images succeed with cargo present; build-osdc jobs find /opt/rust/bin/cargo. Verified by CI on the stacked torch._rust diff (all build jobs green).

Authored with Claude.

Reviewed By: bobrenjc93

Differential Revision: D107557726
@aorenste
aorenste force-pushed the export-D107557726 branch from b9f441a to 62deda5 Compare July 27, 2026 20:46
aorenste added a commit to aorenste/pytorch that referenced this pull request Jul 27, 2026
Summary:

PyTorch's build now compiles the torch._rust extension via setup.py (cargo) and Buck, so cargo/rustc must be present in the build images. This adds a shared common/install_rust.sh (distro-agnostic: apt for the Ubuntu CI images, yum/dnf for the manylinux CD images) plus a ci_commit_pins/rust.txt version pin, installs the toolchain system-wide under /opt/rust (world-writable so the unprivileged build user can use it and write the cargo cache), and wires it into:
- CI images: ubuntu/, ubuntu-rocm/, ubuntu-xpu/ Dockerfiles
- CD images: manywheel Dockerfile_2_28, Dockerfile_2_28_aarch64, Dockerfile_cuda_aarch64

The conda feedstock recipe gains a rust build dep so conda-build can compile the extension.

No-op until torch._rust lands. Split out of D106044299 so the feature builds against images that already provide cargo.

Test Plan:
docker-build jobs for the affected images succeed with cargo present; build-osdc jobs find /opt/rust/bin/cargo. Verified by CI on the stacked torch._rust diff (all build jobs green).

Authored with Claude.

Reviewed By: bobrenjc93, jathu

Differential Revision: D107557726
@aorenste aorenste added ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/rocm-mi350 Trigger "default" config CI on ROCm MI350 runners labels Jul 28, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/rocm-mi350.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-navi31
  • ciflow/rocm-nightly
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

@aorenste aorenste added the ciflow/xpu Run XPU CI tasks label Jul 28, 2026
@aorenste aorenste added ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/mps Run MPS tests (subset of trunk) and removed ciflow/rocm-mi350 Trigger "default" config CI on ROCm MI350 runners labels Jul 28, 2026
Summary:

PyTorch's build now compiles the torch._rust extension via cargo (invoked by the OSS CMake build and by Buck), so cargo/rustc must be present in the build images. This adds a shared common/install_rust.sh (distro-agnostic: apt for the Ubuntu CI images, yum/dnf for the manylinux CD images) plus a ci_commit_pins/rust.txt version pin (rust 1.97.1, matching fbcode's Buck toolchain), installs the toolchain system-wide under /opt/rust (world-writable so the unprivileged build user can use it and write the cargo cache), and wires it into:
- CI images: ubuntu/, ubuntu-rocm/, ubuntu-xpu/ Dockerfiles
- CD images: manywheel Dockerfile_2_28, Dockerfile_2_28_aarch64, Dockerfile_cuda_aarch64

The conda feedstock recipe gains a rust build dep so conda-build can compile the extension.

No-op until torch._rust lands. Split out of D106044299 so the feature builds against images that already provide cargo.

Test Plan:
docker-build jobs for the affected images succeed with cargo present; build-osdc jobs find /opt/rust/bin/cargo.

The first CI run pinned rust 1.85.0, which broke every manywheel/CD wheel build: with cargo now on PATH, `pip install` compiles hypothesis-native from sdist for cpython-3.15t, and that crate requires rustc >= 1.91. Bumped ci_commit_pins/rust.txt to 1.97.1 (current stable; matches fbcode's Buck rust toolchain). Manywheel build re-verification pending on the next CI run.

Authored with Claude.

Reviewed By: bobrenjc93, jathu

Differential Revision: D107557726
@aorenste
aorenste force-pushed the export-D107557726 branch from 62deda5 to 416b792 Compare July 28, 2026 19:11
@huydhn
huydhn marked this pull request as ready for review July 29, 2026 06:38
@huydhn

huydhn commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: xpu / linux-noble-xpu-n-py3.10 / test (default, 12, 12, linux.idc.xpu)

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

ezyang added a commit that referenced this pull request Jul 29, 2026
…mages

PRs that touch .ci/docker generate a new set of CI docker images, keyed by
the git tree hash of .ci/docker (see docker-builds.yml, which tags images
with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images
are missing or stale, every downstream trunk job fails because it can't find
the image it needs -- as happened in the #190927 / #186302 land race, where a
force-merge bypassed CI and a second docker PR landed in the skew window.

Add two hard gates in merge_into (the shared chokepoint for both normal and
force merges, so -f no longer bypasses them):

1. check_docker_builds_ready: a docker-affecting PR must have run the
   docker-builds (ciflow/docker) workflow with all jobs passing, so the
   images are pre-built and pushed to ECR. Pending builds raise
   MandatoryChecksMissingError so a normal merge waits; missing/failed
   builds are refused.

2. check_no_docker_merge_skew: after the merge commit is created locally,
   its .ci/docker tree hash must match the tree that ciflow/docker actually
   built and tested on the PR head. A mismatch means another docker change
   landed in the skew window and the required images were never built, so
   the merge is refused with a request to rebase.

Both gates are intentionally not overridable by -f, matching existing
-f-proof invariants like ghstack-out-of-sync and internal-changes-must-land-
via-Phabricator. Add unit tests for the pure helpers.

ghstack-source-id: a820cfd
Pull-Request: #191508
ezyang added a commit that referenced this pull request Jul 29, 2026
…mages

PRs that touch .ci/docker generate a new set of CI docker images, keyed by
the git tree hash of .ci/docker (see docker-builds.yml, which tags images
with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images
are missing or stale, every downstream trunk job fails because it can't find
the image it needs -- as happened in the #190927 / #186302 land race, where a
force-merge bypassed CI and a second docker PR landed in the skew window.

Add two hard gates in merge_into (the shared chokepoint for both normal and
force merges, so -f no longer bypasses them):

1. check_docker_builds_ready: a docker-affecting PR must have run the
   docker-builds (ciflow/docker) workflow with all jobs passing, so the
   images are pre-built and pushed to ECR. Pending builds raise
   MandatoryChecksMissingError so a normal merge waits; missing/failed
   builds are refused.

2. check_no_docker_merge_skew: after the merge commit is created locally,
   its .ci/docker tree hash must match the tree that ciflow/docker actually
   built and tested on the PR head. A mismatch means another docker change
   landed in the skew window and the required images were never built, so
   the merge is refused with a request to rebase.

Both gates are intentionally not overridable by -f, matching existing
-f-proof invariants like ghstack-out-of-sync and internal-changes-must-land-
via-Phabricator. Add unit tests for the pure helpers.

ghstack-source-id: 58e7dfa
Pull-Request: #191508
ezyang added a commit that referenced this pull request Jul 30, 2026
…mages

PRs that touch .ci/docker generate a new set of CI docker images, keyed by
the git tree hash of .ci/docker (see docker-builds.yml, which tags images
with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images
are missing or stale, every downstream trunk job fails because it can't find
the image it needs -- as happened in the #190927 / #186302 land race, where a
force-merge bypassed CI and a second docker PR landed in the skew window.

Add two hard gates in merge_into (the shared chokepoint for both normal and
force merges, so -f no longer bypasses them):

1. check_docker_builds_ready: a docker-affecting PR must have run the
   docker-builds (ciflow/docker) workflow with all jobs passing, so the
   images are pre-built and pushed to ECR. Pending builds raise
   MandatoryChecksMissingError so a normal merge waits; missing/failed
   builds are refused.

2. check_no_docker_merge_skew: after the merge commit is created locally,
   its .ci/docker tree hash must match the tree that ciflow/docker actually
   built and tested on the PR head. A mismatch means another docker change
   landed in the skew window and the required images were never built, so
   the merge is refused with a request to rebase.

Both gates are intentionally not overridable by -f, matching existing
-f-proof invariants like ghstack-out-of-sync and internal-changes-must-land-
via-Phabricator. Add unit tests for the pure helpers.

ghstack-source-id: 8cfe250
Pull-Request: #191508
tinglvv added a commit that referenced this pull request Jul 30, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Source the cargo env from $CARGO_HOME. Since #186302 the builder images
pre-install rust at /opt/rust and set CARGO_HOME=/opt/rust, so rustup's env file
is /opt/rust/env, not $HOME/.cargo/env. Hardcoding `. "$HOME/.cargo/env"` made
every from-source image fail at that line before reaching cargo (this caused the
revert of the first landing). Use `. "${CARGO_HOME:-$HOME/.cargo}/env"`.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Jul 30, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Jul 30, 2026
…mages (#191508)

PRs that touch .ci/docker generate a new set of CI docker images, keyed by
the git tree hash of .ci/docker (see docker-builds.yml, which tags images
with `git rev-parse HEAD:.ci/docker`). If such a PR lands while its images
are missing or stale, every downstream trunk job fails because it can't find
the image it needs -- as happened in the #190927 / #186302 land race, where a
force-merge bypassed CI and a second docker PR landed in the skew window.

Add two hard gates in merge_into (the shared chokepoint for both normal and
force merges, so -f no longer bypasses them):

1. check_docker_builds_ready: a docker-affecting PR must have run the
   docker-builds (ciflow/docker) workflow with all jobs passing, so the
   images are pre-built and pushed to ECR. Pending builds raise
   MandatoryChecksMissingError so a normal merge waits; missing/failed
   builds are refused.

2. check_no_docker_merge_skew: after the merge commit is created locally,
   its .ci/docker tree hash must match the tree that ciflow/docker actually
   built and tested on the PR head. A mismatch means another docker change
   landed in the skew window and the required images were never built, so
   the merge is refused with a request to rebase.

Both gates are intentionally not overridable by -f, matching existing
-f-proof invariants like ghstack-out-of-sync and internal-changes-must-land-
via-Phabricator. Add unit tests for the pure helpers.
Pull Request resolved: #191508
Approved by: https://github.com/huydhn
pytorchmergebot pushed a commit that referenced this pull request Jul 30, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…pytorch#186302)

Summary:

PyTorch's build now compiles the torch._rust extension via cargo (invoked by the OSS CMake build and by Buck), so cargo/rustc must be present in the build images. This adds a shared common/install_rust.sh (distro-agnostic: apt for the Ubuntu CI images, yum/dnf for the manylinux CD images) plus a ci_commit_pins/rust.txt version pin (rust 1.97.1, matching fbcode's Buck toolchain), installs the toolchain system-wide under /opt/rust (world-writable so the unprivileged build user can use it and write the cargo cache), and wires it into:
- CI images: ubuntu/, ubuntu-rocm/, ubuntu-xpu/ Dockerfiles
- CD images: manywheel Dockerfile_2_28, Dockerfile_2_28_aarch64, Dockerfile_cuda_aarch64

The conda feedstock recipe gains a rust build dep so conda-build can compile the extension.

No-op until torch._rust lands. Split out of D106044299 so the feature builds against images that already provide cargo.

Test Plan:
docker-build jobs for the affected images succeed with cargo present; build-osdc jobs find /opt/rust/bin/cargo.

The first CI run pinned rust 1.85.0, which broke every manywheel/CD wheel build: with cargo now on PATH, `pip install` compiles hypothesis-native from sdist for cpython-3.15t, and that crate requires rustc >= 1.91. Bumped ci_commit_pins/rust.txt to 1.97.1 (current stable; matches fbcode's Buck rust toolchain). Manywheel build re-verification pending on the next CI run.

Authored with Claude.

Reviewed By: bobrenjc93, jathu

Differential Revision: D107557726

Pull Request resolved: pytorch#186302
Approved by: https://github.com/bobrenjc93
pytorchmergebot pushed a commit that referenced this pull request Aug 1, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 2, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 2, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix backported from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch), which locates the cicc/ptxas
input by its generated-file suffix (.cpp1.ii / .ptx) instead of by position, in
both cicc.rs and nvcc.rs. Build from source for all image types (riscv64 keeps
the prebuilt binary: no nvcc, no sccache-dist, and a from-source build under
QEMU emulation would be impractically slow) so the whole fleet shares a single
sccache binary; the patch is a no-op on older/non-CUDA compiles (it only changes
how the input is located and falls back to the old offset).

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker). The patch applies
cleanly to sccache v0.16.0 (`git apply --check`). Validate in a CUDA 13.3+ CI
image (e.g. cuda13.4):

  echo '__global__ void k() {}' > repro.cu
  sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). Build from source for all
image types (riscv64 keeps the prebuilt binary: no nvcc, no sccache-dist, and a
from-source build under QEMU emulation would be impractically slow) so the whole
fleet shares a single sccache binary.

The backport gates #2722 rather than taking it verbatim. Upstream replaces the
positional lookup with a search for the input's generated-file suffix
(.cpp1.ii / .ptx) unconditionally, for both cicc and ptxas. Upstream's own
dryrun fixture shows --simt-only on the cudafe++ and cicc lines but not on the
ptxas line, so ptxas offsets were already correct and did not need changing;
running the search there regressed CUDA < 13.3, where torchao's mxfp8 extension
fails to build with `Missing "cubin" file output` while stock sccache builds it
fine. Here the suffix search runs only when the argument at the historical
offset is not a generated input file, so every command line nvcc still emits in
the old shape parses exactly as stock 0.16.0 does -- same input, same cache keys
-- and 13.3+ still gets the fix on the cicc line that needs it.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. Reaching that error means the input was located at the wrong
argument and -o was consumed or dropped, and nvcc reshapes these sub-commands
between CUDA releases, so the argument vector as sccache saw it is the thing
needed to diagnose the next occurrence.

Two alternatives were considered. Dropping the ptxas half of #2722 outright is a
smaller diff, but it leaves cicc's search unconditional on older CUDA (the same
pattern, one compiler over) and gives ptxas no fallback if NVIDIA later shifts
its input off the offset the way it did for cicc. Disabling sccache on 13.3+
avoids the parser entirely but gives up CUDA caching, which is the point of
having sccache at all.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker), so the patch is not
compiled or unit-tested locally. It applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

Validate in a CUDA 13.3+ CI image (e.g. cuda13.4):

```
echo '__global__ void k() {}' > repro.cu
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm the CUDA 13.0/13.2 torchao build (which regressed on the ungated
backport) plus non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
nvcc 13.3+ injects a valueless --simt-only flag (Tile compilation) into the
cicc/cudafe++ sub-commands of `nvcc --dryrun`, typically right before -o. The
prebuilt sccache 0.16.0 locates the cicc/ptxas input by a fixed offset from the
end of the argument list and groups the dryrun sub-commands positionally, so the
extra token makes it mis-locate the input and skip the device compile. ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". This affects any separable/relocatable (-rdc=true) CUDA
target (e.g. gloo_cuda, torch_nvshmem).

Revert #189365 (prebuilt-binary download) and build sccache 0.16.0 from source
again, applying the upstream fix from mozilla/sccache#2722
(patches/sccache-nvcc-13.3-dryrun-parsing.patch). Build from source for all
image types (riscv64 keeps the prebuilt binary: no nvcc, no sccache-dist, and a
from-source build under QEMU emulation would be impractically slow) so the whole
fleet shares a single sccache binary.

The backport gates #2722 rather than taking it verbatim. Upstream replaces the
positional lookup with a search for the input's generated-file suffix
(.cpp1.ii / .ptx) unconditionally, for both cicc and ptxas. Upstream's own
dryrun fixture shows --simt-only on the cudafe++ and cicc lines but not on the
ptxas line, so ptxas offsets were already correct and did not need changing;
running the search there regressed CUDA < 13.3, where torchao's mxfp8 extension
fails to build with `Missing "cubin" file output` while stock sccache builds it
fine. Here the suffix search runs only when the argument at the historical
offset is not a generated input file, so every command line nvcc still emits in
the old shape parses exactly as stock 0.16.0 does -- same input, same cache keys
-- and 13.3+ still gets the fix on the cicc line that needs it.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. Reaching that error means the input was located at the wrong
argument and -o was consumed or dropped, and nvcc reshapes these sub-commands
between CUDA releases, so the argument vector as sccache saw it is the thing
needed to diagnose the next occurrence.

Two alternatives were considered. Dropping the ptxas half of #2722 outright is a
smaller diff, but it leaves cicc's search unconditional on older CUDA (the same
pattern, one compiler over) and gives ptxas no fallback if NVIDIA later shifts
its input off the offset the way it did for cicc. Disabling sccache on 13.3+
avoids the parser entirely but gives up CUDA caching, which is the point of
having sccache at all.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo -- this caused the revert. Drop the
redundant (and pin-diverging) rustup reinstall and just use the cargo already on
PATH.

Drop the from-source build and return to the prebuilt binary once a sccache
release including #2722 ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker), so the patch is not
compiled or unit-tested locally. It applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

Validate in a CUDA 13.3+ CI image (e.g. cuda13.4):

```
echo '__global__ void k() {}' > repro.cu
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm the CUDA 13.0/13.2 torchao build (which regressed on the ungated
backport) plus non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
Reland of #190927 (landed as 2a4b761, auto-reverted in dc90186), with
the cause of the revert fixed.

Two separate sccache 0.16.0 bugs break CUDA builds; this patches both
(patches/sccache-nvcc-13.3-dryrun-parsing.patch) and builds sccache from source
until a release carrying them ships.

First, nvcc 13.3+ injects a valueless --simt-only flag into the cudafe++ and
cicc sub-commands of `nvcc --dryrun`, right before -o. sccache locates the
sub-command input by a fixed offset from the end of the argument list, so the
extra token makes cicc mis-locate its input and skip the device compile; ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". mozilla/sccache#2722 fixes this by locating the input by
its generated-file suffix (.cpp1.ii for cicc, .ptx for ptxas) instead.

That fix is taken with one deviation: the suffix search runs only when the
argument at the historical offset is not itself a generated input file. Of the
three sub-commands sccache parses this way, only cicc is affected -- cudafe++
takes the input as its last argument (offset 1, unaffected by a flag inserted
before it) and ptxas never receives --simt-only at all, so its offset was
already correct. Gating keeps every command line nvcc still emits in the old
shape parsing exactly as stock 0.16.0 does, with identical cache keys, while
13.3+ still gets the fix on the one sub-command that needs it.

Second, and this is what the autorevert caught: for a virtual-only gencode such
as -gencode arch=compute_120,code=compute_120, nvcc runs ptxas as a PTX
verification pass with no -o at all --

  ptxas -arch=compute_120 -m64 kernel.compute_120.ptx

It syntax-checks the PTX and emits nothing. sccache unconditionally requires an
"obj" output, which only -o populates, so it fails the whole compile with
`Missing "cubin" file output`. This is not a regression from #2722: stock
0.16.0 fails identically here, since with a three-argument list the offset picks
-arch=compute_120 as the input and there is still no -o to find. Any target
carrying a +PTX architecture can hit it; here it was torchao's mxfp8 extension,
built as a dependency of inductor-build-cuda132. A verification pass has no
artifact to cache, so treat the missing output as CannotCache and let the
command run directly rather than failing the build.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. That instrumentation is what identified the second bug -- the
error alone said only that an output was absent, not that the command never had
one -- and nvcc reshapes these sub-commands between CUDA releases, so the
argument vector as sccache saw it is worth keeping in the message.

Build from source for all image types (riscv64 keeps the prebuilt binary: no
nvcc, no sccache-dist, and a from-source build under QEMU emulation would be
impractically slow) so the whole fleet shares a single sccache binary.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo. Drop the redundant (and pin-diverging)
rustup reinstall and just use the cargo already on PATH.

Disabling sccache for the affected CUDA versions was considered and rejected: it
gives up CUDA build caching, which is the reason to run sccache at all.

Drop the from-source build and return to the prebuilt binary once a sccache
release including these fixes ships. See #190832.

Test Plan:
Not buildable on the author's machine (no cargo/docker), so the patch is not
compiled or unit-tested locally. It applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

Validate in CI. The torchao mxfp8 extension built by inductor-build-cuda132 is
the direct regression test for the second fix, since it carries a
code=compute_120 gencode. For the first, in a CUDA 13.3+ image:

```
echo '__global__ void k() {}' > repro.cu
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm non-CUDA / ROCm / XPU images still build and cache normally. Worth
watching sccache hit rates on CUDA jobs afterwards: CannotCache on the
verification pass may suppress caching more of an nvcc invocation than that one
sub-command.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
tinglvv added a commit that referenced this pull request Aug 4, 2026
Reland of #190927 (landed as 2a4b761, auto-reverted in dc90186), with
the cause of the revert fixed.

Two separate sccache 0.16.0 bugs break CUDA builds; this patches both
(patches/sccache-nvcc-13.3-dryrun-parsing.patch) and builds sccache from source
until a release carrying them ships.

First, nvcc 13.3+ injects a valueless --simt-only flag into the cudafe++ and
cicc sub-commands of `nvcc --dryrun`, right before -o. sccache locates the
sub-command input by a fixed offset from the end of the argument list, so the
extra token makes cicc mis-locate its input and skip the device compile; ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". mozilla/sccache#2722 fixes this by locating the input by
its generated-file suffix (.cpp1.ii for cicc, .ptx for ptxas) instead.

That fix is taken with one deviation: the suffix search runs only when the
argument at the historical offset is not itself a generated input file. Of the
three sub-commands sccache parses this way, only cicc is affected -- cudafe++
takes the input as its last argument (offset 1, unaffected by a flag inserted
before it) and ptxas never receives --simt-only at all, so its offset was
already correct. Gating keeps every command line nvcc still emits in the old
shape parsing exactly as stock 0.16.0 does, with identical cache keys, while
13.3+ still gets the fix on the one sub-command that needs it.

Second, and this is what the autorevert caught: for a virtual-only gencode such
as -gencode arch=compute_120,code=compute_120, nvcc runs ptxas as a PTX
verification pass with no -o at all --

  ptxas -arch=compute_120 -m64 kernel.compute_120.ptx

It syntax-checks the PTX and emits nothing. sccache marks every ptxas
sub-command Cacheable::Yes, and the caching path requires an "obj" output that
only -o populates, so the whole compile fails with `Missing "cubin" file
output`. This is not a regression from #2722: stock 0.16.0 fails identically
here, since with a three-argument list the offset picks -arch=compute_120 as the
input and there is still no -o to find. Any target carrying a +PTX architecture
can hit it; here it was torchao's mxfp8 extension, built as a dependency of
inductor-build-cuda132.

Mark that sub-command Cacheable::No instead, which routes it to the path nvcc.rs
already uses for non-cacheable sub-commands: build the command and run it. The
first attempt at this returned CompilerArguments::CannotCache from
cicc::parse_arguments, but the nvcc sub-command dispatch converts CannotCache
into an error rather than falling back to running the command, so it only moved
the failure ("Cannot cache(no output file)"). Deciding at the grouping stage
avoids that path entirely; Cacheable::No with a group is already how the host
preprocessor steps are handled.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. That instrumentation is what identified the second bug -- the
error alone said only that an output was absent, not that the command never had
one -- and nvcc reshapes these sub-commands between CUDA releases, so the
argument vector as sccache saw it is worth keeping in the message.

Build from source for all image types (riscv64 keeps the prebuilt binary: no
nvcc, no sccache-dist, and a from-source build under QEMU emulation would be
impractically slow) so the whole fleet shares a single sccache binary.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo. Drop the redundant (and pin-diverging)
rustup reinstall and just use the cargo already on PATH.

Disabling sccache for the affected CUDA versions was considered and rejected: it
gives up CUDA build caching, which is the reason to run sccache at all.

Drop the from-source build and return to the prebuilt binary once a sccache
release including these fixes ships. See #190832.

Test Plan:
The patch applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

The second bug reproduces without PyTorch or torchao, on any CUDA install, from
the virtual-only gencode alone:

```
echo '__global__ void k() {}' > repro.cu
cargo build --manifest-path /tmp/sccache/Cargo.toml --release
/tmp/sccache/target/release/sccache nvcc -gencode=arch=compute_100,code=sm_100 \
    -gencode=arch=compute_120,code=compute_120 -c repro.cu -o repro.o
```

In CI, the torchao mxfp8 extension built by inductor-build-cuda132 is the direct
regression test. For the first bug, in a CUDA 13.3+ image:

```
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 5, 2026
Reland of #190927 (landed as 2a4b761, auto-reverted in dc90186), with
the cause of the revert fixed.

Two separate sccache 0.16.0 bugs break CUDA builds; this patches both
(patches/sccache-nvcc-13.3-dryrun-parsing.patch) and builds sccache from source
until a release carrying them ships.

First, nvcc 13.3+ injects a valueless --simt-only flag into the cudafe++ and
cicc sub-commands of `nvcc --dryrun`, right before -o. sccache locates the
sub-command input by a fixed offset from the end of the argument list, so the
extra token makes cicc mis-locate its input and skip the device compile; ptxas
then produces no .cubin and the build dies with "fatbinary fatal: Could not open
input file '*.cubin'". mozilla/sccache#2722 fixes this by locating the input by
its generated-file suffix (.cpp1.ii for cicc, .ptx for ptxas) instead.

That fix is taken with one deviation: the suffix search runs only when the
argument at the historical offset is not itself a generated input file. Of the
three sub-commands sccache parses this way, only cicc is affected -- cudafe++
takes the input as its last argument (offset 1, unaffected by a flag inserted
before it) and ptxas never receives --simt-only at all, so its offset was
already correct. Gating keeps every command line nvcc still emits in the old
shape parsing exactly as stock 0.16.0 does, with identical cache keys, while
13.3+ still gets the fix on the one sub-command that needs it.

Second, and this is what the autorevert caught: for a virtual-only gencode such
as -gencode arch=compute_120,code=compute_120, nvcc runs ptxas as a PTX
verification pass with no -o at all --

  ptxas -arch=compute_120 -m64 kernel.compute_120.ptx

It syntax-checks the PTX and emits nothing. sccache marks every ptxas
sub-command Cacheable::Yes, and the caching path requires an "obj" output that
only -o populates, so the whole compile fails with `Missing "cubin" file
output`. This is not a regression from #2722: stock 0.16.0 fails identically
here, since with a three-argument list the offset picks -arch=compute_120 as the
input and there is still no -o to find. Any target carrying a +PTX architecture
can hit it; here it was torchao's mxfp8 extension, built as a dependency of
inductor-build-cuda132.

Mark that sub-command Cacheable::No instead, which routes it to the path nvcc.rs
already uses for non-cacheable sub-commands: build the command and run it. The
first attempt at this returned CompilerArguments::CannotCache from
cicc::parse_arguments, but the nvcc sub-command dispatch converts CannotCache
into an error rather than falling back to running the command, so it only moved
the failure ("Cannot cache(no output file)"). Deciding at the grouping stage
avoids that path entirely; Cacheable::No with a group is already how the host
preprocessor steps are handled.

The "Missing <lang> file output" error now also reports the parsed input and
argument lists. That instrumentation is what identified the second bug -- the
error alone said only that an output was absent, not that the command never had
one -- and nvcc reshapes these sub-commands between CUDA releases, so the
argument vector as sccache saw it is worth keeping in the message.

Build from source for all image types (riscv64 keeps the prebuilt binary: no
nvcc, no sccache-dist, and a from-source build under QEMU emulation would be
impractically slow) so the whole fleet shares a single sccache binary.

Build with the pre-installed rust toolchain rather than reinstalling rustup.
Since #186302 the builder images pre-install a pinned rust (1.97.1) at
CARGO_HOME=/opt/rust with /opt/rust/bin on PATH. The first landing ran
`curl rustup | sh` then `. "$HOME/.cargo/env"`, but with CARGO_HOME=/opt/rust
that env file is /opt/rust/env, so the source failed and every from-source image
died at that line before reaching cargo. Drop the redundant (and pin-diverging)
rustup reinstall and just use the cargo already on PATH.

Disabling sccache for the affected CUDA versions was considered and rejected: it
gives up CUDA build caching, which is the reason to run sccache at all.

Drop the from-source build and return to the prebuilt binary once a sccache
release including these fixes ships. See #190832.

Test Plan:
The patch applies cleanly to a pristine v0.16.0:

```
git clone --depth 1 --branch v0.16.0 https://github.com/mozilla/sccache /tmp/sccache
git -C /tmp/sccache apply --check .ci/docker/common/patches/sccache-nvcc-13.3-dryrun-parsing.patch
```

The second bug reproduces without PyTorch or torchao, on any CUDA install, from
the virtual-only gencode alone:

```
echo '__global__ void k() {}' > repro.cu
cargo build --manifest-path /tmp/sccache/Cargo.toml --release
/tmp/sccache/target/release/sccache nvcc -gencode=arch=compute_100,code=sm_100 \
    -gencode=arch=compute_120,code=compute_120 -c repro.cu -o repro.o
```

In CI, the torchao mxfp8 extension built by inductor-build-cuda132 is the direct
regression test. For the first bug, in a CUDA 13.3+ image:

```
sccache nvcc -rdc=true -gencode arch=compute_75,code=sm_75 -c repro.cu -o repro.o  # succeeds, no fatbinary error
```

and confirm non-CUDA / ROCm / XPU images still build and cache normally.

Authored with assistance from Claude.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Aug 7, 2026
…arn (#192522)

Follow-up to #191508.

## What #191508 added, and what changes here

It added two gates for docker-affecting PRs, both in `merge_into` so force merges
cannot bypass them:

1. **`check_docker_builds_ready`** — the PR's own `ciflow/docker` builds must have
   run and passed. **Unchanged by this PR.** Pending builds still raise
   `MandatoryChecksMissingError` so a normal merge waits; missing/failed builds are
   still refused.
2. **`check_no_docker_merge_skew`** — additionally required the `.ci/docker` tree of
   the *merge commit* to equal the tree `ciflow/docker` built on the PR head, and
   refused the merge otherwise. **This PR downgrades it to a warning.**

So the "all the builds are green" requirement is fully retained; what goes away is
the extra requirement that the base branch not have moved.

## Why

Requiring the two trees to match means a docker PR has to win a race against the
base branch, and a rebase only helps until the next docker-affecting PR lands. On
a busy day a PR can bounce indefinitely. #190639 hit it twice in a row — the
PR-head tree moved (`08b9699a` → `75ce86e4`) after a rebase while the merge-commit
tree stayed `ab961773`:

```
Refusing to merge: this PR modifies the CI docker images, but the .ci/docker tree
of the merge commit (ab96177...) does not match the tree that ciflow/docker built
and tested on the PR head (75ce86e...)
```

**A missing post-merge image is not fatal**, which is the key point:

- `docker-builds.yml` triggers on `push` to `main` / `release/*`, so the merged
  tree's images get built and pushed right after the merge lands.
- test-infra's `calculate-docker-image` polls for the image before giving up —
  `docker manifest inspect` in a loop, `sleep 300` per iteration, up to 120
  minutes for non-docker-build jobs — and then falls through to `rebuild=true`
  and builds it locally.

So a skew costs **time** on the first trunk jobs after the merge (waiting for
docker-builds, or a local rebuild with longer TTS), not a hard failure. Trading
that against docker PRs being unable to land seems like the better default.

## Kept: the diagnostic

The mismatch is still printed to the merge job log, so a slow or rebuilding trunk
job can be correlated with the land race that caused it:

```
WARNING: docker land race on PR #NNNNN: the .ci/docker tree of the merge commit
(...) does not match the tree that ciflow/docker built and tested on the PR head
(...). ... the first trunk jobs after this merge may wait for docker-builds to
publish the merged tree's images, or rebuild them locally. Merging anyway.
```

Renamed `check_no_docker_merge_skew` → `warn_on_docker_merge_skew` so the name
matches the behaviour.

## Test plan

- `python -m pytest .github/scripts/test_trymerge.py` → **74 passed, 2 skipped**
  (the 4 docker-gate tests included; none referenced the renamed function).
- `py_compile` clean; no remaining references to the old name
  (`grep -rn check_no_docker_merge_skew .github/` → empty).
- `MergeRuleFailedError` is still used in 7 other places, so the import is not
  orphaned.

## Trade-off, stated plainly

This intentionally reopens the window that #191508 closed: a docker PR can now
land whose post-merge images were never built or tested, which is the shape of the
#190927 / #186302 land race cited in that PR. The mitigation is that the images
are auto-published by `docker-builds.yml` on the merge and that jobs wait for
them, so the failure mode is latency rather than red trunk. If dev-infra would
rather keep a hard gate, an alternative is to keep refusing only when
`check_docker_builds_ready` did **not** pass, i.e. exactly the unbuilt-image case,
and always allow the pure-skew case — happy to switch to that.

Pull Request resolved: #192522
Approved by: https://github.com/tinglvv, https://github.com/izaitsevfb, https://github.com/ezyang
ankitbhrdwj pushed a commit to ankitbhrdwj/pytorch that referenced this pull request Aug 12, 2026
…arn (pytorch#192522)

Follow-up to pytorch#191508.

## What pytorch#191508 added, and what changes here

It added two gates for docker-affecting PRs, both in `merge_into` so force merges
cannot bypass them:

1. **`check_docker_builds_ready`** — the PR's own `ciflow/docker` builds must have
   run and passed. **Unchanged by this PR.** Pending builds still raise
   `MandatoryChecksMissingError` so a normal merge waits; missing/failed builds are
   still refused.
2. **`check_no_docker_merge_skew`** — additionally required the `.ci/docker` tree of
   the *merge commit* to equal the tree `ciflow/docker` built on the PR head, and
   refused the merge otherwise. **This PR downgrades it to a warning.**

So the "all the builds are green" requirement is fully retained; what goes away is
the extra requirement that the base branch not have moved.

## Why

Requiring the two trees to match means a docker PR has to win a race against the
base branch, and a rebase only helps until the next docker-affecting PR lands. On
a busy day a PR can bounce indefinitely. pytorch#190639 hit it twice in a row — the
PR-head tree moved (`08b9699a` → `75ce86e4`) after a rebase while the merge-commit
tree stayed `ab961773`:

```
Refusing to merge: this PR modifies the CI docker images, but the .ci/docker tree
of the merge commit (ab96177...) does not match the tree that ciflow/docker built
and tested on the PR head (75ce86e...)
```

**A missing post-merge image is not fatal**, which is the key point:

- `docker-builds.yml` triggers on `push` to `main` / `release/*`, so the merged
  tree's images get built and pushed right after the merge lands.
- test-infra's `calculate-docker-image` polls for the image before giving up —
  `docker manifest inspect` in a loop, `sleep 300` per iteration, up to 120
  minutes for non-docker-build jobs — and then falls through to `rebuild=true`
  and builds it locally.

So a skew costs **time** on the first trunk jobs after the merge (waiting for
docker-builds, or a local rebuild with longer TTS), not a hard failure. Trading
that against docker PRs being unable to land seems like the better default.

## Kept: the diagnostic

The mismatch is still printed to the merge job log, so a slow or rebuilding trunk
job can be correlated with the land race that caused it:

```
WARNING: docker land race on PR #NNNNN: the .ci/docker tree of the merge commit
(...) does not match the tree that ciflow/docker built and tested on the PR head
(...). ... the first trunk jobs after this merge may wait for docker-builds to
publish the merged tree's images, or rebuild them locally. Merging anyway.
```

Renamed `check_no_docker_merge_skew` → `warn_on_docker_merge_skew` so the name
matches the behaviour.

## Test plan

- `python -m pytest .github/scripts/test_trymerge.py` → **74 passed, 2 skipped**
  (the 4 docker-gate tests included; none referenced the renamed function).
- `py_compile` clean; no remaining references to the old name
  (`grep -rn check_no_docker_merge_skew .github/` → empty).
- `MergeRuleFailedError` is still used in 7 other places, so the import is not
  orphaned.

## Trade-off, stated plainly

This intentionally reopens the window that pytorch#191508 closed: a docker PR can now
land whose post-merge images were never built or tested, which is the shape of the
pytorch#190927 / pytorch#186302 land race cited in that PR. The mitigation is that the images
are auto-published by `docker-builds.yml` on the merge and that jobs wait for
them, so the failure mode is latency rather than red trunk. If dev-infra would
rather keep a hard gate, an alternative is to keep refusing only when
`check_docker_builds_ready` did **not** pass, i.e. exactly the unbuilt-image case,
and always allow the pure-skew case — happy to switch to that.

Pull Request resolved: pytorch#192522
Approved by: https://github.com/tinglvv, https://github.com/izaitsevfb, https://github.com/ezyang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/docker ciflow/inductor ciflow/mps Run MPS tests (subset of trunk) ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged meta-exported topic: not user facing topic category

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants