77
88import argparse
99import os
10- import platform
11- import re
1210import subprocess
1311import sys
1412
15-
16- def python_is_compatible ():
17- # Scrape the version range from pyproject.toml, which should be in the current directory.
18- version_specifier = None
19- with open ("pyproject.toml" , "r" ) as file :
20- for line in file :
21- if line .startswith ("requires-python" ):
22- match = re .search (r'"([^"]*)"' , line )
23- if match :
24- version_specifier = match .group (1 )
25- break
26-
27- if not version_specifier :
28- print (
29- "WARNING: Skipping python version check: version range not found" ,
30- file = sys .stderr ,
31- )
32- return False
33-
34- # Install the packaging module if necessary.
35- try :
36- import packaging
37- except ImportError :
38- subprocess .run (
39- [sys .executable , "-m" , "pip" , "install" , "packaging" ], check = True
40- )
41- # Compare the current python version to the range in version_specifier. Exits
42- # with status 1 if the version is not compatible, or with status 0 if the
43- # version is compatible or the logic itself fails.
44- try :
45- import packaging .specifiers
46- import packaging .version
47-
48- python_version = packaging .version .parse (platform .python_version ())
49- version_range = packaging .specifiers .SpecifierSet (version_specifier )
50- if python_version not in version_range :
51- print (
52- f'ERROR: ExecuTorch does not support python version { python_version } : must satisfy "{ version_specifier } "' ,
53- file = sys .stderr ,
54- )
55- return False
56- except Exception as e :
57- print (f"WARNING: Skipping python version check: { e } " , file = sys .stderr )
58- return True
59-
13+ from install_utils import determine_torch_url , is_intel_mac_os , python_is_compatible
6014
6115# The pip repository that hosts nightly torch packages.
62- TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu"
16+ # This will be dynamically set based on CUDA availability and CUDA backend enabled/disabled.
17+ TORCH_NIGHTLY_URL_BASE = "https://download.pytorch.org/whl/nightly"
6318
19+ # Supported CUDA versions - modify this to add/remove supported versions
20+ # Format: tuple of (major, minor) version numbers
21+ SUPPORTED_CUDA_VERSIONS = (
22+ (12 , 6 ),
23+ (12 , 8 ),
24+ (12 , 9 ),
25+ )
6426
6527# Since ExecuTorch often uses main-branch features of pytorch, only the nightly
6628# pip versions will have the required features.
@@ -71,7 +33,10 @@ def python_is_compatible():
7133#
7234# NOTE: If you're changing, make the corresponding change in .ci/docker/ci_commit_pins/pytorch.txt
7335# by picking the hash from the same date in https://hud.pytorch.org/hud/pytorch/pytorch/nightly/
74- NIGHTLY_VERSION = "dev20250906"
36+ #
37+ # NOTE: If you're changing, make the corresponding supported CUDA versions in
38+ # SUPPORTED_CUDA_VERSIONS above if needed.
39+ NIGHTLY_VERSION = "dev20250915"
7540
7641
7742def install_requirements (use_pytorch_nightly ):
@@ -84,12 +49,15 @@ def install_requirements(use_pytorch_nightly):
8449 )
8550 sys .exit (1 )
8651
52+ # Determine the appropriate PyTorch URL based on CUDA delegate status
53+ torch_url = determine_torch_url (TORCH_NIGHTLY_URL_BASE , SUPPORTED_CUDA_VERSIONS )
54+
8755 # pip packages needed by exir.
8856 TORCH_PACKAGE = [
8957 # Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
9058 # that we don't need to set any version number there because they have already
9159 # been installed on CI before this step, so pip won't reinstall them
92- f"torch==2.9 .0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torch" ,
60+ f"torch==2.10 .0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torch" ,
9361 ]
9462
9563 # Install the requirements for core ExecuTorch package.
@@ -105,7 +73,7 @@ def install_requirements(use_pytorch_nightly):
10573 "requirements-dev.txt" ,
10674 * TORCH_PACKAGE ,
10775 "--extra-index-url" ,
108- TORCH_NIGHTLY_URL ,
76+ torch_url ,
10977 ],
11078 check = True ,
11179 )
@@ -147,10 +115,13 @@ def install_requirements(use_pytorch_nightly):
147115
148116
149117def install_optional_example_requirements (use_pytorch_nightly ):
118+ # Determine the appropriate PyTorch URL based on CUDA delegate status
119+ torch_url = determine_torch_url (TORCH_NIGHTLY_URL_BASE , SUPPORTED_CUDA_VERSIONS )
120+
150121 print ("Installing torch domain libraries" )
151122 DOMAIN_LIBRARIES = [
152123 (
153- f"torchvision==0.24 .0.{ NIGHTLY_VERSION } "
124+ f"torchvision==0.25 .0.{ NIGHTLY_VERSION } "
154125 if use_pytorch_nightly
155126 else "torchvision"
156127 ),
@@ -165,7 +136,7 @@ def install_optional_example_requirements(use_pytorch_nightly):
165136 "install" ,
166137 * DOMAIN_LIBRARIES ,
167138 "--extra-index-url" ,
168- TORCH_NIGHTLY_URL ,
139+ torch_url ,
169140 ],
170141 check = True ,
171142 )
@@ -180,25 +151,14 @@ def install_optional_example_requirements(use_pytorch_nightly):
180151 "-r" ,
181152 "requirements-examples.txt" ,
182153 "--extra-index-url" ,
183- TORCH_NIGHTLY_URL ,
154+ torch_url ,
184155 "--upgrade-strategy" ,
185156 "only-if-needed" ,
186157 ],
187158 check = True ,
188159 )
189160
190161
191- # Prebuilt binaries for Intel-based macOS are no longer available on PyPI; users must compile from source.
192- # PyTorch stopped building macOS x86_64 binaries since version 2.3.0 (January 2024).
193- def is_intel_mac_os ():
194- # Returns True if running on Intel macOS.
195- return platform .system ().lower () == "darwin" and platform .machine ().lower () in (
196- "x86" ,
197- "x86_64" ,
198- "i386" ,
199- )
200-
201-
202162def main (args ):
203163 parser = argparse .ArgumentParser ()
204164 parser .add_argument (
0 commit comments