Skip to content

Commit 66dfc46

Browse files
authored
Remove the ability to choose pybinding when installing ExecuTorch (#11233)
### Summary Fixes #11176 ### Test plan CI ``` rg "\-\-pybind" --hidden -g '!**/{third-party,.git}' ```
1 parent 809a1fd commit 66dfc46

File tree

9 files changed

+29
-113
lines changed

9 files changed

+29
-113
lines changed

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ jobs:
305305
# Install requirements
306306
${CONDA_RUN} sh install_requirements.sh
307307
${CONDA_RUN} sh backends/apple/coreml/scripts/install_requirements.sh
308-
${CONDA_RUN} python install_executorch.py --pybind coreml
308+
${CONDA_RUN} python install_executorch.py
309309
${CONDA_RUN} sh examples/models/llama/install_requirements.sh
310310
311311
# Test ANE llama

backends/apple/mps/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ I 00:00:00.122615 executorch:mps_executor_runner.mm:501] Model verified successf
9191
### [Optional] Run the generated model directly using pybind
9292
1. Make sure `pybind` MPS support was installed:
9393
```bash
94-
./install_executorch.sh --pybind mps
94+
CMAKE_ARGS="-DEXECUTORCH_BUILD_MPS=ON" ./install_executorch.sh
9595
```
9696
2. Run the `mps_example` script to trace the model and run it directly from python:
9797
```bash

docs/source/backends-mps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ I 00:00:00.122615 executorch:mps_executor_runner.mm:501] Model verified successf
9191
### [Optional] Run the generated model directly using pybind
9292
1. Make sure `pybind` MPS support was installed:
9393
```bash
94-
./install_executorch.sh --pybind mps
94+
CMAKE_ARGS="-DEXECUTORCH_BUILD_MPS=ON" ./install_executorch.sh
9595
```
9696
2. Run the `mps_example` script to trace the model and run it directly from python:
9797
```bash

