diff --git a/.ci/scripts/utils.sh b/.ci/scripts/utils.sh index be684b7bfa2..ebed4a31500 100644 --- a/.ci/scripts/utils.sh +++ b/.ci/scripts/utils.sh @@ -17,7 +17,7 @@ retry () { } clean_executorch_install_folders() { - ./install_executorch.sh --clean + ./install_requirements.sh --clean } install_executorch() { @@ -25,9 +25,9 @@ install_executorch() { # Install executorch, this assumes that Executorch is checked out in the # current directory. if [[ "${1:-}" == "use-pt-pinned-commit" ]]; then - ./install_executorch.sh --pybind xnnpack --use-pt-pinned-commit + ./install_requirements.sh --pybind xnnpack --use-pt-pinned-commit else - ./install_executorch.sh --pybind xnnpack + ./install_requirements.sh --pybind xnnpack fi # Just print out the list of packages for debugging pip list diff --git a/.github/workflows/apple.yml b/.github/workflows/apple.yml index 8ac755bf5df..2e85eeec763 100644 --- a/.github/workflows/apple.yml +++ b/.github/workflows/apple.yml @@ -9,7 +9,7 @@ on: paths: - .ci/scripts/setup-ios.sh - .github/workflows/apple.yml - - install_executorch.sh + - install_requirements.sh - backends/apple/** - build/build_apple_frameworks.sh - build/build_apple_llm_demo.sh diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index dbe0e872acd..b629a52e72c 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -200,7 +200,7 @@ jobs: PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake" # install pybind - bash install_executorch.sh --pybind xnnpack + bash install_requirements.sh --pybind xnnpack # install Llava requirements bash examples/models/llama/install_requirements.sh @@ -436,7 +436,7 @@ jobs: PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake" # install pybind - bash install_executorch.sh --pybind xnnpack + bash install_requirements.sh --pybind xnnpack # install phi-3-mini requirements bash examples/models/phi-3-mini/install_requirements.sh @@ -463,7 +463,7 @@ jobs: PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake" # install pybind - bash install_executorch.sh --pybind xnnpack + bash install_requirements.sh --pybind xnnpack # install llama requirements bash examples/models/llama/install_requirements.sh @@ -490,7 +490,7 @@ jobs: PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake" # install pybind - bash install_executorch.sh --pybind xnnpack + bash install_requirements.sh --pybind xnnpack # install llama requirements bash examples/models/llama/install_requirements.sh @@ -517,7 +517,7 @@ jobs: PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake" # install pybind - bash install_executorch.sh --pybind xnnpack + bash install_requirements.sh --pybind xnnpack # install llama requirements bash examples/models/llama/install_requirements.sh diff --git a/.gitmodules b/.gitmodules index f3407ec95fb..afae765e2b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -55,12 +55,18 @@ [submodule "third-party/ios-cmake"] path = third-party/ios-cmake url = https://github.com/leetal/ios-cmake +[submodule "backends/cadence/hifi/third-party/nnlib/nnlib-hifi4"] + path = backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 + url = https://github.com/foss-xtensa/nnlib-hifi4.git [submodule "third-party/prelude"] path = third-party/prelude url = https://github.com/facebook/buck2-prelude.git [submodule "third-party/pybind11"] path = third-party/pybind11 url = https://github.com/pybind/pybind11.git +[submodule "backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3"] + path = backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3 + url = https://github.com/foss-xtensa/nnlib-FusionG3.git [submodule "third-party/ao"] path = third-party/ao url = https://github.com/pytorch/ao.git diff --git a/backends/apple/mps/setup.md b/backends/apple/mps/setup.md index 82344876531..7cd4c240a43 100644 --- a/backends/apple/mps/setup.md +++ b/backends/apple/mps/setup.md @@ -97,7 +97,7 @@ I 00:00:00.122615 executorch:mps_executor_runner.mm:501] Model verified successf ### [Optional] Run the generated model directly using pybind 1. Make sure `pybind` MPS support was installed: ```bash -./install_executorch.sh --pybind mps +./install_requirements.sh --pybind mps ``` 2. Run the `mps_example` script to trace the model and run it directly from python: ```bash diff --git a/backends/cadence/.gitignore b/backends/cadence/.gitignore deleted file mode 100644 index b635c3e88de..00000000000 --- a/backends/cadence/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -hifi/third-party/nnlib/nnlib-hifi4 -fusion_g3/third-party/nnlib/nnlib-FusionG3 \ No newline at end of file diff --git a/backends/cadence/build_cadence_fusionG3.sh b/backends/cadence/build_cadence_fusionG3.sh index 3e73dd6dc52..7a4dd68fb34 100644 --- a/backends/cadence/build_cadence_fusionG3.sh +++ b/backends/cadence/build_cadence_fusionG3.sh @@ -12,8 +12,7 @@ unset XTENSA_CORE export XTENSA_CORE=FCV_FG3GP git submodule sync git submodule update --init -./backends/cadence/install_requirements.sh -./install_executorch.sh +./install_requirements.sh rm -rf cmake-out diff --git a/backends/cadence/build_cadence_hifi4.sh b/backends/cadence/build_cadence_hifi4.sh index e4821e1ff03..28a38127520 100644 --- a/backends/cadence/build_cadence_hifi4.sh +++ b/backends/cadence/build_cadence_hifi4.sh @@ -12,8 +12,7 @@ unset XTENSA_CORE export XTENSA_CORE=nxp_rt600_RI23_11_newlib git submodule sync git submodule update --init -./backends/cadence/install_requirements.sh -./install_executorch.sh +./install_requirements.sh rm -rf cmake-out diff --git a/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3 b/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3 new file mode 160000 index 00000000000..8ddd1c39d4b --- /dev/null +++ b/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3 @@ -0,0 +1 @@ +Subproject commit 8ddd1c39d4b20235ebe9dac68d92848da2885ece diff --git a/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 b/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 new file mode 160000 index 00000000000..102944a6f76 --- /dev/null +++ b/backends/cadence/hifi/third-party/nnlib/nnlib-hifi4 @@ -0,0 +1 @@ +Subproject commit 102944a6f76a0de4d81adc431f3f132f517aa87f diff --git a/backends/cadence/install_requirements.sh b/backends/cadence/install_requirements.sh deleted file mode 100755 index 76cff4b30f3..00000000000 --- a/backends/cadence/install_requirements.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -SCRIPT_DIR_PATH="$( - cd -- "$(dirname "$0")" >/dev/null 2>&1 - pwd -P -)" - -red=`tput setaf 1` -green=`tput setaf 2` - -EXECUTORCH_ROOT_PATH=$(realpath "$SCRIPT_DIR_PATH/../../") -CADENCE_DIR_PATH="$EXECUTORCH_ROOT_PATH/backends/cadence" -HIFI_DIR_PATH="$CADENCE_DIR_PATH/hifi/third-party/nnlib/nnlib-hifi4" -FUSION_DIR_PATH="$CADENCE_DIR_PATH/fusion_g3/third-party/nnlib/nnlib-FusionG3" - -cd "$EXECUTORCH_ROOT_PATH" - -## HiFi - -rm -rf "$HIFI_DIR_PATH" -mkdir -p "$HIFI_DIR_PATH" - -echo "${green}ExecuTorch: Cloning hifi nnlib" -git clone "https://github.com/foss-xtensa/nnlib-hifi4.git" $HIFI_DIR_PATH -cd $HIFI_DIR_PATH -STATUS=$? -if [ $STATUS -ne 0 ]; then - echo "${red}ExecuTorch: Failed to clone hifi nnlib." - exit 1 -fi - -git checkout 102944a6f76a0de4d81adc431f3f132f517aa87f - - -## Fusion G3 - -rm -rf "$FUSION_DIR_PATH" -mkdir -p "$FUSION_DIR_PATH" - -echo "${green}ExecuTorch: Cloning fusion g3" -git clone "https://github.com/foss-xtensa/nnlib-FusionG3.git" $FUSION_DIR_PATH -cd $FUSION_DIR_PATH -STATUS=$? -if [ $STATUS -ne 0 ]; then - echo "${red}ExecuTorch: Failed to clone fusion g3." - exit 1 -fi - -git checkout 11230f47b587b074ba0881deb28beb85db566ac2 diff --git a/backends/vulkan/docs/android_demo.md b/backends/vulkan/docs/android_demo.md index 7eab1c21f89..ce23eb989fd 100644 --- a/backends/vulkan/docs/android_demo.md +++ b/backends/vulkan/docs/android_demo.md @@ -81,7 +81,7 @@ First, build and install ExecuTorch libraries, then build the LLaMA runner binary using the Android NDK toolchain. ```shell -./install_executorch.sh --clean +./install_requirements.sh --clean (mkdir cmake-android-out && \ cmake . -DCMAKE_INSTALL_PREFIX=cmake-android-out \ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ diff --git a/backends/xnnpack/README.md b/backends/xnnpack/README.md index 967a852599a..2184257b791 100644 --- a/backends/xnnpack/README.md +++ b/backends/xnnpack/README.md @@ -98,7 +98,7 @@ After exporting the XNNPACK Delegated model, we can now try running it with exam cd executorch # Get a clean cmake-out directory -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-out # Configure cmake diff --git a/build/test_ios.sh b/build/test_ios.sh index cdc02098cee..150a974cc1f 100755 --- a/build/test_ios.sh +++ b/build/test_ios.sh @@ -63,7 +63,7 @@ say "Installing Requirements" pip install --upgrade cmake pip setuptools wheel zstd -./install_executorch.sh --pybind coreml mps xnnpack +./install_requirements.sh --pybind coreml mps xnnpack export PATH="$(realpath third-party/flatbuffers/cmake-out):$PATH" ./build/install_flatc.sh diff --git a/docs/README.md b/docs/README.md index dd1fded5aa9..c65bd8474e0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -65,7 +65,7 @@ To build the documentation locally: 1. Run: ```bash - bash install_executorch.sh + bash install_requirements.sh ``` 1. Go to the `docs/` directory. diff --git a/docs/source/apple-runtime.md b/docs/source/apple-runtime.md index fe744add52e..bfda12db216 100644 --- a/docs/source/apple-runtime.md +++ b/docs/source/apple-runtime.md @@ -109,7 +109,7 @@ python3 -m venv .venv && source .venv/bin/activate && pip install --upgrade pip 4. Install the required dependencies, including those needed for the backends like [Core ML](build-run-coreml.md) or [MPS](build-run-mps.md), if you plan to build them as well: ```bash -./install_executorch.sh --pybind coreml mps xnnpack +./install_requirements.sh --pybind coreml mps xnnpack # Optional dependencies for Core ML backend. ./backends/apple/coreml/scripts/install_requirements.sh diff --git a/docs/source/build-run-xtensa.md b/docs/source/build-run-xtensa.md index 6097c9095a6..bc90ee52922 100644 --- a/docs/source/build-run-xtensa.md +++ b/docs/source/build-run-xtensa.md @@ -162,7 +162,7 @@ In order to run the CMake build, you need the path to the following: ```bash cd executorch -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-out # prebuild and install executorch library cmake -DCMAKE_TOOLCHAIN_FILE=/backends/cadence/cadence.cmake \ diff --git a/docs/source/getting-started-setup.md b/docs/source/getting-started-setup.md index fe0b042e605..e21a73195c2 100644 --- a/docs/source/getting-started-setup.md +++ b/docs/source/getting-started-setup.md @@ -92,23 +92,23 @@ Alternatively, if you would like to experiment with ExecuTorch quickly and easil # Install ExecuTorch pip package and its dependencies, as well as # development tools like CMake. # If developing on a Mac, make sure to install the Xcode Command Line Tools first. - ./install_executorch.sh + ./install_requirements.sh ``` - Use the [`--pybind` flag](https://github.com/pytorch/executorch/blob/main/install_executorch.sh#L26-L29) to install with pybindings and dependencies for other backends. + 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. ```bash - ./install_executorch.sh --pybind + ./install_requirements.sh --pybind # Example: pybindings with CoreML *only* - ./install_executorch.sh --pybind coreml + ./install_requirements.sh --pybind coreml # Example: pybinds with CoreML *and* XNNPACK - ./install_executorch.sh --pybind coreml xnnpack + ./install_requirements.sh --pybind coreml xnnpack ``` - By default, `./install_executorch.sh` command installs pybindings for XNNPACK. To disable any pybindings altogether: + By default, `./install_requirements.sh` command installs pybindings for XNNPACK. To disable any pybindings altogether: ```bash - ./install_executorch.sh --pybind off + ./install_requirements.sh --pybind off ``` After setting up your environment, you are ready to convert your PyTorch programs @@ -125,7 +125,7 @@ to ExecuTorch. > > ```bash > # From the root of the executorch repo: -> ./install_executorch.sh --clean +> ./install_requirements.sh --clean > git submodule sync > git submodule update --init > ``` @@ -208,7 +208,7 @@ The ExecuTorch repo uses CMake to build its C++ code. Here, we'll configure it t ```bash # Clean and configure the CMake build system. Compiled programs will # appear in the executorch/cmake-out directory we create here. - ./install_executorch.sh --clean + ./install_requirements.sh --clean (mkdir cmake-out && cd cmake-out && cmake ..) # Build the executor_runner target @@ -226,7 +226,7 @@ The ExecuTorch repo uses CMake to build its C++ code. Here, we'll configure it t > > ```bash > # From the root of the executorch repo: -> ./install_executorch.sh --clean +> ./install_requirements.sh --clean > git submodule sync > git submodule update --init > ``` diff --git a/docs/source/llm/getting-started.md b/docs/source/llm/getting-started.md index f0de7cc9c97..9f88d7de361 100644 --- a/docs/source/llm/getting-started.md +++ b/docs/source/llm/getting-started.md @@ -52,7 +52,7 @@ git submodule update --init # Create a conda environment and install requirements. conda create -yn executorch python=3.10.0 conda activate executorch -./install_executorch.sh +./install_requirements.sh cd ../.. ``` @@ -83,7 +83,7 @@ cd third-party/executorch git submodule update --init # Install requirements. -PYTHON_EXECUTABLE=python ./install_executorch.sh +PYTHON_EXECUTABLE=python ./install_requirements.sh cd ../.. ``` @@ -396,7 +396,7 @@ At this point, the working directory should contain the following files: If all of these are present, you can now build and run: ```bash -./install_executorch.sh --clean +./install_requirements.sh --clean (mkdir cmake-out && cd cmake-out && cmake ..) cmake --build cmake-out -j10 ./cmake-out/nanogpt_runner diff --git a/docs/source/runtime-build-and-cross-compilation.md b/docs/source/runtime-build-and-cross-compilation.md index 3574b76b6df..f30d2d28d1c 100644 --- a/docs/source/runtime-build-and-cross-compilation.md +++ b/docs/source/runtime-build-and-cross-compilation.md @@ -45,7 +45,7 @@ cd executorch # Clean and configure the CMake build system. It's good practice to do this # whenever cloning or pulling the upstream repo. -./install_executorch.sh --clean +./install_requirements.sh --clean (mkdir cmake-out && cd cmake-out && cmake ..) ``` @@ -122,7 +122,7 @@ Following are instruction on how to perform cross compilation for Android and iO Assuming Android NDK is available, run: ```bash # Run the following lines from the `executorch/` folder -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-android-out && cd cmake-android-out # point -DCMAKE_TOOLCHAIN_FILE to the location where ndk is installed diff --git a/docs/source/tutorial-xnnpack-delegate-lowering.md b/docs/source/tutorial-xnnpack-delegate-lowering.md index c81f61878c6..f4579e2cce4 100644 --- a/docs/source/tutorial-xnnpack-delegate-lowering.md +++ b/docs/source/tutorial-xnnpack-delegate-lowering.md @@ -147,7 +147,7 @@ After exporting the XNNPACK Delegated model, we can now try running it with exam cd executorch # Get a clean cmake-out directory -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-out # Configure cmake diff --git a/examples/demo-apps/android/ExecuTorchDemo/README.md b/examples/demo-apps/android/ExecuTorchDemo/README.md index 931509891a6..1feb9ca92dc 100644 --- a/examples/demo-apps/android/ExecuTorchDemo/README.md +++ b/examples/demo-apps/android/ExecuTorchDemo/README.md @@ -70,7 +70,7 @@ export ANDROID_NDK= export ANDROID_ABI=arm64-v8a # Run the following lines from the `executorch/` folder -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-android-out # Build the core executorch library @@ -114,7 +114,7 @@ export ANDROID_NDK= export ANDROID_ABI=arm64-v8a export QNN_SDK_ROOT= -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-android-out cmake . -DCMAKE_INSTALL_PREFIX=cmake-android-out \ -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/mediatek_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/mediatek_README.md index 6351640dcc0..b80ea516468 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/mediatek_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/mediatek_README.md @@ -36,7 +36,7 @@ git submodule update --init ``` Install dependencies ``` -./install_executorch.sh +./install_requirements.sh ``` ## Setup Environment Variables ### Download Buck2 and make executable diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md index 92afe613f7b..7790f66923c 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md @@ -34,7 +34,7 @@ git submodule update --init ``` Install dependencies ``` -./install_executorch.sh +./install_requirements.sh ``` ## Setup QNN diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md index a2ac04ae93a..087bd242608 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md @@ -36,12 +36,12 @@ git submodule update --init ``` Install dependencies ``` -./install_executorch.sh +./install_requirements.sh ``` Optional: Use the --pybind flag to install with pybindings. ``` -./install_executorch.sh --pybind xnnpack +./install_requirements.sh --pybind xnnpack ``` diff --git a/examples/demo-apps/apple_ios/ExecuTorchDemo/README.md b/examples/demo-apps/apple_ios/ExecuTorchDemo/README.md index 844c83d2200..4a4e682a4ad 100644 --- a/examples/demo-apps/apple_ios/ExecuTorchDemo/README.md +++ b/examples/demo-apps/apple_ios/ExecuTorchDemo/README.md @@ -51,7 +51,7 @@ python3 -m venv .venv && source .venv/bin/activate pip install --upgrade cmake pip setuptools wheel -./install_executorch.sh --pybind coreml mps xnnpack +./install_requirements.sh --pybind coreml mps xnnpack ``` ### 4. Backend Dependencies diff --git a/examples/demo-apps/apple_ios/LLaMA/docs/delegates/mps_README.md b/examples/demo-apps/apple_ios/LLaMA/docs/delegates/mps_README.md index bfe66bbd4e4..eb3c244dee7 100644 --- a/examples/demo-apps/apple_ios/LLaMA/docs/delegates/mps_README.md +++ b/examples/demo-apps/apple_ios/LLaMA/docs/delegates/mps_README.md @@ -33,7 +33,7 @@ git submodule update --init Install dependencies ``` -./install_executorch.sh +./install_requirements.sh ``` ## Prepare Models diff --git a/examples/demo-apps/apple_ios/LLaMA/docs/delegates/xnnpack_README.md b/examples/demo-apps/apple_ios/LLaMA/docs/delegates/xnnpack_README.md index b3576280426..1e03993c949 100644 --- a/examples/demo-apps/apple_ios/LLaMA/docs/delegates/xnnpack_README.md +++ b/examples/demo-apps/apple_ios/LLaMA/docs/delegates/xnnpack_README.md @@ -32,11 +32,11 @@ git submodule update --init Install dependencies ``` -./install_executorch.sh +./install_requirements.sh ``` Optional: Use the --pybind flag to install with pybindings. ``` -./install_executorch.sh --pybind xnnpack +./install_requirements.sh --pybind xnnpack ``` ## Prepare Models In this demo app, we support text-only inference with up-to-date Llama models and image reasoning inference with LLaVA 1.5. diff --git a/examples/demo-apps/react-native/rnllama/README.md b/examples/demo-apps/react-native/rnllama/README.md index 33c607d635f..76c44a6621e 100644 --- a/examples/demo-apps/react-native/rnllama/README.md +++ b/examples/demo-apps/react-native/rnllama/README.md @@ -26,7 +26,7 @@ A React Native mobile application for running LLaMA language models using ExecuT 3. Pull submodules: `git submodule sync && git submodule update --init` -4. Install dependencies: `./install_executorch.sh --pybind xnnpack && ./examples/models/llama/install_requirements.sh` +4. Install dependencies: `./install_requirements.sh --pybind xnnpack && ./examples/models/llama/install_requirements.sh` 5. Follow the instructions in the [README](https://github.com/pytorch/executorch/blob/main/examples/models/llama/README.md#option-a-download-and-export-llama32-1b3b-model) to export a model as `.pte` @@ -40,4 +40,4 @@ A React Native mobile application for running LLaMA language models using ExecuT 10. Select the model and tokenizer in the app to start chatting: -[![rnllama]](https://github.com/user-attachments/assets/b339f1ec-8b80-41f0-b3f6-ded6698ac926) +[![rnllama]](https://github.com/user-attachments/assets/b339f1ec-8b80-41f0-b3f6-ded6698ac926) \ No newline at end of file diff --git a/examples/devtools/build_example_runner.sh b/examples/devtools/build_example_runner.sh index b6a14bcfb1e..693996940d5 100755 --- a/examples/devtools/build_example_runner.sh +++ b/examples/devtools/build_example_runner.sh @@ -37,7 +37,7 @@ done main() { cd "${EXECUTORCH_ROOT}" - ./install_executorch.sh --clean + ./install_requirements.sh --clean if [[ "${BUILD_COREML}" == "ON" ]]; then cmake -DCMAKE_INSTALL_PREFIX=cmake-out \ diff --git a/examples/models/llama/README.md b/examples/models/llama/README.md index 7a8838fb016..cf9553c1c6e 100644 --- a/examples/models/llama/README.md +++ b/examples/models/llama/README.md @@ -148,7 +148,7 @@ Llama 3 8B performance was measured on the Samsung Galaxy S22, S24, and OnePlus ## Step 1: Setup > :warning: **double check your python environment**: make sure `conda activate ` is run before all the bash and python scripts. -1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_executorch.sh --pybind xnnpack` +1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_requirements.sh --pybind xnnpack` 2. Run `examples/models/llama/install_requirements.sh` to install a few dependencies. @@ -440,8 +440,8 @@ This example tries to reuse the Python code, with minimal modifications to make ``` git clean -xfd pip uninstall executorch -./install_executorch.sh --clean -./install_executorch.sh --pybind xnnpack +./install_requirements.sh --clean +./install_requirements.sh --pybind xnnpack ``` - If you encounter `pthread` related issues during link time, add `pthread` in `target_link_libraries` in `CMakeLists.txt` - On Mac, if there is linking error in Step 4 with error message like diff --git a/examples/models/llava/README.md b/examples/models/llava/README.md index d0dc71c0a85..ad2f3f3dc99 100644 --- a/examples/models/llava/README.md +++ b/examples/models/llava/README.md @@ -37,7 +37,7 @@ application to test things out on device. Run the following command to generate `llava.pte`, `tokenizer.bin` and an image tensor (serialized in TorchScript) `image.pt`. -Prerequisite: run `install_executorch.sh` to install ExecuTorch and run +Prerequisite: run `install_requirements.sh` to install ExecuTorch and run `examples/models/llava/install_requirements.sh` to install dependencies. ```bash diff --git a/examples/models/phi-3-mini-lora/README.md b/examples/models/phi-3-mini-lora/README.md index 2b7cc0ba401..8e4b2428071 100644 --- a/examples/models/phi-3-mini-lora/README.md +++ b/examples/models/phi-3-mini-lora/README.md @@ -5,7 +5,7 @@ To see how you can use the model exported for training in a fully involved finet ## Instructions ### Step 1: [Optional] Install ExecuTorch dependencies -`./install_executorch.sh` in ExecuTorch root directory. +`./install_requirements.sh` in ExecuTorch root directory. ### Step 2: Install Requirements - `./examples/models/phi-3-mini-lora/install_requirements.sh` @@ -19,7 +19,7 @@ python export_model.py 2. Run the inference model using an example runtime. For more detailed steps on this, check out [Build & Run](https://pytorch.org/executorch/stable/getting-started-setup.html#build-run). ``` # Clean and configure the CMake build system. Compiled programs will appear in the executorch/cmake-out directory we create here. -./install_executorch.sh --clean +./install_requirements.sh --clean (mkdir cmake-out && cd cmake-out && cmake ..) # Build the executor_runner target diff --git a/examples/models/phi-3-mini/README.md b/examples/models/phi-3-mini/README.md index ba878d42a3f..e5a86c41777 100644 --- a/examples/models/phi-3-mini/README.md +++ b/examples/models/phi-3-mini/README.md @@ -3,7 +3,7 @@ This example demonstrates how to run a [Phi-3-mini](https://huggingface.co/micro # Instructions ## Step 1: Setup -1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_executorch.sh --pybind xnnpack` +1. Follow the [tutorial](https://pytorch.org/executorch/main/getting-started-setup) to set up ExecuTorch. For installation run `./install_requirements.sh --pybind xnnpack` 2. Currently, we support transformers v4.44.2. Install transformers with the following command: ``` pip uninstall -y transformers ; pip install transformers==4.44.2 diff --git a/examples/portable/README.md b/examples/portable/README.md index a6658197da3..e469df1510d 100644 --- a/examples/portable/README.md +++ b/examples/portable/README.md @@ -45,7 +45,7 @@ Use `-h` (or `--help`) to see all the supported models. ```bash # Build the tool from the top-level `executorch` directory. -./install_executorch.sh --clean +./install_requirements.sh --clean (mkdir cmake-out \ && cd cmake-out \ && cmake -DEXECUTORCH_PAL_DEFAULT=posix ..) \ diff --git a/examples/xnnpack/README.md b/examples/xnnpack/README.md index 624dd33b849..a519d935b52 100644 --- a/examples/xnnpack/README.md +++ b/examples/xnnpack/README.md @@ -86,7 +86,7 @@ After exporting the XNNPACK Delegated model, we can now try running it with exam cd executorch # Get a clean cmake-out directory -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-out # Configure cmake diff --git a/extension/pybindings/README.md b/extension/pybindings/README.md index 767c0266ed3..8c1adf2c220 100644 --- a/extension/pybindings/README.md +++ b/extension/pybindings/README.md @@ -9,7 +9,7 @@ pip install . --no-build-isolation Or when installing the rest of dependencies: ```bash -install_executorch.sh --pybind +install_requirements.sh --pybind ``` # Link Backends @@ -25,7 +25,7 @@ pip install . --no-build-isolation Similarly, when installing the rest of dependencies: ```bash -install_executorch.sh --pybind coreml mps xnnpack +install_requirements.sh --pybind coreml mps xnnpack ``` ## Functions diff --git a/extension/training/README.md b/extension/training/README.md index f6f8d5139a6..44195471a71 100644 --- a/extension/training/README.md +++ b/extension/training/README.md @@ -230,7 +230,7 @@ After exporting the model for training, we can now try learning using CMake. We cd executorch # Get a clean cmake-out directory -./install_executorch.sh --clean +./install_requirements.sh --clean mkdir cmake-out # Configure cmake diff --git a/install_executorch.py b/install_executorch.py deleted file mode 100644 index 37ef3185ad3..00000000000 --- a/install_executorch.py +++ /dev/null @@ -1,142 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# Copyright 2024-25 Arm Limited and/or its affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - - -import argparse -import glob -import itertools -import os -import shutil -import subprocess -import sys - -from install_requirements import ( - install_requirements, - python_is_compatible, - TORCH_NIGHTLY_URL, -) - - -def clean(): - print("Cleaning build artifacts...") - print("Cleaning pip-out/...") - shutil.rmtree("pip-out/", ignore_errors=True) - dirs = glob.glob("cmake-out*/") + glob.glob("cmake-android-out/") - for d in dirs: - print(f"Cleaning {d}...") - shutil.rmtree(d, ignore_errors=True) - print("Done cleaning build artifacts.") - - -VALID_PYBINDS = ["coreml", "mps", "xnnpack"] - - -def main(args): - if not python_is_compatible(): - sys.exit(1) - - # Parse options. - - EXECUTORCH_BUILD_PYBIND = "" - CMAKE_ARGS = os.getenv("CMAKE_ARGS", "") - use_pytorch_nightly = True - - parser = argparse.ArgumentParser() - parser.add_argument( - "--pybind", - action="append", - nargs="+", - help="one or more of coreml/mps/xnnpack, or off", - ) - parser.add_argument( - "--clean", - action="store_true", - help="clean build artifacts and pip-out instead of installing", - ) - parser.add_argument( - "--use-pt-pinned-commit", - action="store_true", - help="build from the pinned PyTorch commit instead of nightly", - ) - args = parser.parse_args(args) - if args.pybind: - # Flatten list of lists. - args.pybind = list(itertools.chain(*args.pybind)) - if "off" in args.pybind: - if len(args.pybind) != 1: - raise Exception( - f"Cannot combine `off` with other pybinds: {args.pybind}" - ) - EXECUTORCH_BUILD_PYBIND = "OFF" - else: - for pybind_arg in args.pybind: - if pybind_arg not in VALID_PYBINDS: - raise Exception( - f"Unrecognized pybind argument {pybind_arg}; valid options are: {', '.join(VALID_PYBINDS)}" - ) - EXECUTORCH_BUILD_PYBIND = "ON" - CMAKE_ARGS += f" -DEXECUTORCH_BUILD_{pybind_arg.upper()}=ON" - - if args.clean: - clean() - return - - if args.use_pt_pinned_commit: - # This option is used in CI to make sure that PyTorch build from the pinned commit - # is used instead of nightly. CI jobs wouldn't be able to catch regression from the - # latest PT commit otherwise - use_pytorch_nightly = False - - install_requirements(use_pytorch_nightly) - - # If --pybind is not set explicitly for backends (e.g., --pybind xnnpack) - # or is not turned off explicitly (--pybind off) - # then install XNNPACK by default. - if EXECUTORCH_BUILD_PYBIND == "": - EXECUTORCH_BUILD_PYBIND = "ON" - CMAKE_ARGS += " -DEXECUTORCH_BUILD_XNNPACK=ON" - - # Use ClangCL on Windows. - # ClangCL is an alias to Clang that configures it to work in an MSVC-compatible - # mode. Using it on Windows to avoid compiler compatibility issues for MSVC. - if os.name == "nt": - CMAKE_ARGS += " -T ClangCL" - - # - # Install executorch pip package. This also makes `flatc` available on the path. - # The --extra-index-url may be necessary if pyproject.toml has a dependency on a - # pre-release or nightly version of a torch package. - # - - # Set environment variables - os.environ["EXECUTORCH_BUILD_PYBIND"] = EXECUTORCH_BUILD_PYBIND - os.environ["CMAKE_ARGS"] = CMAKE_ARGS - - # Run the pip install command - subprocess.run( - [ - sys.executable, - "-m", - "pip", - "install", - ".", - "--no-build-isolation", - "-v", - "--extra-index-url", - TORCH_NIGHTLY_URL, - ], - check=True, - ) - - -if __name__ == "__main__": - # Before doing anything, cd to the directory containing this script. - os.chdir(os.path.dirname(os.path.abspath(__file__))) - if not python_is_compatible(): - sys.exit(1) - - main(sys.argv[1:]) diff --git a/install_executorch.sh b/install_executorch.sh deleted file mode 100755 index ec8cad12266..00000000000 --- a/install_executorch.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -# Before doing anything, cd to the directory containing this script. -cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null || /bin/true -./run_python_script.sh ./install_executorch.py "$@" diff --git a/install_executorch.bat b/install_requirements.bat similarity index 84% rename from install_executorch.bat rename to install_requirements.bat index 863ade7bdbb..4cfe4b21c4b 100644 --- a/install_executorch.bat +++ b/install_requirements.bat @@ -16,6 +16,6 @@ if "%PYTHON_EXECUTABLE%"=="" ( ) ) -"%PYTHON_EXECUTABLE%" install_executorch.py %* +"%PYTHON_EXECUTABLE%" install_requirements.py %* -exit /b %ERRORLEVEL% +exit /b %ERRORLEVEL% \ No newline at end of file diff --git a/install_requirements.py b/install_requirements.py index c634e483945..adb26170cd0 100644 --- a/install_requirements.py +++ b/install_requirements.py @@ -5,12 +5,18 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -import argparse + +import glob +import os import platform import re +import shutil import subprocess import sys +# Before doing anything, cd to the directory containing this script. +os.chdir(os.path.dirname(os.path.abspath(__file__))) + def python_is_compatible(): # Scrape the version range from pyproject.toml, which should be in the current directory. @@ -57,9 +63,69 @@ def python_is_compatible(): return True -# The pip repository that hosts nightly torch packages. -TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu" +if not python_is_compatible(): + sys.exit(1) + +# Parse options. + +EXECUTORCH_BUILD_PYBIND = "" +CMAKE_ARGS = os.getenv("CMAKE_ARGS", "") +CMAKE_BUILD_ARGS = os.getenv("CMAKE_BUILD_ARGS", "") +USE_PYTORCH_NIGHTLY = True + +args = sys.argv[1:] +for arg in args: + if arg == "--pybind": + pass + elif arg in ["coreml", "mps", "xnnpack"]: + if "--pybind" in args: + arg_upper = arg.upper() + EXECUTORCH_BUILD_PYBIND = "ON" + CMAKE_ARGS += f" -DEXECUTORCH_BUILD_{arg_upper}=ON" + else: + print(f"Error: {arg} must follow --pybind") + sys.exit(1) + elif arg == "off": + if "--pybind" in args: + if EXECUTORCH_BUILD_PYBIND == "ON": + print("Cannot turnoff pybind option as it is already set.") + sys.exit(1) + EXECUTORCH_BUILD_PYBIND = "OFF" + else: + print(f"Error: {arg} must follow --pybind") + sys.exit(1) + + elif arg == "--clean": + print("Cleaning build artifacts...") + print("Cleaning pip-out/...") + shutil.rmtree("pip-out/", ignore_errors=True) + dirs = glob.glob("cmake-out*/") + glob.glob("cmake-android-out/") + for d in dirs: + print(f"Cleaning {d}...") + shutil.rmtree(d, ignore_errors=True) + print("Done cleaning build artifacts.") + sys.exit(0) + elif arg == "--use-pt-pinned-commit": + # This option is used in CI to make sure that PyTorch build from the pinned commit + # is used instead of nightly. CI jobs wouldn't be able to catch regression from the + # latest PT commit otherwise + USE_PYTORCH_NIGHTLY = False + else: + print(f"Error: Unknown option {arg}") + sys.exit(1) + +# If --pybind is not set explicitly for backends (e.g., --pybind xnnpack) +# or is not turned off explicitly (--pybind off) +# then install XNNPACK by default. +if EXECUTORCH_BUILD_PYBIND == "": + EXECUTORCH_BUILD_PYBIND = "ON" + CMAKE_ARGS += " -DEXECUTORCH_BUILD_XNNPACK=ON" +# Use ClangCL on Windows. +# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible +# mode. Using it on Windows to avoid compiler compatibility issues for MSVC. +if os.name == "nt": + CMAKE_ARGS += " -T ClangCL" # Since ExecuTorch often uses main-branch features of pytorch, only the nightly # pip versions will have the required features. @@ -69,84 +135,102 @@ def python_is_compatible(): # package versions. NIGHTLY_VERSION = "dev20250104" +# The pip repository that hosts nightly torch packages. +TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu" -def install_requirements(use_pytorch_nightly): - # pip packages needed by exir. - EXIR_REQUIREMENTS = [ - # Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note - # that we don't need to set any version number there because they have already - # been installed on CI before this step, so pip won't reinstall them - f"torch==2.6.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torch", - ( - f"torchvision==0.22.0.{NIGHTLY_VERSION}" - if use_pytorch_nightly - else "torchvision" - ), # For testing. - ] - - EXAMPLES_REQUIREMENTS = [ - f"torchaudio==2.6.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torchaudio", - ] - - # Assemble the list of requirements to actually install. - # TODO: Add options for reducing the number of requirements. - REQUIREMENTS_TO_INSTALL = EXIR_REQUIREMENTS + EXAMPLES_REQUIREMENTS - - # Install the requirements. `--extra-index-url` tells pip to look for package - # versions on the provided URL if they aren't available on the default URL. - subprocess.run( - [ - sys.executable, - "-m", - "pip", - "install", - "-r", - "requirements-examples.txt", - "-r", - "requirements-dev.txt", - *REQUIREMENTS_TO_INSTALL, - "--extra-index-url", - TORCH_NIGHTLY_URL, - ], - check=True, - ) - - LOCAL_REQUIREMENTS = [ - "third-party/ao", # We need the latest kernels for fast iteration, so not relying on pypi. - ] - - # Install packages directly from local copy instead of pypi. - # This is usually not recommended. - subprocess.run( - [ - sys.executable, - "-m", - "pip", - "install", - # Without --no-build-isolation, setup.py can't find the torch module. - "--no-build-isolation", - *LOCAL_REQUIREMENTS, - ], - check=True, - ) - - -def main(args): - parser = argparse.ArgumentParser() - parser.add_argument( - "--use-pt-pinned-commit", - action="store_true", - help="build from the pinned PyTorch commit instead of nightly", - ) - args = parser.parse_args(args) - install_requirements(use_pytorch_nightly=not bool(args.use_pt_pinned_commit)) - - -if __name__ == "__main__": - import os - - # Before doing anything, cd to the directory containing this script. - os.chdir(os.path.dirname(os.path.abspath(__file__))) - if not python_is_compatible(): - sys.exit(1) - main(sys.argv[1:]) +# pip packages needed by exir. +EXIR_REQUIREMENTS = [ + # Setting USE_PYTORCH_NIGHTLY to false to test the pinned PyTorch commit. Note + # that we don't need to set any version number there because they have already + # been installed on CI before this step, so pip won't reinstall them + f"torch==2.6.0.{NIGHTLY_VERSION}" if USE_PYTORCH_NIGHTLY else "torch", + ( + f"torchvision==0.22.0.{NIGHTLY_VERSION}" + if USE_PYTORCH_NIGHTLY + else "torchvision" + ), # For testing. + "typing-extensions", +] + +# pip packages needed to run examples. +# TODO: Make each example publish its own requirements.txt +EXAMPLES_REQUIREMENTS = [ + "timm==1.0.7", + f"torchaudio==2.6.0.{NIGHTLY_VERSION}" if USE_PYTORCH_NIGHTLY else "torchaudio", + "torchsr==1.0.4", + "transformers==4.47.1", +] + +# pip packages needed for development. +DEVEL_REQUIREMENTS = [ + "cmake", # For building binary targets. + "pip>=23", # For building the pip package. + "pyyaml", # Imported by the kernel codegen tools. + "setuptools>=63", # For building the pip package. + "tomli", # Imported by extract_sources.py when using python < 3.11. + "wheel", # For building the pip package archive. + "zstd", # Imported by resolve_buck.py. +] + +# Assemble the list of requirements to actually install. +# TODO: Add options for reducing the number of requirements. +REQUIREMENTS_TO_INSTALL = EXIR_REQUIREMENTS + DEVEL_REQUIREMENTS + EXAMPLES_REQUIREMENTS + +# Install the requirements. `--extra-index-url` tells pip to look for package +# versions on the provided URL if they aren't available on the default URL. +subprocess.run( + [ + sys.executable, + "-m", + "pip", + "install", + *REQUIREMENTS_TO_INSTALL, + "--extra-index-url", + TORCH_NIGHTLY_URL, + ], + check=True, +) + +LOCAL_REQUIREMENTS = [ + "third-party/ao", # We need the latest kernels for fast iteration, so not relying on pypi. +] + +# Install packages directly from local copy instead of pypi. +# This is usually not recommended. +subprocess.run( + [ + sys.executable, + "-m", + "pip", + "install", + *LOCAL_REQUIREMENTS, + ], + check=True, +) + +# +# Install executorch pip package. This also makes `flatc` available on the path. +# The --extra-index-url may be necessary if pyproject.toml has a dependency on a +# pre-release or nightly version of a torch package. +# + +# Set environment variables +os.environ["EXECUTORCH_BUILD_PYBIND"] = EXECUTORCH_BUILD_PYBIND +os.environ["CMAKE_ARGS"] = CMAKE_ARGS +os.environ["CMAKE_BUILD_ARGS"] = CMAKE_BUILD_ARGS + +# Run the pip install command +subprocess.run( + [ + sys.executable, + "-m", + "pip", + "install", + ".", + "--no-build-isolation", + "-v", + "--extra-index-url", + TORCH_NIGHTLY_URL, + ], + check=True, +) diff --git a/install_requirements.sh b/install_requirements.sh index ef156cd020e..6caaa880e66 100755 --- a/install_requirements.sh +++ b/install_requirements.sh @@ -7,4 +7,19 @@ # Before doing anything, cd to the directory containing this script. cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null || /bin/true -./run_python_script.sh ./install_requirements.py "$@" + +# Find the names of the python tools to use. +if [[ -z $PYTHON_EXECUTABLE ]]; +then + if [[ -z $CONDA_DEFAULT_ENV ]] || [[ $CONDA_DEFAULT_ENV == "base" ]] || [[ ! -x "$(command -v python)" ]]; + then + PYTHON_EXECUTABLE=python3 + else + PYTHON_EXECUTABLE=python + fi +fi + +$PYTHON_EXECUTABLE ./install_requirements.py "$@" + +# Exit with the same status as the python script. +exit $? diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index fb59bf3d21a..00000000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake # For building binary targets in the wheel. -pip>=23 # For building the pip package. -pyyaml # Imported by the kernel codegen tools. -setuptools>=63 # For building the pip package contents. -tomli # Imported by extract_sources.py when using python < 3.11. -wheel # For building the pip package archive. -zstd # Imported by resolve_buck.py. diff --git a/requirements-examples.txt b/requirements-examples.txt deleted file mode 100644 index d4126a178aa..00000000000 --- a/requirements-examples.txt +++ /dev/null @@ -1,5 +0,0 @@ -# pip packages needed to run examples. -# TODO: Make each example publish its own requirements.txt -timm == 1.0.7 -torchsr == 1.0.4 -transformers ==4.47.1 diff --git a/run_python_script.sh b/run_python_script.sh deleted file mode 100755 index 4f9a74ec360..00000000000 --- a/run_python_script.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. - -# Before doing anything, cd to the directory containing this script. -cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null || /bin/true - -# Find the names of the python tools to use. -if [[ -z $PYTHON_EXECUTABLE ]]; -then - if [[ -z $CONDA_DEFAULT_ENV ]] || [[ $CONDA_DEFAULT_ENV == "base" ]] || [[ ! -x "$(command -v python)" ]]; - then - PYTHON_EXECUTABLE=python3 - else - PYTHON_EXECUTABLE=python - fi -fi - -SCRIPT="$1"; shift -$PYTHON_EXECUTABLE $SCRIPT "$@" - -# Exit with the same status as the python script. -exit $?