Skip to content

Commit fe94337

Browse files
committed
Install examples and domain libraries as last (optional) step
1 parent 289acbd commit fe94337

File tree

4 files changed

+67
-26
lines changed

4 files changed

+67
-26
lines changed

install_executorch.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from contextlib import contextmanager
1717

1818
from install_requirements import (
19+
install_optional_example_requirements,
1920
install_requirements,
2021
python_is_compatible,
2122
TORCH_NIGHTLY_URL,
@@ -157,6 +158,13 @@ def _parse_args() -> argparse.Namespace:
157158
"picked up without rebuilding the wheel. Extension libraries will be "
158159
"installed inside the source tree.",
159160
)
161+
parser.add_argument(
162+
"--minimal",
163+
"-m",
164+
action="store_true",
165+
help="Only installs necessary dependencies for core executorch and skips "
166+
" packages necessary for running example scripts.",
167+
)
160168
return parser.parse_args()
161169

162170

@@ -182,9 +190,13 @@ def main(args):
182190
# This option is used in CI to make sure that PyTorch build from the pinned commit
183191
# is used instead of nightly. CI jobs wouldn't be able to catch regression from the
184192
# latest PT commit otherwise
185-
install_requirements(use_pytorch_nightly=not args.use_pt_pinned_commit)
186-
os.execvp(
187-
sys.executable,
193+
use_pytorch_nightly = not args.use_pt_pinned_commit
194+
195+
# Step 1: Install dependencies first
196+
install_requirements(use_pytorch_nightly)
197+
198+
# Step 2: Install core package
199+
cmd = (
188200
[
189201
sys.executable,
190202
"-m",
@@ -198,8 +210,13 @@ def main(args):
198210
"-v",
199211
"--extra-index-url",
200212
TORCH_NIGHTLY_URL,
201-
],
213+
]
202214
)
215+
subprocess.run(cmd, check=True)
216+
217+
# Step 3: Extra (optional) packages that is only useful for running examples.
218+
if not args.minimal:
219+
install_optional_example_requirements(use_pytorch_nightly)
203220

204221

205222
if __name__ == "__main__":

install_requirements.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,15 @@ def python_is_compatible():
7676

7777
def install_requirements(use_pytorch_nightly):
7878
# pip packages needed by exir.
79-
EXIR_REQUIREMENTS = [
79+
TORCH_PACKAGE = [
8080
# Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
8181
# that we don't need to set any version number there because they have already
8282
# been installed on CI before this step, so pip won't reinstall them
8383
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.
8984
]
9085

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
10088
# versions on the provided URL if they aren't available on the default URL.
10189
subprocess.run(
10290
[
@@ -105,10 +93,8 @@ def install_requirements(use_pytorch_nightly):
10593
"pip",
10694
"install",
10795
"-r",
108-
"requirements-examples.txt",
109-
"-r",
11096
"requirements-dev.txt",
111-
*REQUIREMENTS_TO_INSTALL,
97+
*TORCH_PACKAGE,
11298
"--extra-index-url",
11399
TORCH_NIGHTLY_URL,
114100
],
@@ -139,6 +125,44 @@ def install_requirements(use_pytorch_nightly):
139125
)
140126

141127

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+
142166
def main(args):
143167
parser = argparse.ArgumentParser()
144168
parser.add_argument(

requirements-dev.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# Pip packages needed to build from source. Mainly for development of ExecuTorch.
2+
13
cmake>=3.19, <4.0.0 # For building binary targets in the wheel.
24
pip>=23 # For building the pip package.
35
pyyaml # Imported by the kernel codegen tools.
46
setuptools>=63 # For building the pip package contents.
57
tomli # Imported by extract_sources.py when using python < 3.11.
68
wheel # For building the pip package archive.
79
zstd # Imported by resolve_buck.py.
10+
lintrunner==0.12.7
11+
lintrunner-adapters==0.12.4

requirements-lintrunner.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Lintrunner itself
2-
lintrunner==0.12.7
3-
lintrunner-adapters==0.12.4
4-
51
# Flake 8 and its dependencies
62
flake8==6.1.0
73
flake8-breakpoint==1.1.0

0 commit comments

Comments
 (0)