|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Run me as: |
| 3 | +# curl https://raw.githubusercontent.com/meta-pytorch/monarch/refs/heads/main/scripts/install-nightly.py | python |
| 4 | + |
| 5 | +import json |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | +import urllib.request |
| 9 | + |
| 10 | + |
| 11 | +def get_latest_version(package_name: str) -> str: |
| 12 | + """Get latest version from PyPI""" |
| 13 | + api_url = f"https://pypi.org/pypi/{package_name}/json" |
| 14 | + |
| 15 | + try: |
| 16 | + with urllib.request.urlopen(api_url) as response: |
| 17 | + data = json.loads(response.read().decode("utf-8")) |
| 18 | + return data["info"]["version"] |
| 19 | + except Exception as e: |
| 20 | + print(f"Failed to fetch version for {package_name}: {e}", file=sys.stderr) |
| 21 | + sys.exit(1) |
| 22 | + |
| 23 | + |
| 24 | +def get_torch_release_version() -> str: |
| 25 | + """Get PyTorch version numbers""" |
| 26 | + version_url = ( |
| 27 | + "https://raw.githubusercontent.com/pytorch/pytorch/refs/heads/main/version.txt" |
| 28 | + ) |
| 29 | + try: |
| 30 | + with urllib.request.urlopen(version_url) as response: |
| 31 | + return response.read().decode("utf-8").split("a")[0] |
| 32 | + except Exception as e: |
| 33 | + print(f"Failed to fetch torch version: {e}", file=sys.stderr) |
| 34 | + sys.exit(1) |
| 35 | + |
| 36 | + |
| 37 | +def convert_version_for_torch(version: str) -> str: |
| 38 | + """Convert version format for torch (YYYY.M.D or YYYY.MM.DD -> YYYYMMDD)""" |
| 39 | + # Split the version into components |
| 40 | + year, month, day = [int(x) for x in version.split(".")] |
| 41 | + |
| 42 | + return f"{year}{month:02}{day:02}" |
| 43 | + |
| 44 | + |
| 45 | +def main() -> None: |
| 46 | + """Main function""" |
| 47 | + print("Starting torchmonarch-nightly installation script") |
| 48 | + |
| 49 | + # Get latest version |
| 50 | + torchmonarch_version = get_latest_version("torchmonarch-nightly") |
| 51 | + print(f"Latest torchmonarch-nightly version: {torchmonarch_version}") |
| 52 | + |
| 53 | + # Convert version for torch |
| 54 | + torch_release_version = get_torch_release_version() |
| 55 | + torch_date = convert_version_for_torch(torchmonarch_version) |
| 56 | + torch_version = f"{torch_release_version}.dev{torch_date}" |
| 57 | + |
| 58 | + print(f"Corresponding torch version: {torch_version}") |
| 59 | + |
| 60 | + # Construct the pip install command arguments |
| 61 | + pip_command = [ |
| 62 | + sys.executable, |
| 63 | + "-m", |
| 64 | + "pip", |
| 65 | + "install", |
| 66 | + f"torchmonarch-nightly=={torchmonarch_version}", |
| 67 | + f"torch=={torch_version}", |
| 68 | + "--pre", |
| 69 | + "--extra-index-url", |
| 70 | + "https://download.pytorch.org/whl/nightly/cu128", |
| 71 | + ] |
| 72 | + |
| 73 | + print(f"Executing command:\n\t{' '.join(pip_command)}\n\n") |
| 74 | + |
| 75 | + # Execute the command |
| 76 | + subprocess.check_call(pip_command) |
| 77 | + print("Installation completed successfully!") |
| 78 | + print("Installed packages:") |
| 79 | + print(f" - torchmonarch-nightly=={torchmonarch_version}") |
| 80 | + print(f" - torch=={torch_version}") |
| 81 | + |
| 82 | + |
| 83 | +if __name__ == "__main__": |
| 84 | + main() |
0 commit comments