docs/source/using-executorch-building-from-source.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,15 @@ Or alternatively, [install conda on your machine](https://conda.io/projects/cond
6464
./install_executorch.sh
6565
```
6666

67-
Use the [`--pybind` flag](https://github.com/pytorch/executorch/blob/main/install_executorch.sh#L26-L29) to install with pybindings and dependencies for other backends.
68-
```bash
69-
./install_executorch.sh --pybind <coreml | mps | xnnpack>
70-
71-
# Example: pybindings with CoreML *only*
72-
./install_executorch.sh --pybind coreml
73-
74-
# Example: pybinds with CoreML *and* XNNPACK
75-
./install_executorch.sh --pybind coreml xnnpack
76-
```
67+
Not all backends are built into the pip wheel by default. You can link these missing/experimental backends by turning on the corresponding cmake flag. For example, to include the MPS backend:
7768

78-
By default, `./install_executorch.sh` command installs pybindings for XNNPACK. To disable any pybindings altogether:
79-
```bash
80-
./install_executorch.sh --pybind off
81-
```
69+
```bash
70+
CMAKE_ARGS="-DEXECUTORCH_BUILD_MPS=ON" ./install_executorch.sh
71+
```
8272

8373
For development mode, run the command with `--editable`, which allows us to modify Python source code and see changes reflected immediately.
8474
```bash
85-
./install_executorch.sh --editable [--pybind xnnpack]
75+
./install_executorch.sh --editable
8676

8777
# Or you can directly do the following if dependencies are already installed
8878
# either via a previous invocation of `./install_executorch.sh` or by explicitly installing requirements via `./install_requirements.sh` first.

examples/demo-apps/react-native/rnllama/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A React Native mobile application for running LLaMA language models using ExecuT
2626

2727
3. Pull submodules: `git submodule sync && git submodule update --init`
2828

29-
4. Install dependencies: `./install_executorch.sh --pybind xnnpack && ./examples/models/llama/install_requirements.sh`
29+
4. Install dependencies: `./install_executorch.sh && ./examples/models/llama/install_requirements.sh`
3030

3131
5. Follow the instructions in the [README](https://github.com/pytorch/executorch/blob/main/examples/models/llama/README.md#option-a-download-and-export-llama32-1b3b-model) to export a model as `.pte`
3232

examples/models/llama/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Llama 3 8B performance was measured on the Samsung Galaxy S22, S24, and OnePlus
148148
## Step 1: Setup
149149
> :warning: **double check your python environment**: make sure `conda activate <VENV>` is run before all the bash and python scripts.
150150
151-
1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_executorch.sh --pybind xnnpack`
151+
1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_executorch.sh`
152152
2. Run `examples/models/llama/install_requirements.sh` to install a few dependencies.
153153

154154

@@ -528,7 +528,7 @@ This example tries to reuse the Python code, with minimal modifications to make
528528
git clean -xfd
529529
pip uninstall executorch
530530
./install_executorch.sh --clean
531-
./install_executorch.sh --pybind xnnpack
531+
./install_executorch.sh
532532
```
533533
- If you encounter `pthread` related issues during link time, add `pthread` in `target_link_libraries` in `CMakeLists.txt`
534534
- On Mac, if there is linking error in Step 4 with error message like

examples/models/phi-3-mini/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This example demonstrates how to run a [Phi-3-mini](https://huggingface.co/micro
33

44
# Instructions
55
## Step 1: Setup
6-
1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_executorch.sh --pybind xnnpack`
6+
1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_executorch.sh`
77
2. Currently, we support transformers v4.44.2. Install transformers with the following command:
88
```
99
pip uninstall -y transformers ; pip install transformers==4.44.2

extension/pybindings/README.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,18 @@
22
This Python module, named `portable_lib`, provides a set of functions and classes for loading and executing bundled programs. To install it, run the fullowing command:
33

44
```bash
5-
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON" pip install . --no-build-isolation
6-
```
7-
8-
Or when installing the rest of dependencies:
5+
./install_executorch.sh
96

10-
```bash
11-
install_executorch.sh --pybind
7+
# ...or use pip directly
8+
pip install . --no-build-isolation
129
```
1310

1411
# Link Backends
1512

16-
You can link the runtime against some backends to make sure a delegated or partitioned model can still run by Python module successfully:
17-
18-
```bash
19-
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON" \
20-
pip install . --no-build-isolation
21-
```
22-
23-
Similarly, when installing the rest of dependencies:
13+
Not all backends are built into the pip wheel by default. You can link these missing/experimental backends by turning on the corresponding cmake flag. For example, to include the MPS backend:
2414

2515
```bash
26-
install_executorch.sh --pybind xnnpack coreml mps
16+
CMAKE_ARGS="-DEXECUTORCH_BUILD_MPS=ON" ./install_executorch.sh
2717
```
2818

2919
## Functions

install_executorch.py

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
import argparse
1010
import glob
11-
import itertools
1211
import logging
1312
import os
1413
import shutil
1514
import subprocess
1615
import sys
1716
from contextlib import contextmanager
18-
from typing import List, Tuple
1917

2018
from install_requirements import (
2119
install_requirements,
@@ -52,10 +50,6 @@ def clean():
5250
print("Done cleaning build artifacts.")
5351

5452

55-
# Please keep this insync with `ShouldBuild.pybindings` in setup.py.
56-
VALID_PYBINDS = ["coreml", "mps", "xnnpack", "training", "openvino"]
57-
58-
5953
################################################################################
6054
# Git submodules
6155
################################################################################
@@ -139,14 +133,9 @@ def check_folder(folder: str, file: str) -> bool:
139133
logger.info("All required submodules are present.")
140134

141135

142-
def build_args_parser() -> argparse.ArgumentParser:
143-
# Parse options.
144-
parser = argparse.ArgumentParser()
145-
parser.add_argument(
146-
"--pybind",
147-
action="append",
148-
nargs="+",
149-
help="one or more of coreml/mps/xnnpack, or off",
136+
def _parse_args() -> argparse.Namespace:
137+
parser = argparse.ArgumentParser(
138+
description="Install executorch in your Python environment."
150139
)
151140
parser.add_argument(
152141
"--clean",
@@ -166,83 +155,34 @@ def build_args_parser() -> argparse.ArgumentParser:
166155
"picked up without rebuilding the wheel. Extension libraries will be "
167156
"installed inside the source tree.",
168157
)
169-
return parser
170-
171-
172-
# Returns (wants_off, wanted_pybindings)
173-
def _list_pybind_defines(args) -> Tuple[bool, List[str]]:
174-
if args.pybind is None:
175-
return False, []
176-
177-
# Flatten list of lists.
178-
args.pybind = list(itertools.chain(*args.pybind))
179-
if "off" in args.pybind:
180-
if len(args.pybind) != 1:
181-
raise Exception(f"Cannot combine `off` with other pybinds: {args.pybind}")
182-
return True, []
183-
184-
cmake_args = []
185-
for pybind_arg in args.pybind:
186-
if pybind_arg not in VALID_PYBINDS:
187-
raise Exception(
188-
f"Unrecognized pybind argument {pybind_arg}; valid options are: {', '.join(VALID_PYBINDS)}"
189-
)
190-
if pybind_arg == "training":
191-
cmake_args.append("-DEXECUTORCH_BUILD_EXTENSION_TRAINING=ON")
192-
else:
193-
cmake_args.append(f"-DEXECUTORCH_BUILD_{pybind_arg.upper()}=ON")
194-
195-
return False, cmake_args
158+
return parser.parse_args()
196159

197160

198161
def main(args):
199162
if not python_is_compatible():
200163
sys.exit(1)
201164

202-
parser = build_args_parser()
203-
args = parser.parse_args()
204-
205-
cmake_args = [os.getenv("CMAKE_ARGS", "")]
206-
use_pytorch_nightly = True
207-
208-
wants_pybindings_off, pybind_defines = _list_pybind_defines(args)
209-
if wants_pybindings_off:
210-
cmake_args.append("-DEXECUTORCH_BUILD_PYBIND=OFF")
211-
else:
212-
cmake_args += pybind_defines
165+
args = _parse_args()
213166

214167
if args.clean:
215168
clean()
216169
return
217170

218-
if args.use_pt_pinned_commit:
219-
# This option is used in CI to make sure that PyTorch build from the pinned commit
220-
# is used instead of nightly. CI jobs wouldn't be able to catch regression from the
221-
# latest PT commit otherwise
222-
use_pytorch_nightly = False
223-
171+
cmake_args = [os.getenv("CMAKE_ARGS", "")]
224172
# Use ClangCL on Windows.
225173
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
226174
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
227175
if os.name == "nt":
228176
cmake_args.append("-T ClangCL")
229-
230-
#
231-
# Install executorch pip package. This also makes `flatc` available on the path.
232-
# The --extra-index-url may be necessary if pyproject.toml has a dependency on a
233-
# pre-release or nightly version of a torch package.
234-
#
235-
236-
# Set environment variables
237177
os.environ["CMAKE_ARGS"] = " ".join(cmake_args)
238178

239-
# Check if the required submodules are present and update them if not
240179
check_and_update_submodules()
241-
242-
install_requirements(use_pytorch_nightly)
243-
244-
# Run the pip install command
245-
subprocess.run(
180+
# This option is used in CI to make sure that PyTorch build from the pinned commit
181+
# is used instead of nightly. CI jobs wouldn't be able to catch regression from the
182+
# latest PT commit otherwise
183+
install_requirements(use_pytorch_nightly=not args.use_pt_pinned_commit)
184+
os.execvp(
185+
sys.executable,
246186
[
247187
sys.executable,
248188
"-m",
@@ -257,14 +197,10 @@ def main(args):
257197
"--extra-index-url",
258198
TORCH_NIGHTLY_URL,
259199
],
260-
check=True,
261200
)
262201

263202

264203
if __name__ == "__main__":
265204
# Before doing anything, cd to the directory containing this script.
266205
os.chdir(os.path.dirname(os.path.abspath(__file__)))
267-
if not python_is_compatible():
268-
sys.exit(1)
269-
270206
main(sys.argv[1:])

0 commit comments

Comments
 (0)