Skip to content

Commit c00c798

Browse files
authored
Automatically put torch in CMAKE_PREFIX_PATH so users/scripts don't have to (#8474)
Removed all explicit setting of CMAKE_PREFIX_PATH to the torch directory in favor of automatically doing it when we find_package(Torch). Hat tip to @huydhn for showing the way to only find torch once.
1 parent cb2b174 commit c00c798

22 files changed

+62
-69
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1414
PYTHON_EXECUTABLE=python3
1515
fi
1616
which "${PYTHON_EXECUTABLE}"
17-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
1817

1918
install_executorch_and_backend_lib() {
2019
echo "Installing executorch and xnnpack backend"
@@ -28,7 +27,6 @@ install_executorch_and_backend_lib() {
2827
-DANDROID_ABI="${ANDROID_ABI}" \
2928
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
3029
-DCMAKE_BUILD_TYPE=Release \
31-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
3230
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
3331
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
3432
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
@@ -54,7 +52,6 @@ build_llama_runner() {
5452
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
5553
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
5654
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
57-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
5855
-Bcmake-android-out/examples/models/llama examples/models/llama
5956

6057
cmake --build cmake-android-out/examples/models/llama -j4 --config Release

.ci/scripts/test_llama.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ cmake_install_executorch_libraries() {
154154
rm -rf cmake-out
155155
retry cmake \
156156
-DCMAKE_INSTALL_PREFIX=cmake-out \
157-
-DCMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')" \
158157
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
159158
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
160159
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \

.ci/scripts/test_llava.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ NPROC=8
3131
if hash nproc &> /dev/null; then NPROC=$(nproc); fi
3232

3333
python_lib=$($PYTHON_EXECUTABLE -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
34-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
3534
EXECUTORCH_COMMON_CMAKE_ARGS=" \
3635
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
3736
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
@@ -48,7 +47,6 @@ EXECUTORCH_COMMON_CMAKE_ARGS=" \
4847
cmake_install_executorch_libraries() {
4948
cmake \
5049
${EXECUTORCH_COMMON_CMAKE_ARGS} \
51-
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" \
5250
-B${BUILD_DIR} .
5351

5452
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${CMAKE_BUILD_TYPE}
@@ -59,7 +57,6 @@ cmake_install_executorch_libraries_for_android() {
5957
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
6058
-DANDROID_ABI=arm64-v8a \
6159
${EXECUTORCH_COMMON_CMAKE_ARGS} \
62-
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" \
6360
-B${BUILD_DIR} .
6461

6562
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${CMAKE_BUILD_TYPE}
@@ -80,7 +77,7 @@ cmake_build_llava_runner() {
8077

8178
cmake \
8279
${LLAVA_COMMON_CMAKE_ARGS} \
83-
-DCMAKE_PREFIX_PATH="$python_lib;${CMAKE_PREFIX_PATH}" \
80+
-DCMAKE_PREFIX_PATH="$python_lib" \
8481
-B${BUILD_DIR}/${dir} \
8582
${dir}
8683

@@ -96,7 +93,7 @@ cmake_build_llava_runner_for_android() {
9693
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
9794
-DANDROID_ABI=arm64-v8a \
9895
${LLAVA_COMMON_CMAKE_ARGS} \
99-
-DCMAKE_PREFIX_PATH="$python_lib;${CMAKE_PREFIX_PATH}" \
96+
-DCMAKE_PREFIX_PATH="$python_lib" \
10097
-DLLAVA_RUNNER_NO_TORCH_DUMMY_IMAGE=ON \
10198
-B${BUILD_DIR}/${dir} \
10299
${dir}

.ci/scripts/test_model.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ prepare_artifacts_upload() {
5050

5151
build_cmake_executor_runner() {
5252
echo "Building executor_runner"
53-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
5453
rm -rf ${CMAKE_OUTPUT_DIR}
5554
cmake -DCMAKE_BUILD_TYPE=Debug \
5655
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
5756
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
58-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
5957
-B${CMAKE_OUTPUT_DIR} .
6058

6159
cmake --build ${CMAKE_OUTPUT_DIR} -j4 --config Debug
@@ -100,14 +98,12 @@ test_model() {
10098

10199
build_cmake_xnn_executor_runner() {
102100
echo "Building xnn_executor_runner"
103-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
104101

105102
(rm -rf ${CMAKE_OUTPUT_DIR} \
106103
&& mkdir ${CMAKE_OUTPUT_DIR} \
107104
&& cd ${CMAKE_OUTPUT_DIR} \
108105
&& retry cmake -DCMAKE_BUILD_TYPE=Release \
109106
-DEXECUTORCH_BUILD_XNNPACK=ON \
110-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
111107
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
112108

113109
cmake --build ${CMAKE_OUTPUT_DIR} -j4

.ci/scripts/test_phi_3_mini.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ NPROC=8
2222
if hash nproc &> /dev/null; then NPROC=$(nproc); fi
2323

2424
cmake_install_executorch_libraries() {
25-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
2625
cmake -DPYTHON_EXECUTABLE=python \
2726
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
28-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
2927
-DEXECUTORCH_ENABLE_LOGGING=1 \
3028
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
3129
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
@@ -41,10 +39,8 @@ cmake_install_executorch_libraries() {
4139
}
4240

4341
cmake_build_phi_3_mini() {
44-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
4542
cmake -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
4643
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
47-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
4844
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
4945
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
5046
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \

.ci/scripts/test_quantized_aot_lib.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ CMAKE_OUTPUT_DIR=cmake-out
1616

1717
build_cmake_quantized_aot_lib() {
1818
echo "Building quantized aot lib"
19-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
20-
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
2119
(rm -rf ${CMAKE_OUTPUT_DIR} \
2220
&& mkdir ${CMAKE_OUTPUT_DIR} \
2321
&& cd ${CMAKE_OUTPUT_DIR} \
2422
&& retry cmake -DCMAKE_BUILD_TYPE=Release \
25-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
2623
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
2724
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
2825

.ci/scripts/utils.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ cmake_install_executorch_lib() {
136136
clean_executorch_install_folders
137137
retry cmake -DBUCK2="$BUCK" \
138138
-DCMAKE_INSTALL_PREFIX=cmake-out \
139-
-DCMAKE_PREFIX_PATH="$($PYTHON_EXECUTABLE -c 'import torch as _; print(_.__path__[0])')" \
140139
-DCMAKE_BUILD_TYPE=Release \
141140
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
142141
-Bcmake-out .

.github/workflows/trunk.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ jobs:
394394
rm -rf cmake-out
395395
cmake \
396396
-DCMAKE_INSTALL_PREFIX=cmake-out \
397-
-DCMAKE_PREFIX_PATH="$(python -c 'import torch as _; print(_.__path__[0])')" \
398397
-DCMAKE_BUILD_TYPE=Release \
399398
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
400399
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
@@ -412,7 +411,6 @@ jobs:
412411
cmake \
413412
-DCMAKE_INSTALL_PREFIX=cmake-out \
414413
-DCMAKE_BUILD_TYPE=Release \
415-
-DCMAKE_PREFIX_PATH="$(python -c 'import torch as _; print(_.__path__[0])')" \
416414
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
417415
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
418416
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,7 @@ if(EXECUTORCH_BUILD_PYBIND)
761761
endif()
762762

763763
# find pytorch lib, to allow pybind to take at::Tensor as input/output
764-
if(NOT TARGET torch)
765-
find_package(Torch CONFIG REQUIRED)
766-
endif()
764+
find_package_torch()
767765
find_library(
768766
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
769767
)

backends/arm/scripts/build_quantized_ops_aot_lib.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ build_type="Release"
1111

1212
build_type=${1:-$build_type}
1313

14-
SITE_PACKAGES="$(python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
15-
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
16-
1714
echo "--------------------------------------------------------------------------------"
1815
echo "Build .so library to register quant ops with AoT flow ${build_type} into '$(echo $(pwd))/cmake-out-aot-lib'"
1916
echo "--------------------------------------------------------------------------------"
@@ -23,7 +20,6 @@ echo "--------------------------------------------------------------------------
2320
rm -f cmake-out-aot-lib/CMakeCache.txt
2421

2522
CXXFLAGS="-fno-exceptions -fno-rtti" cmake \
26-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
2723
-DCMAKE_BUILD_TYPE=${build_type} \
2824
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
2925
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \

build/Codegen.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# Selective build. See codegen/tools/gen_oplist.py for how to use these
1111
# arguments.
12+
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
13+
1214
function(gen_selected_ops)
1315
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS)
1416
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})
@@ -145,18 +147,13 @@ function(gen_custom_ops_aot_lib)
145147
${_out_dir}/RegisterCPUCustomOps.cpp ${_out_dir}/RegisterSchema.cpp
146148
${_out_dir}/CustomOpsNativeFunctions.h "${GEN_KERNEL_SOURCES}"
147149
)
148-
# Find `Torch`.
149-
if(NOT TARGET torch)
150-
find_package(Torch REQUIRED)
151-
endif()
150+
find_package_torch()
152151
# This lib uses ATen lib, so we explicitly enable rtti and exceptions.
153152
target_compile_options(${GEN_LIB_NAME} PRIVATE -frtti -fexceptions)
154153
target_compile_definitions(${GEN_LIB_NAME} PRIVATE USE_ATEN_LIB=1)
155154
include_directories(${TORCH_INCLUDE_DIRS})
156155
target_link_libraries(${GEN_LIB_NAME} PRIVATE torch)
157156

158-
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
159-
160157
target_link_options_shared_lib(${GEN_LIB_NAME})
161158
if(TARGET portable_lib)
162159
target_link_libraries(${GEN_LIB_NAME} PRIVATE portable_lib)

build/Utils.cmake

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,61 @@ function(resolve_python_executable)
328328
endif()
329329
endfunction()
330330

331-
# find_package(Torch CONFIG REQUIRED) replacement for targets that
332-
# have a header-only Torch dependency. Because find_package sets
333-
# variables in the parent scope, we use a macro to preserve this
334-
# rather than maintaining our own list of those variables.
331+
# find_package(Torch CONFIG REQUIRED) replacement for targets that have a
332+
# header-only Torch dependency. Because find_package sets variables in the
333+
# parent scope, we use a macro to preserve this rather than maintaining our own
334+
# list of those variables.
335335
macro(find_package_torch_headers)
336-
# We cannot simply use CMAKE_FIND_ROOT_PATH_BOTH, because that does
337-
# not propagate into TorchConfig.cmake.
336+
# We cannot simply use CMAKE_FIND_ROOT_PATH_BOTH, because that does not
337+
# propagate into TorchConfig.cmake.
338338
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
339-
set(OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}})
339+
set(OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}
340+
${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}}
341+
)
340342
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} BOTH)
341343
endforeach()
344+
find_package_torch()
345+
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
346+
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}
347+
${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}}
348+
)
349+
endforeach()
350+
endmacro()
351+
352+
# Add the Torch CMake configuration to CMAKE_PREFIX_PATH so that find_package
353+
# can find Torch.
354+
function(add_torch_to_cmake_prefix_path)
355+
if(NOT PYTHON_EXECUTABLE)
356+
resolve_python_executable()
357+
endif()
358+
execute_process(
359+
COMMAND "${PYTHON_EXECUTABLE}" -c
360+
"import torch as _; print(_.__path__[0], end='')"
361+
OUTPUT_VARIABLE _tmp_torch_path
362+
ERROR_VARIABLE _tmp_torch_path_error
363+
RESULT_VARIABLE _tmp_torch_path_result COMMAND_ECHO STDERR
364+
OUTPUT_STRIP_TRAILING_WHITESPACE
365+
)
366+
if(NOT _tmp_torch_path_result EQUAL 0)
367+
message("Error while adding torch to CMAKE_PREFIX_PATH. "
368+
"Exit code: ${_tmp_torch_path_result}"
369+
)
370+
message("Output:\n${_tmp_torch_path}")
371+
message(FATAL_ERROR "Error:\n${_tmp_torch_path_error}")
372+
endif()
373+
list(APPEND CMAKE_PREFIX_PATH "${_tmp_torch_path}")
374+
set(CMAKE_PREFIX_PATH
375+
"${CMAKE_PREFIX_PATH}"
376+
PARENT_SCOPE
377+
)
378+
endfunction()
379+
380+
# Replacement for find_package(Torch CONFIG REQUIRED); sets up CMAKE_PREFIX_PATH
381+
# first and only does the find once. If you have a header-only Torch dependency,
382+
# use find_package_torch_headers instead!
383+
macro(find_package_torch)
342384
if(NOT TARGET torch)
385+
add_torch_to_cmake_prefix_path()
343386
find_package(Torch CONFIG REQUIRED)
344387
endif()
345-
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
346-
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}})
347-
endforeach()
348388
endmacro()

build/build_android_llm_demo.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1111
PYTHON_EXECUTABLE=python3
1212
fi
1313
which "${PYTHON_EXECUTABLE}"
14-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
1514

1615
build_jar() {
1716
pushd extension/android
@@ -42,7 +41,6 @@ build_android_native_library() {
4241
fi
4342

4443
cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
45-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
4644
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
4745
-DANDROID_ABI="${ANDROID_ABI}" \
4846
-DANDROID_PLATFORM=android-26 \
@@ -76,7 +74,6 @@ build_android_native_library() {
7674
-DANDROID_ABI="${ANDROID_ABI}" \
7775
-DANDROID_PLATFORM=android-26 \
7876
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
79-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
8077
-DEXECUTORCH_ENABLE_LOGGING=ON \
8178
-DEXECUTORCH_LOG_LEVEL=Info \
8279
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \

build/build_apple_frameworks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ cmake_build() {
150150
mkdir "$platform" && cd "$platform" || exit 1
151151
cmake "$SOURCE_ROOT_DIR" -G Xcode \
152152
-DCMAKE_BUILD_TYPE="$MODE" \
153-
-DCMAKE_PREFIX_PATH="$($PYTHON -c 'import torch as _; print(_.__path__[0])')" \
154153
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
155154
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD="c++17" \
156155
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY="libc++" \

docs/source/executorch-arm-delegate-tutorial.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,13 @@ python3 -m examples.arm.aot_arm_compiler --model_name="add" --delegate
228228
Before generating the `.pte` file for delegated quantized networks like MobileNetV2, we need to build the `quantized_ops_aot_lib`
229229

230230
```bash
231-
SITE_PACKAGES="$(python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
232-
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
233231

234232
cd <executorch_root_dir>
235233
mkdir -p cmake-out-aot-lib
236234
cmake -DCMAKE_BUILD_TYPE=Release \
237235
-DEXECUTORCH_BUILD_XNNPACK=OFF \
238236
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
239237
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
240-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
241238
-DPYTHON_EXECUTABLE=python3 \
242239
-Bcmake-out-aot-lib \
243240
"${et_root_dir}"

examples/models/llava/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if(LLAVA_RUNNER_NO_TORCH_DUMMY_IMAGE)
7979
add_definitions(-DLLAVA_NO_TORCH_DUMMY_IMAGE=1)
8080
message("Buidling the runner without Torch, feeding a dummy image!")
8181
else()
82-
find_package(Torch CONFIG REQUIRED)
82+
find_package_torch()
8383
endif()
8484

8585
#

examples/portable/custom_ops/test_custom_ops.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ get_shared_lib_ext() {
5353

5454
test_cmake_custom_op_2() {
5555
local model_name='custom_ops_2'
56-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
57-
CMAKE_PREFIX_PATH="$PWD/cmake-out/lib/cmake/ExecuTorch;${SITE_PACKAGES}/torch"
56+
CMAKE_PREFIX_PATH="$PWD/cmake-out/lib/cmake/ExecuTorch"
5857

5958
local example_dir=examples/portable/custom_ops
6059
local build_dir=cmake-out/${example_dir}

examples/xnnpack/quantization/test_quantize.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ test_buck2_quantization() {
4444

4545
test_cmake_quantization() {
4646
echo "Building quantized ops shared library"
47-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
48-
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
4947

5048
clean_executorch_install_folders
5149

@@ -56,7 +54,6 @@ test_cmake_quantization() {
5654
-DEXECUTORCH_BUILD_XNNPACK="$EXECUTORCH_BUILD_XNNPACK" \
5755
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
5856
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
59-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
6057
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
6158

6259
cmake --build cmake-out -j4

extension/llm/custom_ops/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ install(TARGETS custom_ops DESTINATION lib)
6969

7070
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
7171
# Add a AOT library
72-
if(NOT TARGET torch)
73-
find_package(Torch CONFIG REQUIRED)
74-
endif()
72+
find_package_torch()
7573
add_library(
7674
custom_ops_aot_lib SHARED
7775
${_custom_ops__srcs}

extension/llm/export/quantizer_lib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ def check_embedding_byte_registered():
107107
raise RuntimeError(
108108
"Need to specify shared library path to register quantized ops (and their out variants) into EXIR.\n"
109109
"Follow the following steps to build the needed lib via cmake.\n"
110-
'Use `python -c "import torch as _; print(_.__path__)"` to find where torch package is installed.\n'
111-
"Set that as TORCH_PACKAGE_DIR.\n"
112110
"Then from root executorch dir do the following:\n"
113-
"rm -rf cmake-out && mkdir cmake-out && (cd cmake-out && cmake -DBUCK2=<path-to-buck2> -DCMAKE_PREFIX_PATH=$TORCH_PACKAGE_DIR -DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON ..) && cmake --build . -j16\n"
111+
"rm -rf cmake-out && mkdir cmake-out && (cd cmake-out && cmake -DBUCK2=<path-to-buck2> -DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON ..) && cmake --build . -j16\n"
114112
'To find the location of the lib: find cmake-out -name "libquantized_ops_aot_lib*"\n'
115113
"Then specify the said library via -s <path to libquantized_ops_aot_lib.so\n"
116114
)

0 commit comments

Comments
 (0)