Skip to content

Commit

Permalink
[Easy] Add ROCm support to nightly pull tool (pytorch#141282)
Browse files Browse the repository at this point in the history
Pull Request resolved: pytorch#141282
Approved by: https://github.com/malfet
ghstack dependencies: pytorch#143263
  • Loading branch information
XuehaiPan authored and pytorchmergebot committed Dec 27, 2024
1 parent 8059d56 commit c4bff71
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/scripts/generate_binary_build_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CUDA_ARCHES_FULL_VERSION = {"11.8": "11.8.0", "12.4": "12.4.1", "12.6": "12.6.3"}
CUDA_ARCHES_CUDNN_VERSION = {"11.8": "9", "12.4": "9", "12.6": "9"}

# NOTE: Also update the ROCm sources in tools/nightly.py when changing this list
ROCM_ARCHES = ["6.2.4", "6.3"]

XPU_ARCHES = ["xpu"]
Expand Down
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ git clone [email protected]:<USERNAME>/pytorch.git
cd pytorch
git remote add upstream [email protected]:pytorch/pytorch.git

make setup-env # or make setup-env-cuda for pre-built CUDA binaries
make setup-env
# Or run `make setup-env-cuda` for pre-built CUDA binaries
# Or run `make setup-env-rocm` for pre-built ROCm binaries
source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
```

Expand Down Expand Up @@ -193,6 +195,13 @@ To install the nightly binaries built with CUDA, you can pass in the flag `--cud
source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
```

To install the nightly binaries built with ROCm, you can pass in the flag `--rocm`:

```bash
./tools/nightly.py checkout -b my-nightly-branch --rocm
source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
```

You can also use this tool to pull the nightly commits into the current branch:

```bash
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ setup-env: ensure-branch-clean
setup-env-cuda:
$(MAKE) setup-env PYTHON="$(PYTHON)" NIGHTLY_TOOL_OPTS="$(NIGHTLY_TOOL_OPTS) --cuda"

setup-env-rocm:
$(MAKE) setup-env PYTHON="$(PYTHON)" NIGHTLY_TOOL_OPTS="$(NIGHTLY_TOOL_OPTS) --rocm"

setup_env: setup-env
setup_env_cuda: setup-env-cuda
setup_env_rocm: setup-env-rocm

setup-lint:
$(PIP) install lintrunner
Expand Down
68 changes: 49 additions & 19 deletions tools/nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
$ ./tools/nightly.py checkout -b my-nightly-branch --cuda
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
To install the nightly binaries built with ROCm, you can pass in the flag --rocm::
$ ./tools/nightly.py checkout -b my-nightly-branch --rocm
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
You can also use this tool to pull the nightly commits into the current branch as
well. This can be done with::
Expand Down Expand Up @@ -134,6 +139,12 @@ class PipSource(NamedTuple):
supported_platforms={"Linux", "Windows"},
accelerator="cuda",
),
"rocm-6.2.4": PipSource(
name="rocm-6.2.4",
index_url=f"{PYTORCH_NIGHTLY_PIP_INDEX_URL}/rocm6.2.4",
supported_platforms={"Linux"},
accelerator="rocm",
),
}


Expand Down Expand Up @@ -882,13 +893,26 @@ def find_executable(name: str) -> Path:
default=argparse.SUPPRESS,
metavar="VERSION",
)
subparser.add_argument(
"--rocm",
help=(
"ROCm version to install "
"(defaults to the latest version available on the platform)"
),
dest="rocm",
nargs="?",
default=argparse.SUPPRESS,
metavar="VERSION",
)
return parser


def parse_arguments() -> argparse.Namespace:
parser = make_parser()
args = parser.parse_args()
args.branch = getattr(args, "branch", None)
if hasattr(args, "cuda") and hasattr(args, "rocm"):
parser.error("Cannot specify both CUDA and ROCm versions.")
return args


Expand All @@ -901,26 +925,32 @@ def main() -> None:
sys.exit(status)

pip_source = None
if hasattr(args, "cuda"):
available_sources = {
src.name[len("cuda-") :]: src
for src in PIP_SOURCES.values()
if src.name.startswith("cuda-") and PLATFORM in src.supported_platforms
}
if not available_sources:
print(f"No CUDA versions available on platform {PLATFORM}.")
sys.exit(1)
if args.cuda is not None:
pip_source = available_sources.get(args.cuda)
if pip_source is None:
print(
f"CUDA {args.cuda} is not available on platform {PLATFORM}. "
f"Available version(s): {', '.join(sorted(available_sources, key=Version))}"
)

for toolkit in ("CUDA", "ROCm"):
accel = toolkit.lower()
if hasattr(args, accel):
requested = getattr(args, accel)
available_sources = {
src.name[len(f"{accel}-") :]: src
for src in PIP_SOURCES.values()
if src.name.startswith(f"{accel}-")
and PLATFORM in src.supported_platforms
}
if not available_sources:
print(f"No {toolkit} versions available on platform {PLATFORM}.")
sys.exit(1)
else:
pip_source = available_sources[max(available_sources, key=Version)]
else:
if requested is not None:
pip_source = available_sources.get(requested)
if pip_source is None:
print(
f"{toolkit} {requested} is not available on platform {PLATFORM}. "
f"Available version(s): {', '.join(sorted(available_sources, key=Version))}"
)
sys.exit(1)
else:
pip_source = available_sources[max(available_sources, key=Version)]

if pip_source is None:
pip_source = PIP_SOURCES["cpu"] # always available

with logging_manager(debug=args.verbose) as logger:
Expand Down

0 comments on commit c4bff71

Please sign in to comment.