forked from pytorch/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable android runner with custom sdpa op (pytorch#363)
Summary: This diff - refactors install_et.sh into a bunch of utils - Uses those utils in build_android.sh to minimize duplication. - Makes sure taht we are building with custom sdpa op Test Plan: Model export python export.py --quant '{"linear:a8w4dq" : {"groupsize": 256}}' --checkpoint-path /home/kimishpatel/models/llama2/stories/stories110M.pt --params-path /home/kimishpatel/models/llama2/stories/params.json --output-pte-path /tmp/stories110m_a8w4dq.pte python utils/tokenizer.py --tokenizer-model=/tmp/tokenizer.model linux: ./scripts/install_et.sh rm -rf build/cmake-out/ cmake -S ./runner-et -B build/cmake-out -G Ninja cmake --build ./build/cmake-out ./build/cmake-out/runner_et /tmp/stories110m_a8w4dq.pte -z /tmp/tokenizer.bin -t 0 -n 120 android: ./runner-et/build_android.sh adb push ./build/cmake-out-android/runner_et /data/local/tmp/ adb push /tmp/stories110m_a8w4dq.pte /data/local/tmp/ adb push /tmp/tokenizer.bin /data/local/tmp/ adb shell "cd /data/local/tmp && ./runner_et ./stories110m_a8w4dq.pte -z ./tokenizer.bin -t 0 -n 120" Will add build commands to ci in the next PR Reviewers: Subscribers: Tasks: Tags:
- Loading branch information
1 parent
ee280db
commit 1f7f01e
Showing
5 changed files
with
158 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/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. | ||
|
||
set -ex | ||
|
||
install_pip_dependencies() { | ||
echo "Intalling common pip packages" | ||
|
||
pip3 install wheel | ||
pip3 install "cmake>=3.19" | ||
pip3 install ninja | ||
pip3 install zstd | ||
pushd ${TORCHCHAT_ROOT} | ||
pip3 install -r ./requirements.txt | ||
popd | ||
} | ||
|
||
function find_cmake_prefix_path() { | ||
path=`python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"` | ||
MY_CMAKE_PREFIX_PATH=$path | ||
} | ||
|
||
clone_executorch() { | ||
echo "Cloning executorch to ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src" | ||
rm -rf ${TORCHCHAT_ROOT}/${ET_BUILD_DIR} | ||
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 viable/strict | ||
echo "Install executorch: submodule update" | ||
git submodule sync | ||
git submodule update --init | ||
|
||
echo "Applying fixes" | ||
cp ${TORCHCHAT_ROOT}/scripts/fixes_et/module.cpp ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src/executorch/extension/module/module.cpp # ET uses non-standard C++ that does not compile in GCC | ||
cp ${TORCHCHAT_ROOT}/scripts/fixes_et/managed_tensor.h ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src/executorch/extension/runner_util/managed_tensor.h # ET is missing headers for vector/memory. This causes downstream issues when building runner-et. | ||
popd | ||
} | ||
|
||
install_executorch_python_libs() { | ||
if [ ! -d "${TORCHCHAT_ROOT}/${ET_BUILD_DIR}" ]; then | ||
echo "Directory ${TORCHCHAT_ROOT}/${ET_BUILD_DIR} does not exist." | ||
echo "Make sur eyou run clone_executorch" | ||
exit 1 | ||
fi | ||
pushd ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/src | ||
cd executorch | ||
|
||
echo "Building and installing python libraries" | ||
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 | ||
pip3 list | ||
popd | ||
} | ||
|
||
install_executorch() { | ||
# AOT lib has to be build for model export | ||
# So by default it is built, and you can explicitly opt-out | ||
EXECUTORCH_BUILD_CUSTOM_OPS_AOT_VAR=OFF | ||
if [ "${EXECUTORCH_BUILD_CUSTOM_OPS_AOT}" == "" ]; then | ||
EXECUTORCH_BUILD_CUSTOM_OPS_AOT_VAR=ON | ||
fi | ||
|
||
# but for runner not | ||
EXECUTORCH_BUILD_CUSTOM_VAR=OFF | ||
if [ ! ["${EXECUTORCH_BUILD_CUSTOM}" == ""] ]; then | ||
EXECUTORCH_BUILD_CUSTOM_VAR=ON | ||
fi | ||
echo "${EXECUTORCH_BUILD_CUSTOM_OPS_AOT_VAR}" | ||
echo "${EXECUTORCH_BUILD_CUSTOM_VAR}" | ||
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 | ||
|
||
if [ "${CMAKE_OUT_DIR}" == "" ]; then | ||
CMAKE_OUT_DIR="cmake-out" | ||
fi | ||
|
||
CROSS_COMPILE_ARGS="" | ||
if [ "${CMAKE_OUT_DIR}" == "cmake-out-android" ]; then | ||
CROSS_COMPILE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DANDROID_ABI=${ANDROID_ABI} -DANDROID_PLATFORM=${ANDROID_PLATFORM}" | ||
fi | ||
|
||
echo "Building and installing C++ libraries" | ||
echo "Inside: ${PWD}" | ||
rm -rf ${CMAKE_OUT_DIR} | ||
mkdir ${CMAKE_OUT_DIR} | ||
cmake -DCMAKE_PREFIX_PATH=${MY_CMAKE_PREFIX_PATH} -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_ENABLE_LOGGING=ON -DEXECUTORCH_LOG_LEVEL=Info -DEXECUTORCH_BUILD_CUSTOM_OPS_AOT=${EXECUTORCH_BUILD_CUSTOM_OPS_AOT_VAR} -DEXECUTORCH_BUILD_CUSTOM=${EXECUTORCH_BUILD_CUSTOM_VAR} -DEXECUTORCH_BUILD_OPTIMIZED=ON -DEXECUTORCH_BUILD_OPTIMIZED=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON -DEXECUTORCH_BUILD_XNNPACK=ON ${CROSS_COMPILE_ARGS} -S . -B ${CMAKE_OUT_DIR} -G Ninja | ||
cmake --build ${CMAKE_OUT_DIR} | ||
cmake --install ${CMAKE_OUT_DIR} --prefix ${TORCHCHAT_ROOT}/${ET_BUILD_DIR}/install | ||
popd | ||
} |