-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Expand file tree
/
Copy pathgenerate_binary_build_matrix.py
More file actions
518 lines (452 loc) · 18.6 KB
/
generate_binary_build_matrix.py
File metadata and controls
518 lines (452 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#!/usr/bin/env python3
"""Generates a matrix to be utilized through github actions
Will output a condensed version of the matrix if on a pull request that only
includes the latest version of python we support built on three different
architectures:
* CPU
* Latest CUDA
* Latest ROCM
* Latest XPU
"""
from __future__ import annotations
import json
import os
import re
from pathlib import Path
SCRIPT_DIR = Path(__file__).absolute().parent
REPO_ROOT = SCRIPT_DIR.parent.parent
CUDA_ARCHES = ["12.6", "12.8", "13.0", "13.2"]
CUDA_STABLE = "13.0"
CUDA_ARCHES_FULL_VERSION = {
"12.6": "12.6.3",
"12.8": "12.8.1",
"13.0": "13.0.2",
"13.2": "13.2.0",
}
CUDA_ARCHES_CUDNN_VERSION = {
"12.6": "9",
"12.8": "9",
"13.0": "9",
"13.2": "9",
}
ROCM_ARCHES = ["7.1", "7.2"]
XPU_ARCHES = ["xpu"]
CPU_AARCH64_ARCH = ["cpu-aarch64"]
CPU_S390X_ARCH = ["cpu-s390x"]
CUDA_AARCH64_ARCHES = [
"12.6-aarch64",
"12.8-aarch64",
"13.0-aarch64",
"13.2-aarch64",
]
PYTORCH_EXTRA_INSTALL_REQUIREMENTS = {
"12.6": (
"cuda-toolkit[nvrtc,cudart,cupti,cufft,curand,cusolver,cusparse,cublas,cufile,nvjitlink,nvtx]==12.6.3; platform_system == 'Linux' | " # noqa: B950
"cuda-bindings>=12.9.4,<13; platform_system == 'Linux' | "
"nvidia-cudnn-cu12==9.10.2.21; platform_system == 'Linux' | "
"nvidia-cusparselt-cu12==0.7.1; platform_system == 'Linux' | "
"nvidia-nccl-cu12==2.29.3; platform_system == 'Linux' | "
"nvidia-nvshmem-cu12==3.4.5; platform_system == 'Linux'"
),
"12.8": (
"cuda-toolkit[nvrtc,cudart,cupti,cufft,curand,cusolver,cusparse,cublas,cufile,nvjitlink,nvtx]==12.8.1; platform_system == 'Linux' | " # noqa: B950
"cuda-bindings>=12.9.4,<13; platform_system == 'Linux' | "
"nvidia-cudnn-cu12==9.20.0.48; platform_system == 'Linux' | "
"nvidia-cusparselt-cu12==0.7.1; platform_system == 'Linux' | "
"nvidia-nccl-cu12==2.29.7; platform_system == 'Linux' | "
"nvidia-nvshmem-cu12==3.4.5; platform_system == 'Linux'"
),
"13.0": (
"cuda-toolkit[nvrtc,cudart,cupti,cufft,curand,cusolver,cusparse,cublas,cufile,nvjitlink,nvtx]==13.0.2; platform_system == 'Linux' | " # noqa: B950
"cuda-bindings>=13.0.3,<14; platform_system == 'Linux' | "
"nvidia-cudnn-cu13==9.20.0.48; platform_system == 'Linux' | "
"nvidia-cusparselt-cu13==0.8.1; platform_system == 'Linux' | "
"nvidia-nccl-cu13==2.29.7; platform_system == 'Linux' | "
"nvidia-nvshmem-cu13==3.4.5; platform_system == 'Linux'"
),
"13.2": (
"cuda-toolkit[nvrtc,cudart,cupti,cufft,curand,cusolver,cusparse,cublas,cufile,nvjitlink,nvtx]==13.2.0; platform_system == 'Linux' | " # noqa: B950
"cuda-bindings>=13.0.3,<14; platform_system == 'Linux' | "
"nvidia-cudnn-cu13==9.20.0.48; platform_system == 'Linux' | "
"nvidia-cusparselt-cu13==0.8.1; platform_system == 'Linux' | "
"nvidia-nccl-cu13==2.29.7; platform_system == 'Linux' | "
"nvidia-nvshmem-cu13==3.4.5; platform_system == 'Linux'"
),
"xpu": (
"intel-cmplr-lib-rt==2025.3.2 | "
"intel-cmplr-lib-ur==2025.3.2 | "
"intel-cmplr-lic-rt==2025.3.2 | "
"intel-sycl-rt==2025.3.2 | "
"oneccl-devel==2021.17.2; platform_system == 'Linux' and platform_machine == 'x86_64' | "
"oneccl==2021.17.2; platform_system == 'Linux' and platform_machine == 'x86_64' | "
"impi-rt==2021.17.2; platform_system == 'Linux' and platform_machine == 'x86_64' | "
"onemkl-license==2025.3.1 | "
"onemkl-sycl-blas==2025.3.1 | "
"onemkl-sycl-dft==2025.3.1 | "
"onemkl-sycl-lapack==2025.3.1 | "
"onemkl-sycl-rng==2025.3.1 | "
"onemkl-sycl-sparse==2025.3.1 | "
"dpcpp-cpp-rt==2025.3.2 | "
"intel-opencl-rt==2025.3.2 | "
"mkl==2025.3.1 | "
"intel-openmp==2025.3.2 | "
"tbb==2022.3.1 | "
"tcmlib==1.4.1 | "
"umf==1.0.3 | "
"intel-pti==0.16.0"
),
}
# Used by tools/nightly.py
PYTORCH_NIGHTLY_PIP_INDEX_URL = "https://download.pytorch.org/whl/nightly"
NIGHTLY_SOURCE_MATRIX = {
"cpu": dict(
name="cpu",
index_url=f"{PYTORCH_NIGHTLY_PIP_INDEX_URL}/cpu",
supported_platforms=["Linux", "macOS", "Windows"],
accelerator="cpu",
)
}
CUDA_NIGHTLY_SOURCE_MATRIX = {
f"cuda-{major}.{minor}": dict(
name=f"cuda-{major}.{minor}",
index_url=f"{PYTORCH_NIGHTLY_PIP_INDEX_URL}/cu{major}{minor}",
supported_platforms=["Linux", "Windows"],
accelerator="cuda",
)
for major, minor in (map(int, version.split(".")) for version in CUDA_ARCHES)
}
ROCM_NIGHTLY_SOURCE_MATRIX = {
f"rocm-{major}.{minor}": dict(
name=f"rocm-{major}.{minor}",
index_url=f"{PYTORCH_NIGHTLY_PIP_INDEX_URL}/rocm{major}.{minor}",
supported_platforms=["Linux"],
accelerator="rocm",
)
for major, minor in (map(int, version.split(".")) for version in ROCM_ARCHES)
}
XPU_NIGHTLY_SOURCE_MATRIX = {
"xpu": dict(
name="xpu",
index_url=f"{PYTORCH_NIGHTLY_PIP_INDEX_URL}/xpu",
supported_platforms=["Linux"],
accelerator="xpu",
)
}
NIGHTLY_SOURCE_MATRIX.update(CUDA_NIGHTLY_SOURCE_MATRIX)
NIGHTLY_SOURCE_MATRIX.update(ROCM_NIGHTLY_SOURCE_MATRIX)
NIGHTLY_SOURCE_MATRIX.update(XPU_NIGHTLY_SOURCE_MATRIX)
def get_nccl_wheel_version(arch_version: str) -> str:
requirements = map(
str.strip, re.split("[;|]", PYTORCH_EXTRA_INSTALL_REQUIREMENTS[arch_version])
)
return next(x for x in requirements if x.startswith("nvidia-nccl")).split("==")[1]
def read_nccl_pin(arch_version: str) -> str:
import sys
sys.path.append(str(REPO_ROOT / "tools"))
# Single source of truth for NCCL version
from optional_submodules import read_nccl_pin
return read_nccl_pin(arch_version)
def validate_nccl_dep_consistency(arch_version: str) -> None:
nccl_release_tag = read_nccl_pin(arch_version)
wheel_ver = get_nccl_wheel_version(arch_version)
if not nccl_release_tag.startswith(f"v{wheel_ver}"):
raise RuntimeError(
f"{arch_version} NCCL release tag version {nccl_release_tag} "
f"does not correspond to wheel version {wheel_ver}"
)
def _parse_linux_cudnn_versions() -> dict[str, str]:
"""Return {cuda_short_version: cudnn_version} from install_cuda.sh."""
text = (REPO_ROOT / ".ci" / "docker" / "common" / "install_cuda.sh").read_text()
results: dict[str, str] = {}
func_re = re.compile(r"^function install_(\d+)\s*\{")
cudnn_re = re.compile(r"^\s*CUDNN_VERSION=(\S+)")
current_func: str | None = None
for line in text.splitlines():
m = func_re.match(line)
if m:
digits = m.group(1)
current_func = digits[:-1] + "." + digits[-1]
continue
if current_func is not None:
m = cudnn_re.match(line)
if m:
results[current_func] = m.group(1)
current_func = None
return results
def _parse_windows_cudnn_versions() -> dict[str, str]:
"""Return {cuda_short_version: cudnn_version} from cuda_install.bat."""
text = (
REPO_ROOT / ".ci" / "pytorch" / "windows" / "internal" / "cuda_install.bat"
).read_text()
results: dict[str, str] = {}
label_re = re.compile(r"^:cuda(\d+)\s*$")
cudnn_re = re.compile(
r"^set CUDNN_FOLDER=cudnn-windows-x86_64-([0-9.]+)_cuda\d+-archive"
)
current_label: str | None = None
for line in text.splitlines():
m = label_re.match(line)
if m:
digits = m.group(1)
current_label = digits[:-1] + "." + digits[-1]
continue
if current_label is not None:
m = cudnn_re.match(line)
if m:
results[current_label] = m.group(1)
current_label = None
return results
def validate_cudnn_version_consistency(arch_version: str) -> None:
linux_versions = _parse_linux_cudnn_versions()
windows_versions = _parse_windows_cudnn_versions()
linux_ver = linux_versions.get(arch_version)
windows_ver = windows_versions.get(arch_version)
if linux_ver is None or windows_ver is None:
return
if linux_ver != windows_ver:
raise RuntimeError(
f"cuDNN version mismatch for CUDA {arch_version}: "
f"Linux has {linux_ver} (.ci/docker/common/install_cuda.sh) "
f"but Windows has {windows_ver} (.ci/pytorch/windows/internal/cuda_install.bat)"
)
def arch_type(arch_version: str) -> str:
if arch_version in CUDA_ARCHES:
return "cuda"
elif arch_version in ROCM_ARCHES:
return "rocm"
elif arch_version in XPU_ARCHES:
return "xpu"
elif arch_version in CPU_AARCH64_ARCH:
return "cpu-aarch64"
elif arch_version in CPU_S390X_ARCH:
return "cpu-s390x"
elif arch_version in CUDA_AARCH64_ARCHES:
return "cuda-aarch64"
else: # arch_version should always be "cpu" in this case
return "cpu"
DEFAULT_TAG = os.getenv("RELEASE_VERSION_TAG", "main")
WHEEL_CONTAINER_IMAGES = {
**{gpu_arch: f"manylinux2_28-builder:cuda{gpu_arch}" for gpu_arch in CUDA_ARCHES},
**{
gpu_arch: f"manylinuxaarch64-builder:cuda{gpu_arch.replace('-aarch64', '')}"
for gpu_arch in CUDA_AARCH64_ARCHES
},
**{gpu_arch: f"manylinux2_28-builder:rocm{gpu_arch}" for gpu_arch in ROCM_ARCHES},
"xpu": "manylinux2_28-builder:xpu",
"cpu": "manylinux2_28-builder:cpu",
"cpu-aarch64": "manylinux2_28_aarch64-builder:cpu-aarch64",
"cpu-s390x": "pytorch/manylinuxs390x-builder:cpu-s390x",
}
RELEASE = "release"
DEBUG = "debug"
FULL_PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13", "3.13t", "3.14", "3.14t"]
def translate_desired_cuda(gpu_arch_type: str, gpu_arch_version: str) -> str:
return {
"cpu": "cpu",
"cpu-aarch64": "cpu",
"cpu-s390x": "cpu",
"cuda": f"cu{gpu_arch_version.replace('.', '')}",
"cuda-aarch64": f"cu{gpu_arch_version.replace('-aarch64', '').replace('.', '')}",
"rocm": f"rocm{gpu_arch_version}",
"xpu": "xpu",
}.get(gpu_arch_type, gpu_arch_version)
def list_without(in_list: list[str], without: list[str]) -> list[str]:
return [item for item in in_list if item not in without]
def generate_libtorch_matrix(
os: str,
release_type: str,
arches: list[str] | None = None,
libtorch_variants: list[str] | None = None,
) -> list[dict[str, str]]:
if arches is None:
arches = ["cpu"]
if os == "windows":
arches += CUDA_ARCHES
if libtorch_variants is None:
libtorch_variants = [
"shared-with-deps",
"shared-without-deps",
"static-with-deps",
"static-without-deps",
]
ret: list[dict[str, str]] = []
for arch_version in arches:
for libtorch_variant in libtorch_variants:
gpu_arch_type = arch_type(arch_version)
gpu_arch_version = "" if arch_version == "cpu" else arch_version
ret.append(
{
"gpu_arch_type": gpu_arch_type,
"gpu_arch_version": gpu_arch_version,
"desired_cuda": translate_desired_cuda(
gpu_arch_type, gpu_arch_version
),
"libtorch_config": release_type,
"libtorch_variant": libtorch_variant,
"container_image": "",
"container_image_tag_prefix": "",
"package_type": "libtorch",
"build_name": f"libtorch-{gpu_arch_type}{gpu_arch_version}-{libtorch_variant}-{release_type}".replace(
".", "_"
),
}
)
return ret
def generate_wheels_matrix(
os: str,
arches: list[str] | None = None,
python_versions: list[str] | None = None,
) -> list[dict[str, str]]:
package_type = "wheel"
if os == "linux" or os == "linux-aarch64" or os == "linux-s390x":
# NOTE: We only build manywheel packages for x86_64 and aarch64 and s390x linux
package_type = "manywheel"
if python_versions is None:
python_versions = FULL_PYTHON_VERSIONS
if arches is None:
# Define default compute archivectures
arches = ["cpu"]
if os == "linux":
arches += CUDA_ARCHES + ROCM_ARCHES + XPU_ARCHES
elif os == "windows":
arches += CUDA_ARCHES + XPU_ARCHES
elif os == "linux-aarch64":
# Separate new if as the CPU type is different and
# uses different build/test scripts
arches = CPU_AARCH64_ARCH + CUDA_AARCH64_ARCHES
elif os == "linux-s390x":
# Only want the one arch as the CPU type is different and
# uses different build/test scripts
arches = ["cpu-s390x"]
ret: list[dict[str, str]] = []
for python_version in python_versions:
for arch_version in arches:
gpu_arch_type = arch_type(arch_version)
gpu_arch_version = (
""
if arch_version == "cpu"
or arch_version == "cpu-aarch64"
or arch_version == "cpu-s390x"
or arch_version == "xpu"
else arch_version
)
# TODO: Enable python 3.14 for rest
if os not in [
"linux",
"linux-aarch64",
"linux-s390x",
"macos-arm64",
"windows",
] and (python_version == "3.14" or python_version == "3.14t"):
continue
# cuda linux wheels require PYTORCH_EXTRA_INSTALL_REQUIREMENTS to install
if (
arch_version in ["13.2", "13.0", "12.8", "12.6"]
and os == "linux"
or arch_version in CUDA_AARCH64_ARCHES
):
desired_cuda = translate_desired_cuda(gpu_arch_type, gpu_arch_version)
ret.append(
{
"python_version": python_version,
"gpu_arch_type": gpu_arch_type,
"gpu_arch_version": gpu_arch_version,
"desired_cuda": desired_cuda,
"container_image": WHEEL_CONTAINER_IMAGES[arch_version].split(
":"
)[0],
"container_image_tag_prefix": WHEEL_CONTAINER_IMAGES[
arch_version
].split(":")[1],
"package_type": package_type,
"pytorch_extra_install_requirements": (
PYTORCH_EXTRA_INSTALL_REQUIREMENTS[
f"{desired_cuda[2:4]}.{desired_cuda[4:]}" # for cuda-aarch64: cu126 -> 12.6
]
if os == "linux-aarch64"
else PYTORCH_EXTRA_INSTALL_REQUIREMENTS[arch_version]
),
"build_name": (
f"{package_type}-py{python_version}-{gpu_arch_type}"
f"{'-' if 'aarch64' in gpu_arch_type else ''}{gpu_arch_version.replace('-aarch64', '')}".replace(
".", "_"
)
), # include special case for aarch64 build, remove the -aarch64 postfix
}
)
else:
ret.append(
{
"python_version": python_version,
"gpu_arch_type": gpu_arch_type,
"gpu_arch_version": gpu_arch_version,
"desired_cuda": translate_desired_cuda(
gpu_arch_type, gpu_arch_version
),
"container_image": WHEEL_CONTAINER_IMAGES[arch_version].split(
":"
)[0],
"container_image_tag_prefix": WHEEL_CONTAINER_IMAGES[
arch_version
].split(":")[1],
"package_type": package_type,
"build_name": f"{package_type}-py{python_version}-{gpu_arch_type}{gpu_arch_version}".replace(
".", "_"
),
"pytorch_extra_install_requirements": (
PYTORCH_EXTRA_INSTALL_REQUIREMENTS["xpu"]
if gpu_arch_type == "xpu"
else ""
),
}
)
return ret
def generate_libtorch_extraction_configs(
os: str,
wheel_configs: list[dict[str, str]],
) -> list[dict[str, str]]:
"""Generate libtorch extraction configs from existing wheel build configs.
For each unique arch variant in wheel_configs, find the py3.10 config
(py3.11 for windows-arm64) and produce a config that the CI template
uses to add an extraction job that depends on that wheel's build job.
"""
preferred_python = "3.11" if os == "windows-arm64" else "3.10"
# Group wheel configs by (gpu_arch_type, gpu_arch_version)
arch_to_config: dict[tuple[str, str], dict[str, str]] = {}
for config in wheel_configs:
key = (config["gpu_arch_type"], config.get("gpu_arch_version", ""))
if config.get("python_version") == preferred_python:
arch_to_config[key] = config
ret: list[dict[str, str]] = []
for (gpu_arch_type, gpu_arch_version), source_config in arch_to_config.items():
# No libtorch for XPU
if gpu_arch_type == "xpu":
continue
desired_cuda = source_config["desired_cuda"]
libtorch_variant = "shared-with-deps"
build_name = f"libtorch-{gpu_arch_type}{gpu_arch_version}-{libtorch_variant}-release".replace(
".", "_"
)
ret.append(
{
"source_wheel_build_name": source_config["build_name"],
"build_name": build_name,
"package_type": "libtorch",
"libtorch_variant": libtorch_variant,
"libtorch_config": RELEASE,
"desired_cuda": desired_cuda,
"gpu_arch_type": gpu_arch_type,
"gpu_arch_version": gpu_arch_version,
}
)
return ret
arch_version = ""
for arch_version in CUDA_ARCHES:
validate_nccl_dep_consistency(arch_version)
validate_cudnn_version_consistency(arch_version)
del arch_version
if __name__ == "__main__":
# Used by tools/nightly.py
(SCRIPT_DIR / "nightly_source_matrix.json").write_text(
json.dumps(NIGHTLY_SOURCE_MATRIX, indent=4) + "\n"
)