From d4988ea0ef2d2bf61d185bb196016c40e47c276e Mon Sep 17 00:00:00 2001 From: Luca Bruni Date: Wed, 8 Jul 2026 11:52:57 -0400 Subject: [PATCH 1/5] ci(pytorch): derive numpy test pin from vendored torch checkout Instead of hand-copying upstream's per-Python numpy pins into requirements-test.txt (which drifts and is per-torch-branch), derive them at install time from the checked-out torch's own .ci/docker/requirements-ci.txt via derive_test_requirements.py, and wire it into the non-full PyTorch test workflow. Prototype / follow-up to the review discussion on #6400. Relates to pytorch/pytorch#189267. --- .github/workflows/test_pytorch_wheels.yml | 4 ++ .../pytorch/derive_test_requirements.py | 65 +++++++++++++++++++ external-builds/pytorch/requirements-test.txt | 4 +- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 external-builds/pytorch/derive_test_requirements.py diff --git a/.github/workflows/test_pytorch_wheels.yml b/.github/workflows/test_pytorch_wheels.yml index 9eddb93d835..1a718a412a9 100644 --- a/.github/workflows/test_pytorch_wheels.yml +++ b/.github/workflows/test_pytorch_wheels.yml @@ -214,6 +214,10 @@ jobs: - name: Install test requirements run: | python -m pip install -r external-builds/pytorch/requirements-test.txt + # numpy is pinned to what upstream validates for the checked-out torch + # ref, derived from its .ci/docker/requirements-ci.txt (avoids drift). + python external-builds/pytorch/derive_test_requirements.py \ + | python -m pip install -r /dev/stdin pip freeze - name: Run rocm-sdk sanity tests diff --git a/external-builds/pytorch/derive_test_requirements.py b/external-builds/pytorch/derive_test_requirements.py new file mode 100644 index 00000000000..73eb2c2f6e9 --- /dev/null +++ b/external-builds/pytorch/derive_test_requirements.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# Copyright Advanced Micro Devices, Inc. +# SPDX-License-Identifier: MIT + +"""Print pinned test requirements sourced from the vendored PyTorch checkout. + +Extracts the pins for the requested packages (default: ``numpy``) from the +checked-out PyTorch's ``.ci/docker/requirements-ci.txt`` and prints them, so +TheRock installs the exact versions upstream validates for the torch ref under +test instead of a hand-copied pin that silently drifts. Environment markers +(e.g. ``; python_version ...``) are preserved so pip selects the right line. + +Usage: + python derive_test_requirements.py + python derive_test_requirements.py --package numpy --package scipy + python derive_test_requirements.py | python -m pip install -r /dev/stdin +""" + +import argparse +import re +import sys +from pathlib import Path + +THIS_DIR = Path(__file__).resolve().parent +DEFAULT_REQUIREMENTS_CI = THIS_DIR / "pytorch" / ".ci" / "docker" / "requirements-ci.txt" + + +def extract_pins(requirements_ci: Path, packages: list[str]) -> list[str]: + """Return the requirement lines for each package, in the given order.""" + lines = requirements_ci.read_text().splitlines() + pins: list[str] = [] + for package in packages: + pattern = re.compile(rf"^\s*{re.escape(package)}\s*(==|>=|<=|<|>|~=|;|$)") + matches = [line.rstrip() for line in lines if pattern.match(line)] + if not matches: + raise ValueError(f"no pin for '{package}' found in {requirements_ci}") + pins.extend(matches) + return pins + + +def main(argv: list[str]) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--package", + action="append", + dest="packages", + help="Package to extract (repeatable). Defaults to numpy.", + ) + parser.add_argument( + "--requirements-ci", + type=Path, + default=DEFAULT_REQUIREMENTS_CI, + help=f"PyTorch requirements-ci.txt to read. Default: {DEFAULT_REQUIREMENTS_CI}", + ) + args = parser.parse_args(argv) + + if not args.requirements_ci.exists(): + parser.error(f"requirements-ci.txt not found: {args.requirements_ci}") + + print("\n".join(extract_pins(args.requirements_ci, args.packages or ["numpy"]))) + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/external-builds/pytorch/requirements-test.txt b/external-builds/pytorch/requirements-test.txt index afaa73b3e48..82dd8c2dc00 100644 --- a/external-builds/pytorch/requirements-test.txt +++ b/external-builds/pytorch/requirements-test.txt @@ -6,5 +6,7 @@ pytest-xdist>=3.5.0 expecttest>=0.3.0 hypothesis ninja -numpy +# numpy is intentionally omitted here: it is derived per torch-ref from the +# vendored PyTorch checkout at test time (see derive_test_requirements.py), +# mirroring upstream's .ci/docker/requirements-ci.txt without manual drift. psutil From c9a9d247bd573e640d093f9f9504fb30b85f7d52 Mon Sep 17 00:00:00 2001 From: Luca Bruni Date: Wed, 8 Jul 2026 11:58:50 -0400 Subject: [PATCH 2/5] ci(pytorch): apply black formatting to derive_test_requirements.py --- external-builds/pytorch/derive_test_requirements.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/external-builds/pytorch/derive_test_requirements.py b/external-builds/pytorch/derive_test_requirements.py index 73eb2c2f6e9..35a06ebe464 100644 --- a/external-builds/pytorch/derive_test_requirements.py +++ b/external-builds/pytorch/derive_test_requirements.py @@ -22,7 +22,9 @@ from pathlib import Path THIS_DIR = Path(__file__).resolve().parent -DEFAULT_REQUIREMENTS_CI = THIS_DIR / "pytorch" / ".ci" / "docker" / "requirements-ci.txt" +DEFAULT_REQUIREMENTS_CI = ( + THIS_DIR / "pytorch" / ".ci" / "docker" / "requirements-ci.txt" +) def extract_pins(requirements_ci: Path, packages: list[str]) -> list[str]: From d0f0bb38bbe8c37b03c88f7f80f0e1f4c7ee6c4a Mon Sep 17 00:00:00 2001 From: Luca Bruni Date: Wed, 8 Jul 2026 13:13:49 -0400 Subject: [PATCH 3/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- external-builds/pytorch/derive_test_requirements.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/external-builds/pytorch/derive_test_requirements.py b/external-builds/pytorch/derive_test_requirements.py index 35a06ebe464..88e5c78ecf7 100644 --- a/external-builds/pytorch/derive_test_requirements.py +++ b/external-builds/pytorch/derive_test_requirements.py @@ -56,10 +56,15 @@ def main(argv: list[str]) -> int: ) args = parser.parse_args(argv) - if not args.requirements_ci.exists(): + if not args.requirements_ci.is_file(): parser.error(f"requirements-ci.txt not found: {args.requirements_ci}") - print("\n".join(extract_pins(args.requirements_ci, args.packages or ["numpy"]))) + try: + pins = extract_pins(args.requirements_ci, args.packages or ["numpy"]) + except ValueError as e: + parser.error(str(e)) + + print("\n".join(pins)) return 0 From 382fef2f026275a70d0f0ac02bdc2c65f80bdf31 Mon Sep 17 00:00:00 2001 From: Luca Bruni Date: Wed, 8 Jul 2026 13:14:08 -0400 Subject: [PATCH 4/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- external-builds/pytorch/derive_test_requirements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external-builds/pytorch/derive_test_requirements.py b/external-builds/pytorch/derive_test_requirements.py index 88e5c78ecf7..92ce64deac4 100644 --- a/external-builds/pytorch/derive_test_requirements.py +++ b/external-builds/pytorch/derive_test_requirements.py @@ -13,7 +13,7 @@ Usage: python derive_test_requirements.py python derive_test_requirements.py --package numpy --package scipy - python derive_test_requirements.py | python -m pip install -r /dev/stdin + python derive_test_requirements.py | python -m pip install -r - """ import argparse From 4d8e0a2e689c6fe25a2d549bba5cb7ba306495c9 Mon Sep 17 00:00:00 2001 From: Luca Bruni Date: Wed, 8 Jul 2026 13:14:21 -0400 Subject: [PATCH 5/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/workflows/test_pytorch_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_pytorch_wheels.yml b/.github/workflows/test_pytorch_wheels.yml index 1a718a412a9..d5c64ab729d 100644 --- a/.github/workflows/test_pytorch_wheels.yml +++ b/.github/workflows/test_pytorch_wheels.yml @@ -217,7 +217,7 @@ jobs: # numpy is pinned to what upstream validates for the checked-out torch # ref, derived from its .ci/docker/requirements-ci.txt (avoids drift). python external-builds/pytorch/derive_test_requirements.py \ - | python -m pip install -r /dev/stdin + | python -m pip install -r - pip freeze - name: Run rocm-sdk sanity tests