From db9b56e4dd23167adb4941550cffa145355adcfa Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Thu, 17 Oct 2024 15:54:16 -0700 Subject: [PATCH 01/14] Install ET nightly and bump up ET version to 20241017 Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- install/.pins/et-pin.txt | 2 +- install/install_requirements.sh | 4 +-- torchchat/utils/scripts/install_utils.sh | 39 +++++++++++------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index e61fae3a5..2d138e8b8 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -72b3bb3194c611f7c4861e6f3b24af5de868af72 +2024-10-17 diff --git a/install/install_requirements.sh b/install/install_requirements.sh index 6344509d8..c86ff517e 100755 --- a/install/install_requirements.sh +++ b/install/install_requirements.sh @@ -47,10 +47,10 @@ fi # NOTE: If a newly-fetched version of the executorch repo changes the value of # PYTORCH_NIGHTLY_VERSION, you should re-run this script to install the necessary # package versions. -PYTORCH_NIGHTLY_VERSION=dev20241002 +PYTORCH_NIGHTLY_VERSION=dev20241007 # Nightly version for torchvision -VISION_NIGHTLY_VERSION=dev20241002 +VISION_NIGHTLY_VERSION=dev20241007 # Nightly version for torchtune TUNE_NIGHTLY_VERSION=dev20241010 diff --git a/torchchat/utils/scripts/install_utils.sh b/torchchat/utils/scripts/install_utils.sh index 84966cc35..286ad335c 100644 --- a/torchchat/utils/scripts/install_utils.sh +++ b/torchchat/utils/scripts/install_utils.sh @@ -27,6 +27,14 @@ function find_cmake_prefix_path() { MY_CMAKE_PREFIX_PATH=$path } + +function get_executorch_commit_hash_pin() { + # Assuming inside executorch + nightly_str=$(cat ${TORCHCHAT_ROOT}/install/.pins/et-pin.txt) + nightly_commit_hash=$(git log origin/nightly --format=%H --grep="${nightly_str} nightly release") + echo "Nightly commit hash: ${nightly_commit_hash}" +} + clone_executorch_internal() { rm -rf ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src @@ -34,7 +42,9 @@ clone_executorch_internal() { pushd ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src git clone https://github.com/pytorch/executorch.git cd executorch - git checkout $(cat ${TORCHCHAT_ROOT}/install/.pins/et-pin.txt) + get_executorch_commit_hash_pin + + git checkout "$nightly_commit_hash" echo "Install ExecuTorch: submodule update" git submodule sync git submodule update --init @@ -60,9 +70,9 @@ clone_executorch() { # Check if the version is the same current_version=$(git rev-parse HEAD) - desired_version=$(cat ${TORCHCHAT_ROOT}/install/.pins/et-pin.txt) + get_executorch_commit_hash_pin - if [ "$current_version" == "$desired_version" ]; then + if [ "$current_version" == "$nightly_commit_hash" ]; then echo "ExecuTorch is already cloned with the correct version. Skipping clone." popd return @@ -77,31 +87,16 @@ clone_executorch() { install_executorch_python_libs() { - if [ ! -d "${TORCHCHAT_ROOT}/${ET_BUILD_DIR}" ]; then - echo "Directory ${TORCHCHAT_ROOT}/${ET_BUILD_DIR} does not exist." - echo "Make sure you run clone_executorch" - exit 1 - fi - pushd ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src - cd executorch - - echo "Building and installing python libraries" - if [ "${ENABLE_ET_PYBIND}" = false ]; then - echo "Not installing pybind" - bash ./install_requirements.sh - else - echo "Installing pybind" - bash ./install_requirements.sh --pybind xnnpack - fi - + NIGHTLY=$(cat ${TORCHCHAT_ROOT}/install/.pins/et-pin.txt | tr -d "-") + echo "Installing ExecuTorch nightly 0.5.0.dev${NIGHTLY}" + pip install executorch=="0.5.0.dev${NIGHTLY}" --extra-index-url https://download.pytorch.org/whl/nightly/cpu # TODO: figure out the root cause of 'AttributeError: module 'evaluate' # has no attribute 'utils'' error from evaluate CI jobs and remove # `import lm_eval` from torchchat.py since it requires a specific version # of numpy. pip install numpy=='1.26.4' - pip3 list - popd + pip list } COMMON_CMAKE_ARGS="\ From c06a71bc91f877d7e99aec36571e6a1b88c6cd69 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Mon, 21 Oct 2024 10:35:03 -0700 Subject: [PATCH 02/14] Update to ET 1021 nightly to incorporate some fixes Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- install/.pins/et-pin.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index 2d138e8b8..335fe4e2b 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -2024-10-17 +2024-10-21 From 01bb19afbda5228718f14e8c60f07e1c919abb48 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Mon, 21 Oct 2024 10:45:29 -0700 Subject: [PATCH 03/14] Use 1020 Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: --- install/.pins/et-pin.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index 335fe4e2b..07988127a 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -2024-10-21 +2024-10-20 From 55d5a42da7303b33dc4a334c8ee77efa037c0e9f Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Fri, 25 Oct 2024 10:17:07 -0700 Subject: [PATCH 04/14] Update to 1024 nightly pin --- install/.pins/et-pin.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index 07988127a..bff21f43c 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -2024-10-20 +2024-10-24 From 495d9066690a07997e35d6dc7e9834e1249d53ef Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Fri, 25 Oct 2024 11:00:04 -0700 Subject: [PATCH 05/14] Update pin to 1025 --- install/.pins/et-pin.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index bff21f43c..3e0f5db1f 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -2024-10-24 +2024-10-25 From 07dba10fe3cdc72817dca061706488c6c4862983 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 30 Oct 2024 10:45:06 -0700 Subject: [PATCH 06/14] Update to 1030 --- install/.pins/et-pin.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index 3e0f5db1f..d24fd2595 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -2024-10-25 +2024-10-30 From 6046e7b1d0453654be42eba90283dd34a7b3e58c Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 30 Oct 2024 16:05:19 -0700 Subject: [PATCH 07/14] Remove redundant Install ExecuTorch python from runner-et step --- .github/workflows/pull.yml | 8 -------- torchchat/utils/scripts/install_et.sh | 4 +--- torchchat/utils/scripts/install_utils.sh | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index ee7270a5d..0fb519b3e 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -947,14 +947,6 @@ jobs: run: | echo "Installing ExecuTorch" bash torchchat/utils/scripts/install_et.sh - - name: Install ExecuTorch python - run: | - echo "Install ExecuTorch python" - export TORCHCHAT_ROOT=$PWD - export ET_BUILD_DIR="et-build" - ENABLE_ET_PYBIND="${1:-true}" - source "torchchat/utils/scripts/install_utils.sh" - install_executorch_python_libs $ENABLE_ET_PYBIND - name: Install runner run: | echo "Installing runner" diff --git a/torchchat/utils/scripts/install_et.sh b/torchchat/utils/scripts/install_et.sh index 8062a8316..4e85444ea 100755 --- a/torchchat/utils/scripts/install_et.sh +++ b/torchchat/utils/scripts/install_et.sh @@ -13,10 +13,8 @@ if [ "${ET_BUILD_DIR}" == "" ]; then ET_BUILD_DIR="et-build" fi -ENABLE_ET_PYBIND="${1:-true}" - pushd ${TORCHCHAT_ROOT} find_cmake_prefix_path clone_executorch -install_executorch_libs $ENABLE_ET_PYBIND +install_executorch_libs popd diff --git a/torchchat/utils/scripts/install_utils.sh b/torchchat/utils/scripts/install_utils.sh index 286ad335c..2d3887358 100644 --- a/torchchat/utils/scripts/install_utils.sh +++ b/torchchat/utils/scripts/install_utils.sh @@ -161,7 +161,7 @@ install_executorch_libs() { EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT_VAR=OFF EXECUTORCH_BUILD_KERNELS_CUSTOM_VAR=OFF install_executorch_cpp_libs - install_executorch_python_libs $1 + install_executorch_python_libs } clone_torchao() { From 4f40b86477a3f0ef1c882423e8373250651528f7 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 30 Oct 2024 16:17:46 -0700 Subject: [PATCH 08/14] Bump torch version to 1019 --- .github/workflows/pull.yml | 5 +++-- install/install_requirements.sh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 0fb519b3e..6647e3d99 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -453,9 +453,9 @@ jobs: ./install/install_requirements.sh export TORCHCHAT_ROOT=$PWD - ./torchchat/utils/scripts/install_et.sh + source ./torchchat/utils/scripts/install_utils.sh + install_executorch_python_libs - pip3 list python3 -c 'import torch;print(f"torch: {torch.__version__, torch.version.git_version}")' python3 -c 'import torchvision;print(f"torchvision: {torchvision.__version__, torchvision.version.git_version}")' @@ -953,6 +953,7 @@ jobs: bash torchchat/utils/scripts/build_native.sh et - name: Run inference run: | + set -eou pipefail python torchchat.py download stories15M wget -O ./tokenizer.model https://github.com/karpathy/llama2.c/raw/master/tokenizer.model diff --git a/install/install_requirements.sh b/install/install_requirements.sh index c86ff517e..282dde922 100755 --- a/install/install_requirements.sh +++ b/install/install_requirements.sh @@ -47,10 +47,10 @@ fi # NOTE: If a newly-fetched version of the executorch repo changes the value of # PYTORCH_NIGHTLY_VERSION, you should re-run this script to install the necessary # package versions. -PYTORCH_NIGHTLY_VERSION=dev20241007 +PYTORCH_NIGHTLY_VERSION=dev20241019 # Nightly version for torchvision -VISION_NIGHTLY_VERSION=dev20241007 +VISION_NIGHTLY_VERSION=dev20241019 # Nightly version for torchtune TUNE_NIGHTLY_VERSION=dev20241010 From b84c13b84af6cf4d3ad2ec821adb26aaab80fe25 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 30 Oct 2024 16:43:55 -0700 Subject: [PATCH 09/14] Use package_aoti API --- torchchat/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchchat/export.py b/torchchat/export.py index 7a7923119..2503470a9 100644 --- a/torchchat/export.py +++ b/torchchat/export.py @@ -41,7 +41,7 @@ def export_for_server( package: bool = True, ) -> str: """ - Export the model using AOT Compile to get a .dso for server use cases. + Export the model using AOT Compile to get a .pt2 for server use cases. Args: model: The model to be exported. From a26c231b6e80f96e6212fddf7111545dde800551 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 30 Oct 2024 16:47:57 -0700 Subject: [PATCH 10/14] Import --- torchchat/export.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torchchat/export.py b/torchchat/export.py index 2503470a9..534216b3e 100644 --- a/torchchat/export.py +++ b/torchchat/export.py @@ -50,6 +50,8 @@ def export_for_server( Returns: The path to the exported model. """ + from torch._inductor.package import package_aoti + if dynamic_shapes: example_inputs = ( torch.tensor([[1, 9038, 2501, 263, 931]], dtype=torch.int, device=device), From 4600f11af52b1fde3e0d13ca60e53a69475c99dc Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Wed, 30 Oct 2024 16:59:15 -0700 Subject: [PATCH 11/14] Fix AOTI runner --- .github/workflows/pull.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 6647e3d99..5bdb364db 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -927,6 +927,11 @@ jobs: run: | echo "Intalling pip3 packages" ./install/install_requirements.sh + + # Install ET + source ./torchchat/utils/scripts/install_utils.sh + install_executorch_python_libs + pip3 list python3 -c 'import torch;print(f"torch: {torch.__version__, torch.version.git_version}")' - name: Set ET git sha From 46a924f3b9586664663c8df67b4d5918d0ffddbe Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Thu, 31 Oct 2024 09:32:57 -0700 Subject: [PATCH 12/14] Update --- .github/workflows/pull.yml | 1 + torchchat/utils/scripts/build_native.sh | 8 +++++--- torchchat/utils/scripts/install_utils.sh | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 5bdb364db..96561ab64 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -929,6 +929,7 @@ jobs: ./install/install_requirements.sh # Install ET + export TORCHCHAT_ROOT=$PWD source ./torchchat/utils/scripts/install_utils.sh install_executorch_python_libs diff --git a/torchchat/utils/scripts/build_native.sh b/torchchat/utils/scripts/build_native.sh index 3c2c1c846..72260fbdd 100755 --- a/torchchat/utils/scripts/build_native.sh +++ b/torchchat/utils/scripts/build_native.sh @@ -66,6 +66,9 @@ fi pushd ${TORCHCHAT_ROOT} git submodule update --init git submodule sync + +find_cmake_prefix_path + if [[ "$TARGET" == "et" ]]; then if [ ! -d "${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install" ]; then echo "Directory ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install does not exist." @@ -81,7 +84,6 @@ if [[ "$TARGET" == "et" ]]; then fi source "$(dirname "${BASH_SOURCE[0]}")/install_utils.sh" - find_cmake_prefix_path EXECUTORCH_INCLUDE_DIRS="${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/include;${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src" EXECUTORCH_LIBRARIES="${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/lib/libexecutorch_no_prim_ops.a;${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/lib/libextension_threadpool.a;${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/lib/libcpuinfo.a;${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install/lib/libpthreadpool.a" install_torchao_executorch_ops @@ -91,9 +93,9 @@ popd # CMake commands if [[ "$TARGET" == "et" ]]; then - cmake -S . -B ./cmake-out -DCMAKE_PREFIX_PATH=`python3 -c 'import torch;print(torch.utils.cmake_prefix_path)'` -DLINK_TORCHAO_OPS="${LINK_TORCHAO_OPS}" -DET_USE_ADAPTIVE_THREADS=ON -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=1" -G Ninja + cmake -S . -B ./cmake-out -DCMAKE_PREFIX_PATH="${MY_CMAKE_PREFIX_PATH}" -DLINK_TORCHAO_OPS="${LINK_TORCHAO_OPS}" -DET_USE_ADAPTIVE_THREADS=ON -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=1" -G Ninja else - cmake -S . -B ./cmake-out -DCMAKE_PREFIX_PATH=`python3 -c 'import torch;print(torch.utils.cmake_prefix_path)'` -DLINK_TORCHAO_OPS="${LINK_TORCHAO_OPS}" -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" -G Ninja + cmake -S . -B ./cmake-out -DCMAKE_PREFIX_PATH="${MY_CMAKE_PREFIX_PATH}" -DLINK_TORCHAO_OPS="${LINK_TORCHAO_OPS}" -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" -G Ninja fi cmake --build ./cmake-out --target "${TARGET}"_run diff --git a/torchchat/utils/scripts/install_utils.sh b/torchchat/utils/scripts/install_utils.sh index 2d3887358..6b4b53f8f 100644 --- a/torchchat/utils/scripts/install_utils.sh +++ b/torchchat/utils/scripts/install_utils.sh @@ -23,7 +23,7 @@ install_pip_dependencies() { } function find_cmake_prefix_path() { - path=`python3 -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"` + path=`python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"` MY_CMAKE_PREFIX_PATH=$path } From a36d998d9f22c7039f64960198ea386bfd4f8f3a Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Fri, 1 Nov 2024 15:00:43 -0700 Subject: [PATCH 13/14] Cleanup --- torchchat/export.py | 1 - torchchat/utils/scripts/install_utils.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/torchchat/export.py b/torchchat/export.py index 534216b3e..0829c9c33 100644 --- a/torchchat/export.py +++ b/torchchat/export.py @@ -50,7 +50,6 @@ def export_for_server( Returns: The path to the exported model. """ - from torch._inductor.package import package_aoti if dynamic_shapes: example_inputs = ( diff --git a/torchchat/utils/scripts/install_utils.sh b/torchchat/utils/scripts/install_utils.sh index 6b4b53f8f..2d3887358 100644 --- a/torchchat/utils/scripts/install_utils.sh +++ b/torchchat/utils/scripts/install_utils.sh @@ -23,7 +23,7 @@ install_pip_dependencies() { } function find_cmake_prefix_path() { - path=`python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"` + path=`python3 -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"` MY_CMAKE_PREFIX_PATH=$path } From f6a303306bc3972c26bc4bd8340664b11c0ff266 Mon Sep 17 00:00:00 2001 From: Mengwei Liu Date: Fri, 1 Nov 2024 16:06:45 -0700 Subject: [PATCH 14/14] Use 20241101 --- install/.pins/et-pin.txt | 2 +- install/install_requirements.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/install/.pins/et-pin.txt b/install/.pins/et-pin.txt index d24fd2595..7309e9c44 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -2024-10-30 +2024-11-01 diff --git a/install/install_requirements.sh b/install/install_requirements.sh index 282dde922..4afa655e9 100755 --- a/install/install_requirements.sh +++ b/install/install_requirements.sh @@ -47,10 +47,10 @@ fi # NOTE: If a newly-fetched version of the executorch repo changes the value of # PYTORCH_NIGHTLY_VERSION, you should re-run this script to install the necessary # package versions. -PYTORCH_NIGHTLY_VERSION=dev20241019 +PYTORCH_NIGHTLY_VERSION=dev20241030 # Nightly version for torchvision -VISION_NIGHTLY_VERSION=dev20241019 +VISION_NIGHTLY_VERSION=dev20241030 # Nightly version for torchtune TUNE_NIGHTLY_VERSION=dev20241010