Welcome to the tutorial on setting up the ExecuTorch iOS Demo App!
This app uses the MobileNet v3 model to process live camera images leveraging three different backends: XNNPACK, Core ML and Metal Performance Shaders (MPS) (Xcode 15+ and iOS 17+ only).
Before we start, make sure you have the following tools installed:
Install Xcode 15 from the Mac App Store and then install the Command Line Tools using the terminal:
xcode-select --install
Python 3.10 or above, along with pip
, should be pre-installed on MacOS 13.5+.
If needed, download Python and
install it. Verify the Python and pip versions using these commands:
which python3 pip
python3 --version
pip --version
Clone ExecuTorch and set up the environment as explained in the Building from Source tutorial:
git clone -b viable/strict https://github.com/pytorch/executorch.git && cd executorch
python3 -m venv .venv && source .venv/bin/activate && pip install --upgrade pip
./install_executorch.sh
Install additional dependencies for Core ML and MPS backends:
./backends/apple/coreml/scripts/install_requirements.sh
./backends/apple/mps/install_requirements.sh
git clone --depth 1 https://github.com/pytorch-labs/executorch-examples.git
Now, let's move on to exporting and bundling the MobileNet v3 model.
Export the MobileNet v3 model with Core ML, MPS and XNNPACK backends, and move the exported model to a specific location where the Demo App will pick them up:
MODEL_NAME="mv3"
python3 -m examples.portable.scripts.export --model_name="$MODEL_NAME"
python3 -m examples.apple.coreml.scripts.export --model_name="$MODEL_NAME"
python3 -m examples.apple.mps.scripts.mps_example --model_name="$MODEL_NAME"
python3 -m examples.xnnpack.aot_compiler --model_name="$MODEL_NAME" --delegate
APP_PATH="executorch-examples/apple/ExecuTorchDemo/ExecuTorchDemo"
mkdir -p "$APP_PATH/Resources/Models/MobileNet/"
mv $MODEL_NAME*.pte "$APP_PATH/Resources/Models/MobileNet/"
Download the MobileNet model labels required for image classification:
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \
-o "$APP_PATH/Resources/Models/MobileNet/imagenet_classes.txt"
We're almost done! Now, we just need to open the project in Xcode, run the tests, and finally run the app.
Double-click on the project file under executorch-examples/apple/ExecuTorchDemo
or run the command:
open $APP_PATH.xcodeproj
You can run tests on Simulaltor directly in Xcode with Cmd + U
or use the command line:
xcrun simctl create executorch "iPhone 15"
xcodebuild clean test \
-project $APP_PATH.xcodeproj \
-scheme App \
-destination name=executorch
xcrun simctl delete executorch
Finally, connect the device, set up Code Signing in Xcode, and then run the app
using Cmd + R
. Try installing a Release build for better performance.
Congratulations! You've successfully set up the ExecuTorch iOS Demo App. Now, you can explore and enjoy the power of ExecuTorch on your iOS device!
Learn more about Using ExecuTorch on iOS.