Skip to content

Commit 4c69250

Browse files
committed
Remove torchaudio _check_cuda_version() call when repackaging cu130->cu132
torchaudio is now built against the PyTorch stable C++ ABI, so the runtime _check_cuda_version() guard in torchaudio/_extension/__init__.py is no longer needed and would otherwise fail on cross-CUDA-version installs (e.g. a cu132-tagged torchaudio wheel running against torch built for a different CUDA minor version). Extends release/repackage_torchaudio_cu130_to_cu132.py to also strip the _check_cuda_version() call from torchaudio/_extension/__init__.py inside each wheel during the same auditwheel InWheelCtx pass that rewrites the +cu130 -> +cu132 local-version label, so the regenerated RECORD covers both edits. The function definition in utils.py is left intact so external callers (e.g. the pytorch/builder smoke test) keep working.
1 parent 35633f8 commit 4c69250

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

release/repackage_torchaudio_cu130_to_cu132.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
3. Rewrites the wheel local-version label from ``+cu130`` to ``+cu132``
1010
(METADATA ``Version:`` field, ``.dist-info`` directory name, and the
1111
wheel filename). The RECORD file is regenerated by auditwheel.
12-
4. Uploads each repackaged wheel to:
12+
4. Removes the ``_check_cuda_version()`` runtime guard from
13+
``torchaudio/_extension/__init__.py`` inside the wheel. torchaudio is
14+
now built against the PyTorch stable C++ ABI, so the strict CUDA
15+
version match is no longer required and would otherwise fail when a
16+
cu132-tagged torchaudio wheel runs alongside a torch built for a
17+
different CUDA minor version. The function definition in ``utils.py``
18+
is preserved so external callers (e.g. the pytorch/builder smoke
19+
test) keep working.
20+
5. Uploads each repackaged wheel to:
1321
- AWS S3: s3://pytorch/whl/test/cu132/
1422
- Cloudflare R2: s3://pytorch-downloads/whl/test/cu132/
1523
Each upload sets ``x-amz-meta-checksum-sha256`` on the object so the
@@ -56,6 +64,9 @@
5664
R2_BUCKET_NAME_DEFAULT = "pytorch-downloads"
5765
R2_PREFIX = "whl/test/{cuda}"
5866

67+
EXTENSION_INIT_PATH = "torchaudio/_extension/__init__.py"
68+
CHECK_CUDA_CALL_RE = re.compile(r"^[ \t]*_check_cuda_version\(\)[ \t]*\n", re.MULTILINE)
69+
5970

6071
def discover_wheels(package: str, version: str, cuda: str) -> List[str]:
6172
"""Return list of wheel filenames for ``package`` at ``version`` on the
@@ -177,6 +188,37 @@ def repackage_wheel(
177188
os.path.join(ctx.path, new_dist_info_dir),
178189
)
179190

191+
# torchaudio is now built against the PyTorch stable C++ ABI,
192+
# so the runtime _check_cuda_version() guard in
193+
# torchaudio/_extension/__init__.py is no longer needed and
194+
# would otherwise fail on cross-CUDA-version installs (e.g. a
195+
# torchaudio cu132 wheel running against torch built for a
196+
# different CUDA minor). Strip the call here; the function
197+
# definition in utils.py is left intact for callers like the
198+
# builder smoke test.
199+
init_file = os.path.join(ctx.path, EXTENSION_INIT_PATH)
200+
if not os.path.exists(init_file):
201+
raise RuntimeError(f"{EXTENSION_INIT_PATH} not found in {wheel_path}")
202+
with open(init_file, "r", encoding="utf-8") as f:
203+
init_src = f.read()
204+
patched_src, count = CHECK_CUDA_CALL_RE.subn("", init_src)
205+
if count == 0:
206+
raise RuntimeError(
207+
f"No _check_cuda_version() call found in "
208+
f"{EXTENSION_INIT_PATH} of {wheel_path.name}"
209+
)
210+
if count > 1:
211+
print(
212+
f"- WARNING: removed {count} _check_cuda_version() "
213+
f"calls from {wheel_path.name} (expected 1)"
214+
)
215+
with open(init_file, "w", encoding="utf-8") as f:
216+
f.write(patched_src)
217+
print(
218+
f"+ Removed _check_cuda_version() call from "
219+
f"{EXTENSION_INIT_PATH} ({wheel_path.name})"
220+
)
221+
180222
new_filename = wheel_path.name.replace(old_label, new_label)
181223
out_path = output_dir / new_filename
182224
if not tmp_whl.exists():

0 commit comments

Comments
 (0)