@@ -79,29 +79,97 @@ def clean():
7979VALID_PYBINDS = ["coreml" , "mps" , "xnnpack" ]
8080
8181
82- # The pip repository that hosts nightly torch packages.
83- TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu"
82+ def main (args ):
83+ if not python_is_compatible ():
84+ sys .exit (1 )
8485
86+ # Parse options.
8587
86- # Since ExecuTorch often uses main-branch features of pytorch, only the nightly
87- # pip versions will have the required features.
88- #
89- # NOTE: If a newly-fetched version of the executorch repo changes the value of
90- # NIGHTLY_VERSION, you should re-run this script to install the necessary
91- # package versions.
92- NIGHTLY_VERSION = "dev20250104"
88+ EXECUTORCH_BUILD_PYBIND = ""
89+ CMAKE_ARGS = os .getenv ("CMAKE_ARGS" , "" )
90+ CMAKE_BUILD_ARGS = os .getenv ("CMAKE_BUILD_ARGS" , "" )
91+ USE_PYTORCH_NIGHTLY = True
92+
93+ parser = argparse .ArgumentParser ()
94+ parser .add_argument (
95+ "--pybind" ,
96+ action = "append" ,
97+ nargs = "+" ,
98+ help = "one or more of coreml/mps/xnnpack, or off" ,
99+ )
100+ parser .add_argument (
101+ "--clean" ,
102+ action = "store_true" ,
103+ help = "clean build artifacts and pip-out instead of installing" ,
104+ )
105+ parser .add_argument (
106+ "--use-pt-pinned-commit" ,
107+ action = "store_true" ,
108+ help = "build from the pinned PyTorch commit instead of nightly" ,
109+ )
110+ args = parser .parse_args (args )
111+
112+ if args .clean :
113+ clean ()
114+ return
115+
116+ if args .pybind :
117+ # Flatten list of lists.
118+ args .pybind = list (itertools .chain (* args .pybind ))
119+ if "off" in args .pybind :
120+ if len (args .pybind ) != 1 :
121+ raise Exception (
122+ f"Cannot combine `off` with other pybinds: { args .pybind } "
123+ )
124+ EXECUTORCH_BUILD_PYBIND = "OFF"
125+ else :
126+ for pybind_arg in args .pybind :
127+ if pybind_arg not in VALID_PYBINDS :
128+ raise Exception (
129+ f"Unrecognized pybind argument { pybind_arg } ; valid options are: { ', ' .join (VALID_PYBINDS )} "
130+ )
131+ EXECUTORCH_BUILD_PYBIND = "ON"
132+ CMAKE_ARGS += f" -DEXECUTORCH_BUILD_{ pybind_arg .upper ()} =ON"
93133
134+ if args .use_pt_pinned_commit :
135+ # This option is used in CI to make sure that PyTorch build from the pinned commit
136+ # is used instead of nightly. CI jobs wouldn't be able to catch regression from the
137+ # latest PT commit otherwise
138+ USE_PYTORCH_NIGHTLY = False
139+
140+ # If --pybind is not set explicitly for backends (e.g., --pybind xnnpack)
141+ # or is not turned off explicitly (--pybind off)
142+ # then install XNNPACK by default.
143+ if EXECUTORCH_BUILD_PYBIND == "" :
144+ EXECUTORCH_BUILD_PYBIND = "ON"
145+ CMAKE_ARGS += " -DEXECUTORCH_BUILD_XNNPACK=ON"
146+
147+ # Use ClangCL on Windows.
148+ # ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
149+ # mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
150+ if os .name == "nt" :
151+ CMAKE_ARGS += " -T ClangCL"
152+
153+ # Since ExecuTorch often uses main-branch features of pytorch, only the nightly
154+ # pip versions will have the required features.
155+ #
156+ # NOTE: If a newly-fetched version of the executorch repo changes the value of
157+ # NIGHTLY_VERSION, you should re-run this script to install the necessary
158+ # package versions.
159+ NIGHTLY_VERSION = "dev20250104"
160+
161+ # The pip repository that hosts nightly torch packages.
162+ TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu"
94163
95- def install_requirements (use_pytorch_nightly ):
96164 # pip packages needed by exir.
97165 EXIR_REQUIREMENTS = [
98- # Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
166+ # Setting USE_PYTORCH_NIGHTLY to false to test the pinned PyTorch commit. Note
99167 # that we don't need to set any version number there because they have already
100168 # been installed on CI before this step, so pip won't reinstall them
101- f"torch==2.6.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torch" ,
169+ f"torch==2.6.0.{ NIGHTLY_VERSION } " if USE_PYTORCH_NIGHTLY else "torch" ,
102170 (
103171 f"torchvision==0.22.0.{ NIGHTLY_VERSION } "
104- if use_pytorch_nightly
172+ if USE_PYTORCH_NIGHTLY
105173 else "torchvision"
106174 ), # For testing.
107175 "typing-extensions" ,
@@ -111,7 +179,7 @@ def install_requirements(use_pytorch_nightly):
111179 # TODO: Make each example publish its own requirements.txt
112180 EXAMPLES_REQUIREMENTS = [
113181 "timm==1.0.7" ,
114- f"torchaudio==2.6.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torchaudio" ,
182+ f"torchaudio==2.6.0.{ NIGHTLY_VERSION } " if USE_PYTORCH_NIGHTLY else "torchaudio" ,
115183 "torchsr==1.0.4" ,
116184 "transformers==4.47.1" ,
117185 ]
@@ -165,79 +233,6 @@ def install_requirements(use_pytorch_nightly):
165233 check = True ,
166234 )
167235
168-
169- def main (args ):
170- if not python_is_compatible ():
171- sys .exit (1 )
172-
173- # Parse options.
174-
175- EXECUTORCH_BUILD_PYBIND = ""
176- CMAKE_ARGS = os .getenv ("CMAKE_ARGS" , "" )
177- CMAKE_BUILD_ARGS = os .getenv ("CMAKE_BUILD_ARGS" , "" )
178- use_pytorch_nightly = True
179-
180- parser = argparse .ArgumentParser ()
181- parser .add_argument (
182- "--pybind" ,
183- action = "append" ,
184- nargs = "+" ,
185- help = "one or more of coreml/mps/xnnpack, or off" ,
186- )
187- parser .add_argument (
188- "--clean" ,
189- action = "store_true" ,
190- help = "clean build artifacts and pip-out instead of installing" ,
191- )
192- parser .add_argument (
193- "--use-pt-pinned-commit" ,
194- action = "store_true" ,
195- help = "build from the pinned PyTorch commit instead of nightly" ,
196- )
197- args = parser .parse_args (args )
198- if args .pybind :
199- # Flatten list of lists.
200- args .pybind = list (itertools .chain (* args .pybind ))
201- if "off" in args .pybind :
202- if len (args .pybind ) != 1 :
203- raise Exception (
204- f"Cannot combine `off` with other pybinds: { args .pybind } "
205- )
206- EXECUTORCH_BUILD_PYBIND = "OFF"
207- else :
208- for pybind_arg in args .pybind :
209- if pybind_arg not in VALID_PYBINDS :
210- raise Exception (
211- f"Unrecognized pybind argument { pybind_arg } ; valid options are: { ', ' .join (VALID_PYBINDS )} "
212- )
213- EXECUTORCH_BUILD_PYBIND = "ON"
214- CMAKE_ARGS += f" -DEXECUTORCH_BUILD_{ pybind_arg .upper ()} =ON"
215-
216- if args .clean :
217- clean ()
218- return
219-
220- if args .use_pt_pinned_commit :
221- # This option is used in CI to make sure that PyTorch build from the pinned commit
222- # is used instead of nightly. CI jobs wouldn't be able to catch regression from the
223- # latest PT commit otherwise
224- use_pytorch_nightly = False
225-
226- install_requirements (use_pytorch_nightly )
227-
228- # If --pybind is not set explicitly for backends (e.g., --pybind xnnpack)
229- # or is not turned off explicitly (--pybind off)
230- # then install XNNPACK by default.
231- if EXECUTORCH_BUILD_PYBIND == "" :
232- EXECUTORCH_BUILD_PYBIND = "ON"
233- CMAKE_ARGS += " -DEXECUTORCH_BUILD_XNNPACK=ON"
234-
235- # Use ClangCL on Windows.
236- # ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
237- # mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
238- if os .name == "nt" :
239- CMAKE_ARGS += " -T ClangCL"
240-
241236 #
242237 # Install executorch pip package. This also makes `flatc` available on the path.
243238 # The --extra-index-url may be necessary if pyproject.toml has a dependency on a
0 commit comments