@@ -76,27 +76,15 @@ def python_is_compatible():
76
76
77
77
def install_requirements (use_pytorch_nightly ):
78
78
# pip packages needed by exir.
79
- EXIR_REQUIREMENTS = [
79
+ TORCH_PACKAGE = [
80
80
# Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
81
81
# that we don't need to set any version number there because they have already
82
82
# been installed on CI before this step, so pip won't reinstall them
83
83
f"torch==2.8.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torch" ,
84
- (
85
- f"torchvision==0.23.0.{ NIGHTLY_VERSION } "
86
- if use_pytorch_nightly
87
- else "torchvision"
88
- ), # For testing.
89
84
]
90
85
91
- EXAMPLES_REQUIREMENTS = [
92
- f"torchaudio==2.8.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torchaudio" ,
93
- ]
94
-
95
- # Assemble the list of requirements to actually install.
96
- # TODO: Add options for reducing the number of requirements.
97
- REQUIREMENTS_TO_INSTALL = EXIR_REQUIREMENTS + EXAMPLES_REQUIREMENTS
98
-
99
- # Install the requirements. `--extra-index-url` tells pip to look for package
86
+ # Install the requirements for core ExecuTorch package.
87
+ # `--extra-index-url` tells pip to look for package
100
88
# versions on the provided URL if they aren't available on the default URL.
101
89
subprocess .run (
102
90
[
@@ -105,10 +93,8 @@ def install_requirements(use_pytorch_nightly):
105
93
"pip" ,
106
94
"install" ,
107
95
"-r" ,
108
- "requirements-examples.txt" ,
109
- "-r" ,
110
96
"requirements-dev.txt" ,
111
- * REQUIREMENTS_TO_INSTALL ,
97
+ * TORCH_PACKAGE ,
112
98
"--extra-index-url" ,
113
99
TORCH_NIGHTLY_URL ,
114
100
],
@@ -139,15 +125,61 @@ def install_requirements(use_pytorch_nightly):
139
125
)
140
126
141
127
128
+ def install_optional_example_requirements (use_pytorch_nightly ):
129
+ print ("Installing packages in requirements-examples.txt" )
130
+ subprocess .run (
131
+ [
132
+ sys .executable ,
133
+ "-m" ,
134
+ "pip" ,
135
+ "install" ,
136
+ "-r" ,
137
+ "requirements-examples.txt" ,
138
+ ],
139
+ check = True ,
140
+ )
141
+
142
+ print ("Installing torch domain libraries" )
143
+ DOMAIN_LIBRARIES = [
144
+ (
145
+ f"torchvision==0.23.0.{ NIGHTLY_VERSION } "
146
+ if use_pytorch_nightly
147
+ else "torchvision"
148
+ ),
149
+ f"torchaudio==2.8.0.{ NIGHTLY_VERSION } " if use_pytorch_nightly else "torchaudio" ,
150
+ ]
151
+ # Then install domain libraries
152
+ subprocess .run (
153
+ [
154
+ sys .executable ,
155
+ "-m" ,
156
+ "pip" ,
157
+ "install" ,
158
+ * DOMAIN_LIBRARIES ,
159
+ "--extra-index-url" ,
160
+ TORCH_NIGHTLY_URL ,
161
+ ],
162
+ check = True ,
163
+ )
164
+
165
+
142
166
def main (args ):
143
167
parser = argparse .ArgumentParser ()
144
168
parser .add_argument (
145
169
"--use-pt-pinned-commit" ,
146
170
action = "store_true" ,
147
171
help = "build from the pinned PyTorch commit instead of nightly" ,
148
172
)
173
+ parser .add_argument (
174
+ "--example" ,
175
+ action = "store_true" ,
176
+ help = "Also installs required packages for running example scripts." ,
177
+ )
149
178
args = parser .parse_args (args )
150
- install_requirements (use_pytorch_nightly = not bool (args .use_pt_pinned_commit ))
179
+ use_pytorch_nightly = not bool (args .use_pt_pinned_commit )
180
+ install_requirements (use_pytorch_nightly )
181
+ if args .example :
182
+ install_optional_example_requirements (use_pytorch_nightly )
151
183
152
184
153
185
if __name__ == "__main__" :
0 commit comments