@@ -79,29 +79,97 @@ def clean():
79
79
VALID_PYBINDS = ["coreml" , "mps" , "xnnpack" ]
80
80
81
81
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 )
84
85
86
+ # Parse options.
85
87
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"
93
133
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"
94
163
95
- def install_requirements (use_pytorch_nightly ):
96
164
# pip packages needed by exir.
97
165
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
99
167
# that we don't need to set any version number there because they have already
100
168
# 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" ,
102
170
(
103
171
f"torchvision==0.22.0.{ NIGHTLY_VERSION } "
104
- if use_pytorch_nightly
172
+ if USE_PYTORCH_NIGHTLY
105
173
else "torchvision"
106
174
), # For testing.
107
175
"typing-extensions" ,
@@ -111,7 +179,7 @@ def install_requirements(use_pytorch_nightly):
111
179
# TODO: Make each example publish its own requirements.txt
112
180
EXAMPLES_REQUIREMENTS = [
113
181
"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" ,
115
183
"torchsr==1.0.4" ,
116
184
"transformers==4.47.1" ,
117
185
]
@@ -165,79 +233,6 @@ def install_requirements(use_pytorch_nightly):
165
233
check = True ,
166
234
)
167
235
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
-
241
236
#
242
237
# Install executorch pip package. This also makes `flatc` available on the path.
243
238
# The --extra-index-url may be necessary if pyproject.toml has a dependency on a
0 commit comments