Skip to content

Commit 5bf0875

Browse files
committed
Add canonicalization of python versions
The ci_build parsing will now drop the revision portion of the requested python version targets to build for, since users were passing in old buggy versions. Using only major.minor will result in the latest of the minor series being used, and won't affect any build outputs like bytecode or ABI bindings. Those are tied to major.minor versions of CPython.
1 parent 5024cf8 commit 5bf0875

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

build/rocm/ci_build

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import sys
2828
from typing import List
2929

3030

31-
DEFAULT_GPU_DEVICE_TARGETS = "gfx906,gfx908,gfx90a,gfx942,gfx1030,gfx1100,gfx1101,gfx1200,gfx1201"
31+
DEFAULT_GPU_DEVICE_TARGETS = (
32+
"gfx906,gfx908,gfx90a,gfx942,gfx1030,gfx1100,gfx1101,gfx1200,gfx1201"
33+
)
3234

3335

3436
LOG = logging.getLogger("ci_build")
@@ -41,7 +43,9 @@ def image_by_name(name):
4143
return image_id
4244

4345

44-
def create_manylinux_build_image(rocm_version, rocm_build_job, rocm_build_num, gpu_device_targets: List[str]) -> str:
46+
def create_manylinux_build_image(
47+
rocm_version, rocm_build_job, rocm_build_num, gpu_device_targets: List[str]
48+
) -> str:
4549
image_name = "jax-build-manylinux_2_28_x86_64_rocm%s" % rocm_version.replace(
4650
".", ""
4751
)
@@ -71,7 +75,7 @@ def dist_wheels(
7175
rocm_build_job="",
7276
rocm_build_num="",
7377
compiler="gcc",
74-
gpu_device_targets : List[str] = None,
78+
gpu_device_targets: List[str] = None,
7579
):
7680
if not gpu_device_targets:
7781
gpu_device_targets = DEFAULT_GPU_DEVICE_TARGETS.split(",")
@@ -183,7 +187,7 @@ def dist_docker(
183187
tag="rocm/jax-dev",
184188
dockerfile=None,
185189
keep_image=True,
186-
gpu_device_targets : List[str] = None,
190+
gpu_device_targets: List[str] = None,
187191
):
188192
if not dockerfile:
189193
dockerfile = "build/rocm/Dockerfile.ms"
@@ -270,6 +274,24 @@ def test(image_name, test_cmd):
270274
subprocess.check_call(cmd)
271275

272276

277+
def canonicalize_python_versions(versions: List[str]):
278+
if isinstance(versions, str):
279+
raise ValueError("'versions' must be a list of strings: versions=%r" % versions)
280+
281+
cleaned = []
282+
for v in versions:
283+
tup = v.split(".")
284+
major = tup[0]
285+
minor = tup[1]
286+
rev = None
287+
if len(tup) > 2 and tup[2]:
288+
rev = tup[2]
289+
290+
cleaned.append("%s.%s" % (major, minor))
291+
292+
return cleaned
293+
294+
273295
def parse_gpu_targets(targets_string):
274296
# catch case where targets_string was empty.
275297
# None should already be caught by argparse, but
@@ -373,11 +395,12 @@ def main():
373395
logging.basicConfig(level=logging.INFO)
374396
args = parse_args()
375397
gpu_device_targets = parse_gpu_targets(args.gpu_device_targets)
398+
python_versions = canonicalize_python_versions(args.python_versions)
376399

377400
if args.action == "dist_wheels":
378401
dist_wheels(
379402
args.rocm_version,
380-
args.python_versions,
403+
python_versions,
381404
args.xla_source_dir,
382405
args.rocm_build_job,
383406
args.rocm_build_num,
@@ -391,7 +414,7 @@ def main():
391414
elif args.action == "dist_docker":
392415
dist_wheels(
393416
args.rocm_version,
394-
args.python_versions,
417+
python_versions,
395418
args.xla_source_dir,
396419
args.rocm_build_job,
397420
args.rocm_build_num,
@@ -401,7 +424,7 @@ def main():
401424
dist_docker(
402425
args.rocm_version,
403426
args.base_docker,
404-
args.python_versions,
427+
python_versions,
405428
args.xla_source_dir,
406429
rocm_build_job=args.rocm_build_job,
407430
rocm_build_num=args.rocm_build_num,
@@ -414,4 +437,3 @@ def main():
414437

415438
if __name__ == "__main__":
416439
main()
417-

build/rocm/test_ci_build.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ def test_parse_gpu_targets_invalid_arch(self):
5555
targets = ["gfx908", "gfx940", "--oops", "/jax"]
5656
self.assertRaises(ValueError, ci_build.parse_gpu_targets, " ".join(targets))
5757

58+
def test_canonicalize_python_versions(self):
59+
versions = ["3.10.0", "3.11.0", "3.12.0"]
60+
exp = ["3.10", "3.11", "3.12"]
61+
res = ci_build.canonicalize_python_versions(versions)
62+
self.assertEqual(res, exp)
63+
64+
def test_canonicalize_python_versions_scalar(self):
65+
versions = ["3.10.0"]
66+
exp = ["3.10"]
67+
res = ci_build.canonicalize_python_versions(versions)
68+
self.assertEqual(res, exp)
69+
70+
def test_canonicalize_python_versions_no_revision_part(self):
71+
versions = ["3.10", "3.11"]
72+
res = ci_build.canonicalize_python_versions(versions)
73+
self.assertEqual(res, versions)
74+
75+
def test_canonicalize_python_versions_string(self):
76+
versions = "3.10.0"
77+
self.assertRaises(ValueError, ci_build.canonicalize_python_versions, versions)
78+
5879

5980
if __name__ == "__main__":
6081
unittest.main()

0 commit comments

Comments
 (0)