@@ -79,97 +79,29 @@ def clean():
7979VALID_PYBINDS = ["coreml" , "mps" , "xnnpack" ]
8080
8181
82- def main (args ):
83- if not python_is_compatible ():
84- sys .exit (1 )
85-
86- # Parse options.
87-
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"
82+ # The pip repository that hosts nightly torch packages.
83+ TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu"
13384
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
13985
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"
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"
16093
161- # The pip repository that hosts nightly torch packages.
162- TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu"
16394
95+ def install_requirements (use_pytorch_nightly ):
16496 # pip packages needed by exir.
16597 EXIR_REQUIREMENTS = [
166- # Setting USE_PYTORCH_NIGHTLY to false to test the pinned PyTorch commit. Note
98+ # Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
16799 # that we don't need to set any version number there because they have already
168100 # been installed on CI before this step, so pip won't reinstall them
169- f"torch==2.6.0.{ NIGHTLY_VERSION } " if USE_PYTORCH_NIGHTLY else "torch" ,
101+ f"torch==2.6.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torch" ,
170102 (
171103 f"torchvision==0.22.0.{ NIGHTLY_VERSION } "
172- if USE_PYTORCH_NIGHTLY
104+ if use_pytorch_nightly
173105 else "torchvision"
174106 ), # For testing.
175107 "typing-extensions" ,
@@ -179,7 +111,7 @@ def main(args):
179111 # TODO: Make each example publish its own requirements.txt
180112 EXAMPLES_REQUIREMENTS = [
181113 "timm==1.0.7" ,
182- f"torchaudio==2.6.0.{ NIGHTLY_VERSION } " if USE_PYTORCH_NIGHTLY else "torchaudio" ,
114+ f"torchaudio==2.6.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torchaudio" ,
183115 "torchsr==1.0.4" ,
184116 "transformers==4.47.1" ,
185117 ]
@@ -233,6 +165,79 @@ def main(args):
233165 check = True ,
234166 )
235167
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+
236241 #
237242 # Install executorch pip package. This also makes `flatc` available on the path.
238243 # The --extra-index-url may be necessary if pyproject.toml has a dependency on a
0 commit comments