Skip to content

Commit 8c1eb0a

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. (cherry picked from commit 5bf0875)
1 parent 3a2fec7 commit 8c1eb0a

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

build/rocm/ci_build

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import sys
2727
from typing import List
2828

2929

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

3234

3335
def image_by_name(name):
@@ -44,7 +46,7 @@ def dist_wheels(
4446
rocm_build_job="",
4547
rocm_build_num="",
4648
compiler="gcc",
47-
gpu_device_targets : List[str] = None,
49+
gpu_device_targets: List[str] = None,
4850
):
4951
if not gpu_device_targets:
5052
gpu_device_targets = DEFAULT_GPU_DEVICE_TARGETS.split(",")
@@ -169,7 +171,7 @@ def dist_docker(
169171
tag="rocm/jax-dev",
170172
dockerfile=None,
171173
keep_image=True,
172-
gpu_device_targets : List[str] = None,
174+
gpu_device_targets: List[str] = None,
173175
):
174176
if not dockerfile:
175177
dockerfile = "build/rocm/Dockerfile.ms"
@@ -254,6 +256,24 @@ def test(image_name):
254256
subprocess.check_call(cmd)
255257

256258

259+
def canonicalize_python_versions(versions: List[str]):
260+
if isinstance(versions, str):
261+
raise ValueError("'versions' must be a list of strings: versions=%r" % versions)
262+
263+
cleaned = []
264+
for v in versions:
265+
tup = v.split(".")
266+
major = tup[0]
267+
minor = tup[1]
268+
rev = None
269+
if len(tup) > 2 and tup[2]:
270+
rev = tup[2]
271+
272+
cleaned.append("%s.%s" % (major, minor))
273+
274+
return cleaned
275+
276+
257277
def parse_gpu_targets(targets_string):
258278
# catch case where targets_string was empty.
259279
# None should already be caught by argparse, but
@@ -352,11 +372,12 @@ def parse_args():
352372
def main():
353373
args = parse_args()
354374
gpu_device_targets = parse_gpu_targets(args.gpu_device_targets)
375+
python_versions = canonicalize_python_versions(args.python_versions)
355376

356377
if args.action == "dist_wheels":
357378
dist_wheels(
358379
args.rocm_version,
359-
args.python_versions,
380+
python_versions,
360381
args.xla_source_dir,
361382
args.rocm_build_job,
362383
args.rocm_build_num,
@@ -370,7 +391,7 @@ def main():
370391
elif args.action == "dist_docker":
371392
dist_wheels(
372393
args.rocm_version,
373-
args.python_versions,
394+
python_versions,
374395
args.xla_source_dir,
375396
args.rocm_build_job,
376397
args.rocm_build_num,
@@ -380,7 +401,7 @@ def main():
380401
dist_docker(
381402
args.rocm_version,
382403
args.base_docker,
383-
args.python_versions,
404+
python_versions,
384405
args.xla_source_dir,
385406
rocm_build_job=args.rocm_build_job,
386407
rocm_build_num=args.rocm_build_num,

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)