Skip to content

Commit aee0795

Browse files
authored
Fix experimental build failure with ExecuTorch enabled (#2526)
After pytorch/executorch#12320 we started to add `--whole-archive` to libraries in `executorch-config.cmake`. This means when we `find_packages(executoch)` and link `${EXECUTORCH_LIBRARIES}`, we started to actually link portable libs: `portable_ops_lib`. This behavior change is breaking because outside of experimental when we build the `llama_runner` library we are linking `optimized_native_cpu_ops_lib` (which contains exactly the same ops but different kernels) as well: https://github.com/pytorch/executorch/blob/main/examples/models/llama/CMakeLists.txt#L95-L101 This results in runtime error: ``` + ./cmake-out/examples/models/llama/llama_main --model_path=model.pte --tokenizer_path=tokenizer.bin '--prompt=Once upon a time,' I tokenizers:regex.cpp:27] Registering override fallback regex E 00:00:00.000453 executorch:operator_registry.cpp:89] Re-registering aten::_cdist_forward.out, from NOT_SUPPORTED I 00:00:00.000494 executorch:operator_registry.cpp:90] key: (null), is_fallback: true F 00:00:00.000497 executorch:operator_registry.cpp:114] In function register_kernels(), assert failed (false): Kernel registration failed with error 18, see error log for details. ``` Like in this job: https://github.com/pytorch/executorch/actions/runs/16207706949/job/45761626062 In order to fix this, we change the logic of linking `${EXECUTORCH_LIBRARIES}` which includes both core and kernel ops lib into only linking `executorch_core`, because the kernel ops lib will be linked outside anyways.
1 parent fe99758 commit aee0795

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

torchao/experimental/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ if (NOT TARGET cpuinfo)
9999
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "Disable mock tests" FORCE)
100100
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "Disable benchmarks" FORCE)
101101
add_compile_options(-Wno-unused-function -Wno-unused-variable)
102+
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
102103
include(FetchContent)
103104
FetchContent_Declare(cpuinfo
104105
GIT_REPOSITORY https://github.com/pytorch/cpuinfo.git
@@ -166,7 +167,6 @@ if(TORCHAO_BUILD_EXECUTORCH_OPS)
166167
target_link_torchao_parallel_backend(torchao_ops_executorch executorch)
167168
target_include_directories(torchao_ops_executorch PRIVATE "${EXECUTORCH_INCLUDE_DIRS}")
168169
target_compile_definitions(torchao_ops_executorch PRIVATE USE_EXECUTORCH=1)
169-
target_link_libraries(torchao_ops_executorch PRIVATE "${EXECUTORCH_LIBRARIES}")
170170
if (TORCHAO_BUILD_CPU_AARCH64)
171171
target_link_libraries(torchao_ops_executorch PRIVATE torchao_kernels_aarch64)
172172
endif()

torchao/experimental/Utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function(target_link_torchao_parallel_backend target_name torchao_parallel_backe
2828
message(STATUS "EXECUTORCH_INCLUDE_DIRS: ${EXECUTORCH_INCLUDE_DIRS}")
2929
message(STATUS "EXECUTORCH_LIBRARIES: ${EXECUTORCH_LIBRARIES}")
3030
target_include_directories(${target_name} PRIVATE "${EXECUTORCH_INCLUDE_DIRS}")
31-
target_link_libraries(${target_name} PRIVATE "${EXECUTORCH_LIBRARIES}")
31+
target_link_libraries(${target_name} PRIVATE executorch_core)
3232
target_compile_definitions(${target_name} PRIVATE TORCHAO_PARALLEL_EXECUTORCH=1)
3333

3434
elseif(TORCHAO_PARALLEL_BACKEND_TOUPPER STREQUAL "OPENMP")

0 commit comments

Comments
 (0)