Skip to content

Commit cf30153

Browse files
authored
[release/2.13] Strip +PTX from CUDA arch list on release/RC builds (#188914) (#188925)
Strip +PTX from CUDA arch list on release/RC builds (in build_env_setup.py) (#188914) ## Summary Restore the pre-2.13 behavior where **release/RC** CUDA wheels ship **without `+PTX`**, while nightlies keep it for forward-compat. ### Background `libtorch_cuda.so` grew ~80-90 MB from 2.12.1 to 2.13.0 (cu130): 2.13 started emitting `12.0+PTX` (sm_120 PTX) in the release wheels. The SASS arch set is unchanged; the growth is the embedded compute_120 PTX. The branch-cut script `scripts/release/apply-release-changes.sh` was *supposed* to strip `+PTX` for releases, but it edited `.ci/manywheel/build_cuda.sh` — which was refactored into `.ci/manywheel/build_env_setup.py`. The `sed` silently became a no-op, so 2.13.0 shipped with `+PTX`. ### Fix Detect release/RC builds in Python instead of relying on a branch-cut `sed`: - `build_env_setup.py`: add `_is_release_build()` (true when `PYTORCH_BUILD_VERSION` is set and has no `.dev` suffix — i.e. tagged release/RC builds, per `binary_populate_env.sh`) and `_ptx_arches()`; emit `+PTX` only for nightly/dev builds. - `apply-release-changes.sh`: drop the now-redundant/broken `+PTX` `sed`. ### Behavior (cuda 13.0, x86_64) | Build | `PYTORCH_BUILD_VERSION` | arch list | |---|---|---| | nightly | `2.13.0.dev...+cu130` | `7.5;8.0;8.6;9.0;10.0;12.0+PTX` | | RC / release | `2.13.0+cu130` | `7.5;8.0;8.6;9.0;10.0;12.0` | | local / unset | `''` | `...;12.0+PTX` (safe default) | This is drift-proof: the logic lives next to the arch table it depends on, keyed off a signal the repo already uses. *Authored with AI assistance.* Pull Request resolved: #188914 Approved by: https://github.com/zxiiro, https://github.com/huydhn (cherry picked from commit 089472d)
1 parent 3e3e24b commit cf30153

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎.ci/manywheel/build_env_setup.py‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,35 @@
8888
},
8989
}
9090

91-
# Architectures we additionally emit PTX for (forward-compat for newer GPUs).
91+
# Architectures we additionally emit PTX for on nightly/dev builds
92+
# (forward-compat for newer GPUs). Release/RC wheels ship SASS-only to keep
93+
# libtorch_cuda.so size down; see _ptx_arches().
9294
_PTX_ARCHES: set[int] = {120}
9395

9496

97+
def _is_release_build() -> bool:
98+
"""True for release / RC binary builds (vs nightly / dev builds).
99+
100+
Binary builds off a git tag (releases and RCs, e.g. v2.13.0 / v2.13.0-rc1)
101+
get a ``PYTORCH_BUILD_VERSION`` with no ``.dev<date>`` suffix, while
102+
nightlies do -- see .ci/pytorch/binary_populate_env.sh, which relies on the
103+
same ``dev`` check for Triton pinning. A missing/empty version (local or
104+
non-binary builds) is treated as non-release, so PTX is kept.
105+
"""
106+
version = os.environ.get("PYTORCH_BUILD_VERSION", "")
107+
return bool(version) and "dev" not in version
108+
109+
110+
def _ptx_arches() -> set[int]:
111+
"""PTX arches for this build: empty on release/RC, forward-compat set otherwise."""
112+
return set() if _is_release_build() else _PTX_ARCHES
113+
114+
95115
def torch_cuda_arch_list(cuda_version: str, arch: str) -> str:
96116
"""Format TORCH_CUDA_ARCH_LIST for the wheel build (";"-separated).
97117
98-
Returns e.g. "8.0;9.0;10.0;11.0;12.0+PTX" for cuda 13.x aarch64.
118+
Returns e.g. "8.0;9.0;10.0;11.0;12.0+PTX" for cuda 13.x aarch64 on
119+
nightly builds; release/RC builds omit the +PTX suffix (see _ptx_arches()).
99120
100121
CUDA 13.x dropped sm_50/60/70, so we must NOT leave this empty --
101122
CMake's defaults still include compute_50 which nvcc 13 rejects with
@@ -106,8 +127,9 @@ def torch_cuda_arch_list(cuda_version: str, arch: str) -> str:
106127
archs = TORCH_CUDA_ARCH_LIST_TABLE[cuda_version].get(arch)
107128
if not archs:
108129
raise SystemExit(f"no TORCH_CUDA_ARCH_LIST for cuda {cuda_version} on {arch}")
130+
ptx_arches = _ptx_arches()
109131
return ";".join(
110-
f"{cc // 10}.{cc % 10}" + ("+PTX" if cc in _PTX_ARCHES else "")
132+
f"{cc // 10}.{cc % 10}" + ("+PTX" if cc in ptx_arches else "")
111133
for cc in sorted(archs)
112134
)
113135

‎scripts/release/apply-release-changes.sh‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ echo "XLA Changes"
4444
sed -i -e s#--quiet#-b\ r"${RELEASE_VERSION}"# .ci/pytorch/common_utils.sh
4545
sed -i -e s#.*#r"${RELEASE_VERSION}"# .github/ci_commit_pins/xla.txt
4646

47-
# Strip +PTX from CUDA arch lists in release builds
48-
echo "Stripping +PTX from CUDA arch lists"
49-
sed -i 's/+PTX//' .ci/manywheel/build_cuda.sh
50-
5147
# Regenerate templates
5248
export RELEASE_VERSION_TAG=${RELEASE_VERSION}
5349
./.github/regenerate.sh

0 commit comments

Comments
 (0)