Skip to content

Commit 9dc5152

Browse files
authored
Update install_requirements to install --pybind xnnpack by default. (#7473)
Summary: Regular ./install_requirements.sh will install pybind xnnpack by default. It is necessary for Llama for instance. It is still backwards compatible with './install_requirements.sh --pybind xnnpack' One can also turn off explicitly by calling './install_requirement.sh --pybind off' Test Plan: Test valid options: ./install_requirements.sh ./install_requirements.sh --pybind xnnpack ./install_requirements.sh --pybind coreml ./install_requirements.sh --pybind coreml xnnpack ./install_requirements.sh --pybind off Invalid options: ./install_requirements.sh xnnpack ./install_requirements.sh --pybind coreml off ./install_requirements.sh --pybind coreml xnnpack off ./install_requirements.sh off
1 parent 45bb2dd commit 9dc5152

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

docs/source/getting-started-setup.md

+12
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,19 @@ Alternatively, if you would like to experiment with ExecuTorch quickly and easil
9898
Use the [`--pybind` flag](https://github.com/pytorch/executorch/blob/main/install_requirements.sh#L26-L29) to install with pybindings and dependencies for other backends.
9999
```bash
100100
./install_requirements.sh --pybind <coreml | mps | xnnpack>
101+
102+
# Example: pybindings with CoreML *only*
103+
./install_requirements.sh --pybind coreml
104+
105+
# Example: pybinds with CoreML *and* XNNPACK
106+
./install_requirements.sh --pybind coreml xnnpack
107+
```
108+
109+
By default, `./install_requirements.sh` command installs pybindings for XNNPACK. To disable any pybindings altogether:
110+
```bash
111+
./install_requirements.sh --pybind off
101112
```
113+
102114
After setting up your environment, you are ready to convert your PyTorch programs
103115
to ExecuTorch.
104116

install_requirements.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,34 @@ def python_is_compatible():
6666
sys.exit(1)
6767

6868
# Parse options.
69-
EXECUTORCH_BUILD_PYBIND = "OFF"
69+
70+
EXECUTORCH_BUILD_PYBIND = ""
7071
CMAKE_ARGS = os.getenv("CMAKE_ARGS", "")
7172
CMAKE_BUILD_ARGS = os.getenv("CMAKE_BUILD_ARGS", "")
7273
USE_PYTORCH_NIGHTLY = True
7374

74-
for arg in sys.argv[1:]:
75+
args = sys.argv[1:]
76+
for arg in args:
7577
if arg == "--pybind":
76-
EXECUTORCH_BUILD_PYBIND = "ON"
78+
pass
7779
elif arg in ["coreml", "mps", "xnnpack"]:
78-
if EXECUTORCH_BUILD_PYBIND == "ON":
80+
if "--pybind" in args:
7981
arg_upper = arg.upper()
82+
EXECUTORCH_BUILD_PYBIND = "ON"
8083
CMAKE_ARGS += f" -DEXECUTORCH_BUILD_{arg_upper}=ON"
8184
else:
8285
print(f"Error: {arg} must follow --pybind")
8386
sys.exit(1)
87+
elif arg == "off":
88+
if "--pybind" in args:
89+
if EXECUTORCH_BUILD_PYBIND == "ON":
90+
print("Cannot turnoff pybind option as it is already set.")
91+
sys.exit(1)
92+
EXECUTORCH_BUILD_PYBIND = "OFF"
93+
else:
94+
print(f"Error: {arg} must follow --pybind")
95+
sys.exit(1)
96+
8497
elif arg == "--clean":
8598
print("Cleaning build artifacts...")
8699
print("Cleaning pip-out/...")
@@ -100,6 +113,13 @@ def python_is_compatible():
100113
print(f"Error: Unknown option {arg}")
101114
sys.exit(1)
102115

116+
# If --pybind is not set explicitly for backends (e.g., --pybind xnnpack)
117+
# or is not turned off explicitly (--pybind off)
118+
# then install XNNPACK by default.
119+
if EXECUTORCH_BUILD_PYBIND == "":
120+
EXECUTORCH_BUILD_PYBIND = "ON"
121+
CMAKE_ARGS += " -DEXECUTORCH_BUILD_XNNPACK=ON"
122+
103123
# Use ClangCL on Windows.
104124
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
105125
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.

0 commit comments

Comments
 (0)