Skip to content

Commit 0151665

Browse files
committed
Update on "Reuse GELU implementation from PyTorch core"
kernels/optimized doesn't need to support embedded systems, so it can just take a header-only dep on PyTorch. Note that, because we will pick up Sleef internally and ignore it externally thanks to ATen vec, this PR gets to enable optimized GELU in OSS. Testing: CI to make sure this doesn't break mobile build modes; happy to take advice on anything not currently covered that might break. Differential Revision: [D66335522](https://our.internmc.facebook.com/intern/diff/D66335522/) [ghstack-poisoned]
2 parents ce8c770 + c6299b6 commit 0151665

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1515
fi
1616
which "${PYTHON_EXECUTABLE}"
1717
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
18-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
1918

2019
install_executorch_and_backend_lib() {
2120
echo "Installing executorch and xnnpack backend"
@@ -29,7 +28,6 @@ install_executorch_and_backend_lib() {
2928
-DANDROID_ABI="${ANDROID_ABI}" \
3029
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
3130
-DCMAKE_BUILD_TYPE=Release \
32-
-DCMAKE_FIND_ROOT_PATH="${SITE_PACKAGES}" \
3331
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
3432
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
3533
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \

build/build_android_llm_demo.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ build_android_native_library() {
4040
else
4141
EXECUTORCH_BUILD_NEURON=OFF
4242
fi
43-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
4443

4544
cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
46-
-DCMAKE_FIND_ROOT_PATH="${SITE_PACKAGES}" \
4745
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
4846
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
4947
-DANDROID_ABI="${ANDROID_ABI}" \
@@ -78,7 +76,6 @@ build_android_native_library() {
7876
-DANDROID_ABI="${ANDROID_ABI}" \
7977
-DANDROID_PLATFORM=android-26 \
8078
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
81-
-DCMAKE_FIND_ROOT_PATH="${SITE_PACKAGES}" \
8279
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
8380
-DEXECUTORCH_ENABLE_LOGGING=ON \
8481
-DEXECUTORCH_LOG_LEVEL=Info \

kernels/optimized/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ message("Generated files ${gen_command_sources}")
6363

6464
list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
6565
add_library(optimized_kernels ${_optimized_kernels__srcs})
66-
find_package(Torch CONFIG REQUIRED)
66+
# We require Torch headers, which setup.py puts in CMAKE_PREFIX_PATH
67+
# for us. Toolchains that we might be using for cross-compiling could
68+
# set CMAKE_FIND_ROOT_PATH, which prevents find_package from finding
69+
# headers not rooted under CMAKE_FIND_ROOT_PATH. This is reasonable
70+
# for binary dependencies because they probably aren't built for the
71+
# target platform, but for our header-only use case, we should just
72+
# ignore CMAKE_FIND_ROOT_PATH.
73+
find_package(Torch CONFIG REQUIRED NO_CMAKE_FIND_ROOT_PATH)
6774
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS})
6875
target_link_libraries(
6976
optimized_kernels PRIVATE executorch_core cpublas extension_threadpool

0 commit comments

Comments
 (0)