Repository navigation
Let PyTorch choose the C++ standard when building ops - #341
Merged
Merged
Conversation
torch.utils.cpp_extension compiles extensions with -std=c++20 since PyTorch 2.12, but the op builder appended -std=c++17 to the host C++ flags and to the ROCm hipcc flags. The later flag wins, so every op was compiled as C++17. PyTorch 2.14 headers require C++20 (ATen.h raises "C++20 or later compatible compiler is required", and c10 uses std::strong_ordering and requires-clauses), so every op fails to build, both when JIT-built on first use and when prebuilt with APEX_BUILD_*=1. Remove every hard-coded -std flag from the op builder: from cxx_args(), from the ROCm branch of nvcc_args(), and the CUDA-version-based selection in the CUDA branch. torch.utils.cpp_extension adds the standard that matches the installed PyTorch headers whenever no -std flag is passed, on both the JIT and setup.py paths. This follows NVIDIA#2006, which made the same change upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leconcio
force-pushed
the
cxx20-for-pytorch-2.14
branch
from
October 16, 2026 20:08
f4e5605 to
8837f88
Compare
Collaborator
|
! cherry-pick --onto release/1.14.0,release/1.15.0 |
|
Target branch Comment processed by Build |
Collaborator
|
! cherry-pick --onto release/1.14.0 release/1.15.0 |
This was referenced Oct 19, 2026
|
Created branch autogenerated/release/1.14.0_cherry-pick_pr-341 and #342 Created branch autogenerated/release/1.15.0_cherry-pick_pr-341 and #343 Comment processed by Build |
leconcio
added a commit
to ROCm/pytorch
that referenced
this pull request
Oct 21, 2026
Move ROCm/apex release/1.14.0 from a7f8fded to 172d2689, the release/1.14.0 backport of ROCm/apex#341, which lets PyTorch choose the C++ standard when building apex ops (PyTorch 2.14+ requires C++20). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leconcio
added a commit
to ROCm/pytorch
that referenced
this pull request
Oct 21, 2026
Move ROCm/apex release/1.15.0 from 3310832c to 11867be7, the release/1.15.0 backport of ROCm/apex#341, which lets PyTorch choose the C++ standard when building apex ops (PyTorch 2.14+ requires C++20). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 21, 2026
jithunnair-amd
pushed a commit
to ROCm/pytorch
that referenced
this pull request
Oct 24, 2026
## Summary - Update the apex pin in `related_commits` for the 2.14 release. - Move `ROCm/apex` `release/1.14.0` from `a7f8fded` to `172d2689`, the `release/1.14.0` backport of [ROCm/apex#341](ROCm/apex#341). It is the only commit between the two. - ROCm/apex#341 removes the hard-coded `-std=c++17` from apex's `op_builder/builder.py`, so PyTorch's `cpp_extension` picks the C++ standard. PyTorch 2.14+ headers require C++20, so with the old pin the apex ops (`amp_C`, `fused_layer_norm_cuda`, ...) fail to build, both when prebuilt and when JIT-compiled on first use. - The torchvision and torchaudio pins in `related_commits` are unchanged. Apex release commit: 172d26895969173213b2b4c206ed074103efe602 ## Test plan - [x] Validate the PyTorch build through the Linux and Windows build CI jobs: https://github.com/ROCm/TheRock/actions/runs/39976925637 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
jithunnair-amd
pushed a commit
to ROCm/pytorch
that referenced
this pull request
Oct 24, 2026
## Summary - Update the apex pin in `related_commits` for the 2.15 release. - Move `ROCm/apex` `release/1.15.0` from `3310832c` to `11867be7`, the `release/1.15.0` backport of [ROCm/apex#341](ROCm/apex#341). It is the only commit between the two. - ROCm/apex#341 removes the hard-coded `-std=c++17` from apex's `op_builder/builder.py`, so PyTorch's `cpp_extension` picks the C++ standard. PyTorch 2.14+ headers require C++20, so with the old pin the apex ops (`amp_C`, `fused_layer_norm_cuda`, ...) fail to build, both when prebuilt and when JIT-compiled on first use. - The torchvision and torchaudio pins in `related_commits` are unchanged. Apex release commit: 11867be79cb16fe53bd8b1b898ea38b7508721ff ## Test plan - [x] Validate the PyTorch build through the Linux and Windows build CI jobs: https://github.com/ROCm/TheRock/actions/runs/40002541100 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PyTorch 2.14 is now an official ROCm Docker release for ROCm 10.1 and above, and on it apex ops fail to build, whether they are JIT-built on first use or prebuilt with
APEX_BUILD_*=1.torch.utils.cpp_extensioncompiles extensions with-std=c++20since PyTorch 2.12, butCUDAOpBuilderappends-std=c++17to the host C++ flags (cxx_args()) and to the ROCm hipcc flags (nvcc_args()). The later flag wins, so every op is compiled as C++17. That still worked on 2.12 and 2.13, whose headers accept C++17, but the PyTorch 2.14 headers require C++20:How
Remove every hard-coded
-stdflag fromCUDAOpBuilder, and lettorch.utils.cpp_extensionchoose the standard that matches the installed PyTorch headers:cxx_args(): drop-std=c++17.nvcc_args(): drop-std=c++17.nvcc_args(): drop the CUDA-version-based selection (c++20on CUDA 12.5+,c++17on CUDA 11 to 12.4,c++14on older).torch.utils.cpp_extensionadds its own-stdwhenever none is passed, on both the JIT path and thesetup.pypath. This is the approach upstream apex took in NVIDIA#2006, and apex no longer needs updating each time PyTorch raises its required standard.After this change apex sets no
-stdanywhere. Builders that overridecxx_args()ornvcc_args()without callingsuper()(bnp, and the hipcc flags ofamp_C,fused_adam,syncbn, ...) already passed none.Testing
All runs on MI300X (gfx942) with ROCm images, comparing
master(2dfd342) with this branch.masterAPEX_BUILD_CPP_OPS=1 APEX_BUILD_CUDA_OPS=1 python setup.py build_ext-std=c++20pip install ., thenjit_load()on every builderbnp, which passes no-std, builds)build.ninjafiles contain only-std=c++20amp_C.multi_tensor_l2normon a 1024-element tensor of ones, PyTorch 2.14L0 tests on PyTorch 2.14 with this branch (JIT install,
APEX_TEST_WITH_ROCM=1 APEX_SKIP_FLAKY_TEST=1):run_amprun_fp16utilrun_optimizersrun_fused_layer_normrun_mlprun_fused_denserun_transformerImage:
rocm/frameworks-internal:rocm10.2.0a20261008_ubuntu24.04_py3.12_pytorch_2.14.0_5d7f2f0(torch2.14.0+rocm10.2.0a20261008, HIP 7.17).Not tested: CUDA builds. On CUDA 12.0 to 12.4 this changes the standard from
c++17to whatever the installed PyTorch defaults to.🤖 Generated with Claude Code
Cherry-picked to release/1.14.0 branch via #342
Cherry-picked to release/1.15.0 branch via #343