### Installing additional Python packages Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/README.md Command to install necessary Python packages for the examples. ```bash pip install scikit-learn pandas graphviz ``` -------------------------------- ### Install Transformers Source: https://github.com/pytorch/executorch/blob/main/examples/models/phi-3-mini/README.md Installs the required version of the transformers library. ```bash pip uninstall -y transformers ; pip install transformers==4.56.1 ``` -------------------------------- ### Install optimum-executorch Source: https://github.com/pytorch/executorch/blob/main/examples/models/phi-3-mini/README.md Installs the optimum-executorch package from a specific commit. ```bash OPTIMUM_ET_VERSION=$(cat .ci/docker/ci_commit_pins/optimum-executorch.txt) pip install git+https://github.com/huggingface/optimum-executorch.git@${OPTIMUM_ET_VERSION} ``` -------------------------------- ### Getting Help for Quantized Example Models Source: https://github.com/pytorch/executorch/blob/main/examples/xnnpack/README.md Command to find more valid quantized example models. ```bash python3 -m examples.xnnpack.quantization.example --help ``` -------------------------------- ### Install Optimum ExecuTorch from source Source: https://github.com/pytorch/executorch/blob/main/examples/models/gemma3/README.md Installs the Optimum ExecuTorch library from its source repository. ```bash git clone https://github.com/huggingface/optimum-executorch.git cd optimum-executorch python install_dev.py ``` -------------------------------- ### CMakeLists.txt Configuration for ExecuTorch Source: https://github.com/pytorch/executorch/blob/main/docs/source/getting-started.md Example CMakeLists.txt configuration for integrating ExecuTorch into a C++ project. ```cmake # Set CMAKE_CXX_STANDARD to 17 or above. set(CMAKE_CXX_STANDARD 17) # CMakeLists.txt set(EXECUTORCH_BUILD_PRESET_FILE ${CMAKE_SOURCE_DIR}/executorch/tools/cmake/preset/llm.cmake) # Set other ExecuTorch options here. add_subdirectory("executorch") ... target_link_libraries( my_target PRIVATE executorch executorch::backends executorch::extensions executorch::kernels) ``` -------------------------------- ### Setup Arm toolchain and FVP Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/arm-cortex-m/arm-cortex-m-overview.md One-time setup command to install the Arm toolchain and FVP. ```bash # One-time: install the Arm toolchain + FVP. examples/arm/setup.sh --i-agree-to-the-contained-eula source examples/arm/arm-scratch/setup_path.sh ``` -------------------------------- ### Include Directories Setup Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/CMakeLists.txt Sets common include directories for the project. ```cmake # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include ) ``` -------------------------------- ### Running Ethos-U minimal example in a notebook Source: https://github.com/pytorch/executorch/blob/main/examples/arm/README.md Instructions to install Jupyter and run the Ethos-U minimal example notebook. ```bash pip install jupyter jupyter notebook ethos_u_minimal_example.ipynb ``` -------------------------------- ### Install Optimum ExecuTorch via pip Source: https://github.com/pytorch/executorch/blob/main/examples/models/gemma3/README.md Installs the Optimum ExecuTorch library using pip. ```bash pip install optimum-executorch ``` -------------------------------- ### Environment Setup Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/template/tutorials/backend-basic-tutorial.md Commands to create a Conda environment, activate it, and install the ExecuTorch Python package. ```bash conda create -y --name executorch python=3.12 conda activate executorch conda install executorch ``` -------------------------------- ### Executorch and Dependencies Setup Source: https://github.com/pytorch/executorch/blob/main/examples/models/llama/CMakeLists.txt Configures Python executable, Executorch and PyTorch roots, and finds necessary packages like executorch and gflags. ```cmake if(NOT PYTHON_EXECUTABLE) set(PYTHON_EXECUTABLE python3) endif() set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) if(NOT PYTHON_EXECUTABLE) resolve_python_executable() endif() if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) # Can't set to 11 due to executor_runner.cpp make_unique endif() if(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") set(CMAKE_TOOLCHAIN_IOS ON) else() set(CMAKE_TOOLCHAIN_IOS OFF) endif() set(_common_compile_options -Wno-deprecated-declarations -fPIC) # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/..) # For some reason android build is not able to find where gflags is and hence # cannot find corresponding .cmake file set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) find_package(gflags REQUIRED) # # llama_main: test binary to run llama, with tokenizer and sampler integrated # # find `executorch` libraries. CMAKE_PREFIX_PATH would work for host # compilation, but CMAKE_FIND_ROOT_PATH appears to be necessary for # cross-compiling (e.g., to Android) to work as well. list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) executorch_target_link_options_shared_lib(executorch) ``` -------------------------------- ### Project Setup and Variable Definitions Source: https://github.com/pytorch/executorch/blob/main/examples/nxp/executor_runner/CMakeLists.txt Initializes the CMake version, project name, and defines key variables like EIQ_NEUTRON_TARGET and EXECUTORCH_PATH. ```cmake cmake_minimum_required(VERSION 3.16) project(nxp_executor_runner C CXX) set(EIQ_NEUTRON_TARGET "imxrt700" CACHE STRING "Neutron Target to build the executor_runner" ) set(EXECUTORCH_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../) ``` -------------------------------- ### Quick Start Setup Script Source: https://github.com/pytorch/executorch/blob/main/examples/riscv/README.md Shell script to set up the necessary packages for RISC-V cross-compilation on Ubuntu/Debian. ```bash examples/riscv/setup.sh # apt: gcc-riscv64-linux-gnu, qemu-user-static ``` -------------------------------- ### QWEN2.5 0.5B Default Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md Default example using hybrid mode for QWEN2.5 0.5B model. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --max_seq_len 1024 --prefill_ar_len 128 --decoder_model qwen2_5-0_5b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Install eIQ Neutron dependencies (again) Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/nxp/tutorials/nxp-basic-tutorial.md Ensures the eIQ Neutron dependencies are installed. ```bash $ ./examples/nxp/setup.sh ``` -------------------------------- ### QWEN3 0.6B Default Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md Default example using hybrid mode for QWEN3 0.6B model. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --max_seq_len 1024 --prefill_ar_len 128 --decoder_model qwen3-0_6b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Install ExecuTorch Python package (prebuilt) Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/nxp/tutorials/nxp-basic-tutorial.md Installs the ExecuTorch Python package using Conda. ```bash conda install executorch ``` -------------------------------- ### QWEN3 1.7B Default Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md Default example using hybrid mode for QWEN3 1.7B model. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --prefill_ar_len 128 --max_seq_len 1024 --decoder_model qwen3-1_7b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Check Model Converter Installation Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/arm-vgf/tutorials/vgf-getting-started.md A simple command to verify that the 'model-converter' executable is installed and accessible in the expected location within the 'examples/arm' directory. ```bash which model-converter ``` -------------------------------- ### QWEN2.5 1.5B Default Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md Default example using hybrid mode for QWEN2.5 1.5B model. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --prefill_ar_len 128 --max_seq_len 1024 --decoder_model qwen2_5-1_5b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Install eIQ Neutron dependencies Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/nxp/tutorials/nxp-basic-tutorial.md This command installs the Neutron Converter, eIQ Neutron SDK, and eIQ NSYS, which are necessary for working with the eIQ Neutron NPU. ```bash examples/nxp/setup.sh ``` -------------------------------- ### Example setup for CUDA-Windows export on Ubuntu Source: https://github.com/pytorch/executorch/blob/main/examples/models/voxtral/README.md Sets up the necessary cross-compiler and downloads/extracts the Windows CUDA installer package for cross-compilation. ```bash # 1) Install cross-compiler + extraction tools sudo apt-get update sudo apt-get install -y --no-install-recommends \ g++-mingw-w64-x86-64-posix mingw-w64-tools p7zip-full wget # 2) Verify cross-compiler x86_64-w64-mingw32-g++ --version # 3) Download and extract Windows CUDA installer package CUDA_VERSION=12.8.1 CUDA_DRIVER_VERSION=572.61 CUDA_INSTALLER="cuda_${CUDA_VERSION}_${CUDA_DRIVER_VERSION}_windows.exe" CUDA_URL="https://developer.download.nvidia.com/compute/cuda/${CUDA_VERSION}/local_installers/${CUDA_INSTALLER}" mkdir -p /opt/cuda-windows cd /opt/cuda-windows wget -q "${CUDA_URL}" -O "${CUDA_INSTALLER}" 7z x "${CUDA_INSTALLER}" -oextracted -y # 4) Point WINDOWS_CUDA_HOME to extracted Windows CUDA payload export WINDOWS_CUDA_HOME=/opt/cuda-windows/extracted/cuda_cudart/cudart ``` -------------------------------- ### Static Backend Registration Example Source: https://github.com/pytorch/executorch/blob/main/docs/source/compiler-delegate-and-partitioner.md Example demonstrating static registration of a backend at library initialization or load time. ```cpp namespace { auto cls = BackendWithCompiler(); Backend backend{"BackendWithCompilerDemo", &cls}; static auto success_with_compiler = register_backend(backend); } // namespace ``` -------------------------------- ### Install Requirements Source: https://github.com/pytorch/executorch/blob/main/examples/models/phi-3-mini-lora/README.md Installs Python requirements for the Phi-3-mini-LoRA example. ```shell ./examples/models/phi-3-mini-lora/install_requirements.sh ``` -------------------------------- ### Install VGF Dependencies Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/arm-vgf/tutorials/vgf-getting-started.md This command installs necessary SDK dependencies for generating VGF files, including TOSA Serialization Library, ML SDK Model Converter, Vulkan API, and ML Emulation Layer for Vulkan. ```bash ./examples/arm/setup.sh --i-agree-to-the-contained-eula --disable-ethos-u-deps --enable-mlsdk-deps ``` -------------------------------- ### Install ExecuTorch using uv Source: https://github.com/pytorch/executorch/blob/main/extension/training/examples/CIFAR/README.md Commands to clone the ExecuTorch repository, set up a Python environment with uv, and install ExecuTorch. ```bash git clone https://github.com/pytorch/executorch.git --recurse-submodules cd executorch uv venv --seed --prompt et --python 3.10 source .venv/bin/activate git fetch origin git submodule sync --recursive git submodule update --init --recursive ./install_executorch.sh ``` -------------------------------- ### NeutronDriver API example Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/nxp/tutorials/nxp-basic-tutorial.md Illustrates how to set paths for the NSYS simulator, Neutron Firmware, and NSYS configuration using the NeutronDriver API. ```c++ storeNsysConfigPath(FLAGS_nsys_config.c_str()); storeFirmwarePath(FLAGS_firmware.c_str()); storeNsysPath(FLAGS_nsys.c_str()); ``` -------------------------------- ### Run Gemma3 1B Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for Gemma3 1B using hybrid mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --max_seq_len 1024 --prefill_ar_len 128 --decoder_model gemma3-1b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Project and Options Configuration Source: https://github.com/pytorch/executorch/blob/main/examples/models/llama/CMakeLists.txt Sets up the minimum CMake version, project name, and options for building optimized kernels and libraries like pthreadpool and cpuinfo. ```cmake cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE project(llama_runner) # Duplicating options as root CMakeLists.txt option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED "Build the optimized kernels" OFF) include(CMakeDependentOption) # # pthreadpool: build pthreadpool library. Disable on unsupported platforms # cmake_dependent_option( EXECUTORCH_BUILD_PTHREADPOOL "Build pthreadpool library." ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF ) # # cpuinfo: build cpuinfo library. Disable on unsupported platforms # cmake_dependent_option( EXECUTORCH_BUILD_CPUINFO "Build cpuinfo library." ON "NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF ) option(EXECUTORCH_BUILD_KERNELS_TORCHAO_MPS "Build the torchao MPS kernels" OFF) ``` -------------------------------- ### Requirements Source: https://github.com/pytorch/executorch/blob/main/backends/mlx/examples/llm/README.md Installs necessary Python packages for the example. ```bash pip install transformers optimum-executorch ``` -------------------------------- ### Run LLAMA3.2 1B Instruct Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for LLAMA3.2 1B Instruct using hybrid mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --checkpoint consolidated.00.pth --params params.json --tokenizer_model tokenizer.model --decoder_model llama3_2-1b_instruct --model_mode hybrid --prefill_ar_len 128 --max_seq_len 1024 --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Install Executorch Dependencies Source: https://github.com/pytorch/executorch/blob/main/examples/demo-apps/react-native/rnllama/README.md Installs necessary dependencies for Executorch. ```bash ./install_executorch.sh && ./examples/models/llama/install_requirements.sh ``` -------------------------------- ### Running example scripts with shared buffer Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/README.md Command to run example scripts with shared buffer enabled for inference. ```bash python mobilenet_v2.py -s -m "SM8550" -b path/to/build-android/ -d /path/to/imagenet-mini/val --shared_buffer ``` -------------------------------- ### AOT Compilation Example Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/arm-vgf/tutorials/vgf-getting-started.md This Python code demonstrates how to quantize a simple PyTorch model (AddSigmoid) and export it through the AOT flow using the VGF backend. It includes model definition, input preparation, export, and quantization configuration using ExecuTorch and TorchAO libraries. ```python import torch class AddSigmoid(torch.nn.Module): def __init__(self): super().__init__() self.sigmoid = torch.nn.Sigmoid() def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: return self.sigmoid(x + y) example_inputs = (torch.ones(1,1,1,1),torch.ones(1,1,1,1)) model = AddSigmoid() model = model.eval() exported_program = torch.export.export(model, example_inputs) graph_module = exported_program.module(check_guards=False) from executorch.backends.arm.quantizer import ( VgfQuantizer, get_symmetric_quantization_config, ) from executorch.backends.arm.vgf import VgfCompileSpec from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e # Create a compilation spec describing the target for configuring the quantizer compile_spec = VgfCompileSpec() # Create and configure quantizer to use a symmetric quantization config globally on all nodes quantizer = VgfQuantizer(compile_spec) operator_config = get_symmetric_quantization_config(is_per_channel=False) # Set global (default) quantization config for the layers in the models. # Can also be set to `None` to let layers run in FP as default. quantizer.set_global(operator_config) # Skip quantizing all sigmoid ops (only one for this model); let it run in FP. # This step is optional; selecting which layers to include/exclude for # quantization is part of optimizing the model's performance. quantizer.set_module_type(torch.nn.Sigmoid, None) ``` -------------------------------- ### Main CMake Configuration Source: https://github.com/pytorch/executorch/blob/main/examples/models/voxtral_realtime/CMakeLists.txt Sets up the minimum CMake version, project name, C++ standard, and root directory for ExecuTorch. ```cmake cmake_minimum_required(VERSION 3.24) project(voxtral_realtime) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) ``` -------------------------------- ### Install RN Dependencies Source: https://github.com/pytorch/executorch/blob/main/examples/demo-apps/react-native/rnllama/README.md Installs Node.js and iOS dependencies for the React Native app. ```bash yarn && cd ios && pod install && cd .. ``` -------------------------------- ### Executorch Installation and Build Setup Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends-cadence.md Cleans the Executorch installation and creates a directory for CMake output. ```bash cd executorch ./install_executorch.sh --clean mkdir cmake-out ``` -------------------------------- ### Python Installation Options Source: https://github.com/pytorch/executorch/blob/main/extension/llm/runner/README.md Code examples for installing ExecuTorch with Python bindings, including options using the install script, CMake, and pip. ```bash # Option 1: Use the install script (includes pybindings by default) bash install_executorch.sh # Option 2: Build with CMake directly cmake -B cmake-out \ -DEXECUTORCH_BUILD_PYBIND=ON \ -DCMAKE_INSTALL_PREFIX=cmake-out \ cmake/ cmake --build cmake-out -j$(nproc) --target install # Option 3: pip install from source (includes pybindings) pip install -e . --no-build-isolation ``` -------------------------------- ### Run Gemma2 2B Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for Gemma2 2B using hybrid mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --max_seq_len 1024 --prefill_ar_len 128 --decoder_model gemma2-2b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Running on Corstone FVP Platforms Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/arm-ethos-u/tutorials/ethos-u-getting-started.md This command demonstrates how to use a utility script to run the compiled executable (.elf-file) on a simulated Arm hardware environment (FVP). ```bash backends/arm/scripts/run_fvp.sh --elf=$(find ethos_u_minimal_example -name arm_executor_runner) --target=ethos-u55-128 ``` -------------------------------- ### Build Core ML delegate frameworks Source: https://github.com/pytorch/executorch/blob/main/backends/apple/coreml/setup.md Builds the executorch.xcframework and coreml_backend.xcframework using a script. ```bash cd executorch ./scripts/build_apple_frameworks.sh --coreml ``` -------------------------------- ### Run LLAMA2 Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for LLAMA2 using hybrid mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --checkpoint stories110M.pt --params params.json --tokenizer_model tokenizer.model --tokenizer_bin tokenizer.bin --decoder_model stories110m --model_mode hybrid --prefill_ar_len 32 --max_seq_len 128 --prompt "Once upon a time" ``` -------------------------------- ### Setup and install ExecuTorch Source: https://github.com/pytorch/executorch/blob/main/zephyr/README.md Navigates to the ExecuTorch directory, syncs and updates its submodules, and runs the installation script. ```bash cd modules/lib/executorch/ git submodule sync git submodule update --init --recursive ./install_executorch.sh cd ../../.. ``` -------------------------------- ### Run LLAMA3.2 3B Instruct Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for LLAMA3.2 3B Instruct using hybrid mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --checkpoint consolidated.00.pth --params params.json --tokenizer_model tokenizer.model --decoder_model llama3_2-3b_instruct --model_mode hybrid --prefill_ar_len 128 --max_seq_len 1024 --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Install Llama Specific Requirements Source: https://github.com/pytorch/executorch/blob/main/examples/models/deepseek-r1-distill-llama-8B/README.md Installs the necessary requirements for running Llama models. ```bash ./examples/models/llama/install_requirements.sh ``` -------------------------------- ### Run Codegen2 Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for Codegen2 using kv mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --decoder_model codegen2_1b --model_mode kv --max_seq_len 1024 --prompt "def hello_world():" ``` -------------------------------- ### Example Usage Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llm_utils/README.md This command demonstrates how to run the evaluation script with essential parameters. ```bash python examples/qualcomm/oss_scripts/llm_utils/eval_decoder_model_qnn.py \ --artifact ./eval_output \ --tokenizer_path /path/to/your/tokenizer.model \ --pte /path/to/your/model.pte \ --soc_model SM8550 \ --device YOUR_DEVICE_ID \ --host localhost \ --tasks wikitext \ --limit 1 \ --max_seq_len 512 ``` -------------------------------- ### Building and installing ExecuTorch with MPS support Source: https://github.com/pytorch/executorch/blob/main/examples/apple/mps/README.md Commands to build and install ExecuTorch, enabling MPS support. ```bash cmake -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_DEVTOOLS=ON \ -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ -DEXECUTORCH_BUILD_MPS=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ -Bcmake-out . cmake --build cmake-out -j9 --target install --config Release ``` -------------------------------- ### Install specific transformers commit Source: https://github.com/pytorch/executorch/blob/main/backends/mlx/examples/llm/README.md Installs a specific commit of the transformers library, as required for Gemma 4 validation. ```bash pip install -U "transformers @ git+https://github.com/huggingface/transformers.git@61461a7bcb458db7cf6eeea49678b9ab776a7821" ``` -------------------------------- ### Exporting and Lowering to Ethos-U Backend Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/arm-ethos-u/tutorials/ethos-u-getting-started.md This code snippet demonstrates how to export a quantized PyTorch model, partition it for the Ethos-U backend, and lower it to an Edge program, finally converting it to an ExecuTorch program and saving it as a .pte file. ```python quantized_exported_program = torch.export.export(quantized_graph_module, example_inputs) from executorch.backends.arm.ethosu import EthosUPartitioner from executorch.exir import ( EdgeCompileConfig, ExecutorchBackendConfig, to_edge_transform_and_lower, ) from executorch.extension.export_util.utils import save_pte_program # Create partitioner from compile spec partitioner = EthosUPartitioner(compile_spec) # Lower the exported program to the Ethos-U backend edge_program_manager = to_edge_transform_and_lower( quantized_exported_program, partitioner=[partitioner], compile_config=EdgeCompileConfig( _check_ir_validity=False, ), ) # Convert edge program to executorch executorch_program_manager = edge_program_manager.to_executorch( config=ExecutorchBackendConfig(extract_delegate_segments=False) ) # Save pte file save_pte_program(executorch_program_manager, "ethos_u_minimal_example.pte") ``` -------------------------------- ### Setup necessary tools for Ethos-U55/85 Source: https://github.com/pytorch/executorch/blob/main/examples/arm/README.md Initial setup script to install necessary tools for building applications for Ethos-U55/85. ```bash # Step [1] - setup necessary tools $ cd $ ./examples/arm/setup.sh --i-agree-to-the-contained-eula ``` -------------------------------- ### Install Requirements Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/qaihub_scripts/stable_diffusion/README.md Shell script to install necessary Python packages for running the Stable Diffusion example. ```bash sh examples/qualcomm/qaihub_scripts/stable_diffusion/install_requirements.sh ``` -------------------------------- ### Change directory to Qualcomm examples Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/README.md Navigate to the scripts directory within the Qualcomm examples for ExecuTorch. ```bash cd $EXECUTORCH_ROOT/examples/qualcomm/scripts ``` -------------------------------- ### Run Gemma 2B Example Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/oss_scripts/llama/README.md This command executes the default example for Gemma 2B using hybrid mode. ```bash python examples/qualcomm/oss_scripts/llama/llama.py -b build-android -s ${SERIAL_NUM} -m ${SOC_MODEL} --temperature 0 --model_mode hybrid --max_seq_len 1024 --prefill_ar_len 128 --decoder_model gemma-2b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1 ``` -------------------------------- ### Setup Script Source: https://github.com/pytorch/executorch/blob/main/docs/source/backends/nxp/nxp-overview.md Command to run the setup script for installing development requirements, excluding MCUXpresso IDE and SDK. ```bash ./examples/nxp/setup.sh ``` -------------------------------- ### Build ExecuTorch with LLM preset Source: https://github.com/pytorch/executorch/blob/main/examples/models/phi-3-mini/README.md Configures and builds the ExecuTorch environment with the LLM preset. ```bash cmake --workflow llm-release ``` -------------------------------- ### Install Executorch with Vulkan Support Source: https://github.com/pytorch/executorch/blob/main/examples/vulkan/README.md Installs the executorch python package from source with Vulkan backend support enabled. ```shell CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON " ./install_executorch.sh -e ``` -------------------------------- ### Install Hexagon SDK and Tools Source: https://github.com/pytorch/executorch/blob/main/examples/qualcomm/custom_op/README.md Examples of using qpm-cli to install specific versions of the Hexagon SDK and tools for different targets. ```bash # example: hexagon-sdk-5.4.0 for v75 target (bundled with Hexagon tools 8.7.03) qpm-cli --install hexagonsdk5.x --version 5.4.0.3 --path /path/to/Qualcomm/Hexagon_SDK/hexagon-sdk-5.4.0 # example: hexagon-sdk-6.0.0 for x86 target qpm-cli --install hexagonsdk6.x --version 6.0.0.2 --path /path/to/Qualcomm/Hexagon_SDK/hexagon-sdk-6.0.0 ``` ```bash # example: tools 8.8.02 for x86 target qpm-cli --extract hexagon8.8 --version 8.8.02.1 \ --path /path/to/Qualcomm/Hexagon_SDK/hexagon-sdk-6.0.0/tools/HEXAGON_Tools/8.8.02 ```