Skip to content

Install examples and domain libraries as last (optional) step #11653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions install_executorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from contextlib import contextmanager

from install_requirements import (
install_optional_example_requirements,
install_requirements,
python_is_compatible,
TORCH_NIGHTLY_URL,
Expand Down Expand Up @@ -157,6 +158,13 @@ def _parse_args() -> argparse.Namespace:
"picked up without rebuilding the wheel. Extension libraries will be "
"installed inside the source tree.",
)
parser.add_argument(
"--minimal",
"-m",
action="store_true",
help="Only installs necessary dependencies for core executorch and skips "
" packages necessary for running example scripts.",
)
return parser.parse_args()


Expand All @@ -182,9 +190,13 @@ def main(args):
# This option is used in CI to make sure that PyTorch build from the pinned commit
# is used instead of nightly. CI jobs wouldn't be able to catch regression from the
# latest PT commit otherwise
install_requirements(use_pytorch_nightly=not args.use_pt_pinned_commit)
os.execvp(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change back from os.execvp to subprocess since install_optional_example_requirement is never reachable because os.execvp completely replaces the current process with the pip install command

sys.executable,
use_pytorch_nightly = not args.use_pt_pinned_commit

# Step 1: Install core dependencies first
install_requirements(use_pytorch_nightly)

# Step 2: Install core package
cmd = (
[
sys.executable,
"-m",
Expand All @@ -198,8 +210,13 @@ def main(args):
"-v",
"--extra-index-url",
TORCH_NIGHTLY_URL,
],
]
)
subprocess.run(cmd, check=True)

# Step 3: Extra (optional) packages that is only useful for running examples.
if not args.minimal:
install_optional_example_requirements(use_pytorch_nightly)


if __name__ == "__main__":
Expand Down
70 changes: 51 additions & 19 deletions install_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,15 @@ def python_is_compatible():

def install_requirements(use_pytorch_nightly):
# pip packages needed by exir.
EXIR_REQUIREMENTS = [
TORCH_PACKAGE = [
# Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
# that we don't need to set any version number there because they have already
# been installed on CI before this step, so pip won't reinstall them
f"torch==2.8.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torch",
(
f"torchvision==0.23.0.{NIGHTLY_VERSION}"
if use_pytorch_nightly
else "torchvision"
), # For testing.
]

EXAMPLES_REQUIREMENTS = [
f"torchaudio==2.8.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torchaudio",
]

# Assemble the list of requirements to actually install.
# TODO: Add options for reducing the number of requirements.
REQUIREMENTS_TO_INSTALL = EXIR_REQUIREMENTS + EXAMPLES_REQUIREMENTS

# Install the requirements. `--extra-index-url` tells pip to look for package
# Install the requirements for core ExecuTorch package.
# `--extra-index-url` tells pip to look for package
# versions on the provided URL if they aren't available on the default URL.
subprocess.run(
[
Expand All @@ -105,10 +93,8 @@ def install_requirements(use_pytorch_nightly):
"pip",
"install",
"-r",
"requirements-examples.txt",
"-r",
"requirements-dev.txt",
*REQUIREMENTS_TO_INSTALL,
*TORCH_PACKAGE,
"--extra-index-url",
TORCH_NIGHTLY_URL,
],
Expand Down Expand Up @@ -139,15 +125,61 @@ def install_requirements(use_pytorch_nightly):
)


def install_optional_example_requirements(use_pytorch_nightly):
print("Installing packages in requirements-examples.txt")
subprocess.run(
[
sys.executable,
"-m",
"pip",
"install",
"-r",
"requirements-examples.txt",
],
check=True,
)

print("Installing torch domain libraries")
DOMAIN_LIBRARIES = [
(
f"torchvision==0.23.0.{NIGHTLY_VERSION}"
if use_pytorch_nightly
else "torchvision"
),
f"torchaudio==2.8.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torchaudio",
]
# Then install domain libraries
subprocess.run(
[
sys.executable,
"-m",
"pip",
"install",
*DOMAIN_LIBRARIES,
"--extra-index-url",
TORCH_NIGHTLY_URL,
],
check=True,
)


def main(args):
parser = argparse.ArgumentParser()
parser.add_argument(
"--use-pt-pinned-commit",
action="store_true",
help="build from the pinned PyTorch commit instead of nightly",
)
parser.add_argument(
"--example",
action="store_true",
help="Also installs required packages for running example scripts.",
)
args = parser.parse_args(args)
install_requirements(use_pytorch_nightly=not bool(args.use_pt_pinned_commit))
use_pytorch_nightly=not bool(args.use_pt_pinned_commit)
install_requirements(use_pytorch_nightly)
if args.example:
install_optional_example_requirements(use_pytorch_nightly)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Pip packages needed to build from source. Mainly for development of ExecuTorch.

cmake>=3.19, <4.0.0 # For building binary targets in the wheel.
pip>=23 # For building the pip package.
pyyaml # Imported by the kernel codegen tools.
setuptools>=63 # For building the pip package contents.
tomli # Imported by extract_sources.py when using python < 3.11.
wheel # For building the pip package archive.
zstd # Imported by resolve_buck.py.
lintrunner==0.12.7
lintrunner-adapters==0.12.4
4 changes: 0 additions & 4 deletions requirements-lintrunner.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Lintrunner itself
lintrunner==0.12.7
lintrunner-adapters==0.12.4

# Flake 8 and its dependencies
flake8==6.1.0
flake8-breakpoint==1.1.0
Expand Down
Loading