Skip to content

Build custom ops in pybinding #3263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,6 @@ if(EXECUTORCH_BUILD_PYBIND)
list(APPEND _dep_libs xnnpack_backend XNNPACK)
endif()

if(EXECUTORCH_BUILD_CUSTOM)
list(APPEND _dep_libs custom_ops)
endif()

if(EXECUTORCH_BUILD_QUANTIZED)
target_link_options_shared_lib(quantized_ops_lib)
list(APPEND _dep_libs quantized_kernels quantized_ops_lib)
Expand All @@ -571,6 +567,13 @@ if(EXECUTORCH_BUILD_PYBIND)
if(EXECUTORCH_BUILD_CUSTOM_OPS_AOT AND NOT APPLE)
list(APPEND _dep_libs custom_ops_aot_lib)
endif()
# TODO(laryliu): Fix linux duplicate registation problem. In GH CI worker
# libcustom_ops.a doesn't dedup with the one indirectly linked from
# libcustom_ops_aot_lib.a
if(EXECUTORCH_BUILD_CUSTOM AND APPLE)
target_link_options_shared_lib(custom_ops)
list(APPEND _dep_libs custom_ops)
endif()
# compile options for pybind

set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
Expand Down
1 change: 1 addition & 0 deletions examples/models/llama2/custom_ops/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ runtime.python_test(
],
preload_deps = [
":custom_ops_aot_lib",
":custom_ops_aot_py",
],
deps = [
"//caffe2:torch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import torch
import torch.nn.functional as F

from .sdpa_with_kv_cache import custom_ops_lib # noqa


class SDPATest(unittest.TestCase):

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def run(self):

if ShouldBuild.llama_custom_ops:
cmake_args += [
"-DEXECUTORCH_BUILD_CUSTOM=ON", # add llama sdpa ops to pybindings.
"-DEXECUTORCH_BUILD_CUSTOM_OPS_AOT=ON",
]
build_args += ["--target", "custom_ops_aot_lib"]
Expand Down