Run ExecuTorch Llama 3.2 1B Instruct on an Android phone with Vulkan
Introduction
Prepare a Linux host and Android device for ExecuTorch Vulkan
Install ExecuTorch and download the model on the Linux host
Export the Vulkan PTE
Build the Android Vulkan runtime
Deploy and measure Llama 3.2 with ExecuTorch Vulkan on Android
Next Steps
Run ExecuTorch Llama 3.2 1B Instruct on an Android phone with Vulkan
Clone ExecuTorch 1.4
Keep a source checkout because you’ll cross-compile the Android runtime and the standalone Llama runner:
cd $HOME
git clone --branch release/1.4 --recursive https://github.com/pytorch/executorch.git
cd executorch
git submodule update --init --recursive
Create and activate a Python virtual environment:
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel
To reduce memory pressure during builds, set the following variable:
export CMAKE_BUILD_PARALLEL_LEVEL=2
Fix the PyTorch version mismatch
Always verify torch.__version__ before you start a long native build.
If you build the host envionment with PyTorch 2.14.0+cpu on the release/1.4 branch, the build breaks with the following message:
ATen/core/Tensor.h:70:37: error: 'C10_LIFETIMEBOUND' does not name a type
To avoid this, pin the expected version:
python -m pip uninstall -y torch
python -m pip install "torch==2.13.0+cpu" --index-url https://download.pytorch.org/whl/cpu
python -c "import torch; print(torch.__version__)"
The output is similar to:
2.13.0+cpu
Then, clean and rebuild the host package:
python install_executorch.py --clean
export CMAKE_BUILD_PARALLEL_LEVEL=2
./install_executorch.sh --use-pt-pinned-commit
Request access to Llama 3.2 1B Instruct
The model that you’ll use in this workflow comes from the gated Hugging Face repository
meta-llama/Llama-3.2-1B-Instruct
.
To request access:
- Sign in to your Hugging Face account.
- Open the Llama 3.2 1B Instruct model page.
- Review and accept the Meta Llama license, then submit the access request.
- Wait until Hugging Face confirms that your account can access the repository before continuing.
Access approval is associated with the Hugging Face account that submitted the request.
Install and authenticate the Hugging Face CLI
Install the Hugging Face Hub CLI in the active Python virtual environment:
python -m pip install --upgrade huggingface_hub
hf version
Sign in with the same account that you used to access the model. The command prompts you to authenticate through a browser or with a Hugging Face user access token:
hf auth login
hf auth whoami
Confirm that hf auth whoami displays the account that has access to the gated model.
Download Llama 3.2 1B Instruct
Keep the model outside the source tree:
hf download \
meta-llama/Llama-3.2-1B-Instruct \
--include "original/*" \
--local-dir ~/Llama-3.2-1B-Instruct
Verify that the three files required by the export are present:
test -f ~/Llama-3.2-1B-Instruct/original/consolidated.00.pth && echo "Checkpoint OK"
test -f ~/Llama-3.2-1B-Instruct/original/params.json && echo "Parameters OK"
test -f ~/Llama-3.2-1B-Instruct/original/tokenizer.model && echo "Tokenizer OK"
The example measured run used:
consolidated.00.pthat about 2.4 GBparams.jsontokenizer.modelat about 2.1 MB
If the download returns 401 Unauthorized or 403 Forbidden, run hf auth whoami and confirm that you authenticated with the account approved for the gated repository.
If access is still pending, return to the model page and check the request status.
What you’ve accomplished and what’s next
You’ve now prepared the ExecuTorch source and Python environment. You’ve also requested and gained access to the Llama 3.2 1B Instruct model.
Next, you’ll export the Vulkan PTE.