Skip to content

Commit 5d568e8

Browse files
committed
Automatically put torch in CMAKE_PREFIX_PATH so users/scripts don't have to
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. ghstack-source-id: f66416e ghstack-comment-id: 2657445695 Pull Request resolved: #8474
1 parent 556a1a2 commit 5d568e8

22 files changed

+61
-70
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
@@ -752,9 +752,7 @@ if(EXECUTORCH_BUILD_PYBIND)
752752
endif()
753753

754754
# find pytorch lib, to allow pybind to take at::Tensor as input/output
755-
if(NOT TARGET torch)
756-
find_package(Torch CONFIG REQUIRED)
757-
endif()
755+
find_package_torch()
758756
find_library(
759757
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
760758
)

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
@@ -325,21 +325,61 @@ function(resolve_python_executable)
325325
endif()
326326
endfunction()
327327

328-
# find_package(Torch CONFIG REQUIRED) replacement for targets that
329-
# have a header-only Torch dependency. Because find_package sets
330-
# variables in the parent scope, we use a macro to preserve this
331-
# rather than maintaining our own list of those variables.
328+
# find_package(Torch CONFIG REQUIRED) replacement for targets that have a
329+
# header-only Torch dependency. Because find_package sets variables in the
330+
# parent scope, we use a macro to preserve this rather than maintaining our own
331+
# list of those variables.
332332
macro(find_package_torch_headers)
333-
# We cannot simply use CMAKE_FIND_ROOT_PATH_BOTH, because that does
334-
# not propagate into TorchConfig.cmake.
333+
# We cannot simply use CMAKE_FIND_ROOT_PATH_BOTH, because that does not
334+
# propagate into TorchConfig.cmake.
335335
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
336-
set(OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}})
336+
set(OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}
337+
${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}}
338+
)
337339
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} BOTH)
338340
endforeach()
341+
find_package_torch()
342+
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
343+
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}
344+
${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}}
345+
)
346+
endforeach()
347+
endmacro()
348+
349+
# Add the Torch CMake configuration to CMAKE_PREFIX_PATH so that find_package
350+
# can find Torch.
351+
function(add_torch_to_cmake_prefix_path)
352+
if(NOT PYTHON_EXECUTABLE)
353+
resolve_python_executable()
354+
endif()
355+
execute_process(
356+
COMMAND "${PYTHON_EXECUTABLE}" -c
357+
"import torch as _; print(_.__path__[0], end='')"
358+
OUTPUT_VARIABLE _tmp_torch_path
359+
ERROR_VARIABLE _tmp_torch_path_error
360+
RESULT_VARIABLE _tmp_torch_path_result COMMAND_ECHO STDERR
361+
OUTPUT_STRIP_TRAILING_WHITESPACE
362+
)
363+
if(NOT _tmp_torch_path_result EQUAL 0)
364+
message("Error while adding torch to CMAKE_PREFIX_PATH. "
365+
"Exit code: ${_tmp_torch_path_result}"
366+
)
367+
message("Output:\n${_tmp_torch_path}")
368+
message(FATAL_ERROR "Error:\n${_tmp_torch_path_error}")
369+
endif()
370+
list(APPEND CMAKE_PREFIX_PATH "${_tmp_torch_path}")
371+
set(CMAKE_PREFIX_PATH
372+
"${CMAKE_PREFIX_PATH}"
373+
PARENT_SCOPE
374+
)
375+
endfunction()
376+
377+
# Replacement for find_package(Torch CONFIG REQUIRED); sets up CMAKE_PREFIX_PATH
378+
# first and only does the find once. If you have a header-only Torch dependency,
379+
# use find_package_torch_headers instead!
380+
macro(find_package_torch)
339381
if(NOT TARGET torch)
382+
add_torch_to_cmake_prefix_path()
340383
find_package(Torch CONFIG REQUIRED)
341384
endif()
342-
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
343-
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}})
344-
endforeach()
345385
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
@@ -229,16 +229,13 @@ python3 -m examples.arm.aot_arm_compiler --model_name="add" --delegate
229229
Before generating the `.pte` file for delegated quantized networks like MobileNetV2, we need to build the `quantized_ops_aot_lib`
230230

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

235233
cd <executorch_root_dir>
236234
mkdir -p cmake-out-aot-lib
237235
cmake -DCMAKE_BUILD_TYPE=Release \
238236
-DEXECUTORCH_BUILD_XNNPACK=OFF \
239237
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
240238
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
241-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
242239
-DPYTHON_EXECUTABLE=python3 \
243240
-Bcmake-out-aot-lib \
244241
"${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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ 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"
5856

5957
local example_dir=examples/portable/custom_ops
6058
local build_dir=cmake-out/${example_dir}
6159
rm -rf ${build_dir}
6260
retry cmake \
6361
-DREGISTER_EXAMPLE_CUSTOM_OP=2 \
64-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
6562
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
6663
-B${build_dir} \
6764
${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}

0 commit comments

Comments
 (0)