Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Closed
19 changes: 9 additions & 10 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}")'

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion install/.pins/et-pin.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
72b3bb3194c611f7c4861e6f3b24af5de868af72
2024-11-01
4 changes: 2 additions & 2 deletions install/install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion torchchat/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand Down
8 changes: 5 additions & 3 deletions torchchat/utils/scripts/build_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -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

Expand Down
4 changes: 1 addition & 3 deletions torchchat/utils/scripts/install_et.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 18 additions & 23 deletions torchchat/utils/scripts/install_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ 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

mkdir -p ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src
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
Expand All @@ -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
Expand All @@ -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="\
Expand Down Expand Up @@ -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() {
Expand Down
Loading