Skip to content

Commit 38b36cb

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Provide an extra arg to install_requirements to optionally build pybindings. (#2396)
Summary: Pull Request resolved: #2396 bypass-github-export-checks Reviewed By: kirklandsign Differential Revision: D54840034 fbshipit-source-id: dc4b0e416ae7f093ff80bb336576b463eafd2b44
1 parent 4096dca commit 38b36cb

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

build/test_ios.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ curl -LO "https://github.com/facebook/buck2/releases/download/$BUCK2_RELEASE_DAT
7070
zstd -cdq "$BUCK2_ARCHIVE" > "$BUCK2" && chmod +x "$BUCK2"
7171
rm "$BUCK2_ARCHIVE"
7272

73-
./install_requirements.sh
73+
./install_requirements.sh --pybind coreml mps xnnpack
7474
export PATH="$(realpath third-party/flatbuffers/cmake-out):$PATH"
7575
./build/install_flatc.sh
7676

@@ -82,14 +82,6 @@ say "Installing MPS Backend Requirements"
8282

8383
./backends/apple/mps/install_requirements.sh
8484

85-
say "Installing Python Bindings"
86-
87-
EXECUTORCH_BUILD_PYBIND=ON \
88-
BUCK="$(pwd)/$BUCK2" \
89-
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON" \
90-
CMAKE_BUILD_PARALLEL_LEVEL=9 \
91-
pip install . --no-build-isolation -v
92-
9385
say "Exporting Models"
9486

9587
python3 -m examples.portable.scripts.export --model_name="$MODEL_NAME"

extension/pybindings/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,30 @@
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-
EXECUTORCH_BUILD_PYBIND=ON pip install . --no-build-isolation
5+
EXECUTORCH_BUILD_PYBIND=ON \
6+
pip install . --no-build-isolation
7+
```
8+
9+
Or when installing the rest of dependencies:
10+
11+
```bash
12+
install_requirements.sh --pybind
13+
```
14+
15+
# Link Backends
16+
17+
You can link the runtime against some backends to make sure a delegated or partitioned model can still run by Python module successfully:
18+
19+
```bash
20+
EXECUTORCH_BUILD_PYBIND=ON \
21+
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON" \
22+
pip install . --no-build-isolation
23+
```
24+
25+
Similarly, when installing the rest of dependencies:
26+
27+
```bash
28+
install_requirements.sh --pybind coreml mps xnnpack
629
```
730

831
## Functions

install_requirements.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ then
1717
PYTHON_EXECUTABLE=python3
1818
fi
1919

20+
# Parse options.
21+
EXECUTORCH_BUILD_PYBIND=OFF
22+
CMAKE_ARGS=""
23+
24+
for arg in "$@"; do
25+
case $arg in
26+
--pybind)
27+
EXECUTORCH_BUILD_PYBIND=ON
28+
;;
29+
coreml|mps|xnnpack)
30+
if [[ "$EXECUTORCH_BUILD_PYBIND" == "ON" ]]; then
31+
CMAKE_ARGS="$CMAKE_ARGS -DEXECUTORCH_BUILD_${arg^^}=ON"
32+
else
33+
echo "Error: $arg must follow --pybind"
34+
exit 1
35+
fi
36+
;;
37+
*)
38+
echo "Error: Unknown option $arg"
39+
exit 1
40+
;;
41+
esac
42+
done
43+
2044
# Install pytorch dependencies
2145
#
2246
# Note:
@@ -46,7 +70,10 @@ TORCHSR_VERSION=1.0.4
4670
pip install --pre torchsr==${TORCHSR_VERSION}
4771

4872
# Install ExecuTorch after dependencies are installed.
49-
pip install . --no-build-isolation
73+
EXECUTORCH_BUILD_PYBIND="$EXECUTORCH_BUILD_PYBIND" \
74+
CMAKE_ARGS="$CMAKE_ARGS" \
75+
CMAKE_BUILD_PARALLEL_LEVEL=9 \
76+
pip install . --no-build-isolation -v
5077

5178
# Install flatc dependency
5279
bash build/install_flatc.sh

0 commit comments

Comments
 (0)