Skip to content

Commit 91121e6

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Build custom ops in pybinding (#3263)
Summary: Right now we are not building it and it is causing missing ops in torchchat. This PR adds it into pybinding. Pull Request resolved: #3263 Reviewed By: lucylq Differential Revision: D56500693 Pulled By: larryliu0820
1 parent 79b79cb commit 91121e6

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,6 @@ if(EXECUTORCH_BUILD_PYBIND)
558558
list(APPEND _dep_libs xnnpack_backend XNNPACK)
559559
endif()
560560

561-
if(EXECUTORCH_BUILD_CUSTOM)
562-
list(APPEND _dep_libs custom_ops)
563-
endif()
564-
565561
if(EXECUTORCH_BUILD_QUANTIZED)
566562
target_link_options_shared_lib(quantized_ops_lib)
567563
list(APPEND _dep_libs quantized_kernels quantized_ops_lib)
@@ -571,6 +567,13 @@ if(EXECUTORCH_BUILD_PYBIND)
571567
if(EXECUTORCH_BUILD_CUSTOM_OPS_AOT AND NOT APPLE)
572568
list(APPEND _dep_libs custom_ops_aot_lib)
573569
endif()
570+
# TODO(laryliu): Fix linux duplicate registation problem. In GH CI worker
571+
# libcustom_ops.a doesn't dedup with the one indirectly linked from
572+
# libcustom_ops_aot_lib.a
573+
if(EXECUTORCH_BUILD_CUSTOM AND APPLE)
574+
target_link_options_shared_lib(custom_ops)
575+
list(APPEND _dep_libs custom_ops)
576+
endif()
574577
# compile options for pybind
575578

576579
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti

examples/models/llama2/custom_ops/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ runtime.python_test(
1515
],
1616
preload_deps = [
1717
":custom_ops_aot_lib",
18+
":custom_ops_aot_py",
1819
],
1920
deps = [
2021
"//caffe2:torch",

examples/models/llama2/custom_ops/test_sdpa_with_kv_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import torch
1010
import torch.nn.functional as F
1111

12+
from .sdpa_with_kv_cache import custom_ops_lib # noqa
13+
1214

1315
class SDPATest(unittest.TestCase):
1416

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ def run(self):
389389

390390
if ShouldBuild.llama_custom_ops:
391391
cmake_args += [
392+
"-DEXECUTORCH_BUILD_CUSTOM=ON", # add llama sdpa ops to pybindings.
392393
"-DEXECUTORCH_BUILD_CUSTOM_OPS_AOT=ON",
393394
]
394395
build_args += ["--target", "custom_ops_aot_lib"]

0 commit comments

Comments
 (0)