diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index ee7270a5d..96561ab64 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}")' @@ -927,6 +927,12 @@ jobs: run: | echo "Intalling pip3 packages" ./install/install_requirements.sh + + # Install ET + export TORCHCHAT_ROOT=$PWD + 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 @@ -947,20 +953,13 @@ 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" 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/.pins/et-pin.txt b/install/.pins/et-pin.txt index e61fae3a5..7309e9c44 100644 --- a/install/.pins/et-pin.txt +++ b/install/.pins/et-pin.txt @@ -1 +1 @@ -72b3bb3194c611f7c4861e6f3b24af5de868af72 +2024-11-01 diff --git a/install/install_requirements.sh b/install/install_requirements.sh index 6344509d8..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=dev20241002 +PYTORCH_NIGHTLY_VERSION=dev20241030 # Nightly version for torchvision -VISION_NIGHTLY_VERSION=dev20241002 +VISION_NIGHTLY_VERSION=dev20241030 # Nightly version for torchtune TUNE_NIGHTLY_VERSION=dev20241010 diff --git a/torchchat/export.py b/torchchat/export.py index 7a7923119..0829c9c33 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. @@ -50,6 +50,7 @@ def export_for_server( Returns: The path to the exported model. """ + if dynamic_shapes: example_inputs = ( torch.tensor([[1, 9038, 2501, 263, 931]], dtype=torch.int, device=device), 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_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 84966cc35..2d3887358 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="\ @@ -166,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() {