Skip to content

Commit 4a5e147

Browse files
larryliu0820facebook-github-bot
authored andcommitted
avoid torch.ops.load_library() calls
Summary: Due to different buck root, code such as ``` torch.ops.load_library("//executorch/kernels/quantized:custom_ops_generated_lib") ``` is very hard to work both internally and in oss. Here I'm trying to leverage the `preload_deps` attribute in python_binary and python_unittest, and remove `torch.ops.load_library` calls. This should unblock these tests/binaries to be running in OSS. Reviewed By: cccclai Differential Revision: D48018133 fbshipit-source-id: 06dcf01a611e5b8877a71ebded5f9753db22a55f
1 parent 15c9724 commit 4a5e147

File tree

7 files changed

+26
-24
lines changed

7 files changed

+26
-24
lines changed

backends/test/TARGETS

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ python_unittest(
8686
srcs = [
8787
"test_backends.py",
8888
],
89+
preload_deps = [
90+
"//executorch/kernels/portable:custom_ops_generated_lib",
91+
"//executorch/kernels/quantized:custom_ops_generated_lib",
92+
],
8993
deps = [
9094
":backend_with_compiler_demo",
9195
":hta_partitioner_demo",
@@ -105,8 +109,6 @@ python_unittest(
105109
"//executorch/exir/dialects:lib",
106110
"//executorch/extension/pybindings:portable", # @manual
107111
"//executorch/extension/pytree:pylib",
108-
"//executorch/kernels/portable:custom_ops_generated_lib",
109-
"//executorch/kernels/quantized:custom_ops_generated_lib",
110112
"//executorch/runtime/executor/test:test_backend_compiler_lib",
111113
],
112114
)
@@ -116,6 +118,10 @@ python_unittest(
116118
srcs = [
117119
"test_backends_lifted.py",
118120
],
121+
preload_deps = [
122+
"//executorch/kernels/portable:custom_ops_generated_lib",
123+
"//executorch/kernels/quantized:custom_ops_generated_lib",
124+
],
119125
deps = [
120126
":backend_with_compiler_demo",
121127
":hta_partitioner_demo",
@@ -135,8 +141,6 @@ python_unittest(
135141
"//executorch/exir/dialects:lib",
136142
"//executorch/extension/pybindings:portable", # @manual
137143
"//executorch/extension/pytree:pylib",
138-
"//executorch/kernels/portable:custom_ops_generated_lib",
139-
"//executorch/kernels/quantized:custom_ops_generated_lib",
140144
"//executorch/runtime/executor/test:test_backend_compiler_lib",
141145
],
142146
)
@@ -163,6 +167,10 @@ python_unittest(
163167
srcs = [
164168
"test_backends_nested.py",
165169
],
170+
preload_deps = [
171+
"//executorch/kernels/portable:custom_ops_generated_lib",
172+
"//executorch/kernels/quantized:custom_ops_generated_lib",
173+
],
166174
deps = [
167175
":op_partitioner_demo",
168176
"//caffe2:torch",
@@ -176,8 +184,6 @@ python_unittest(
176184
"//executorch/exir:graph_module",
177185
"//executorch/exir:lib",
178186
"//executorch/exir:lowered_backend_module",
179-
"//executorch/kernels/portable:custom_ops_generated_lib",
180-
"//executorch/kernels/quantized:custom_ops_generated_lib",
181187
"//executorch/runtime/executor/test:test_backend_compiler_lib",
182188
],
183189
)

backends/test/test_backends.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@
6262
from torch.testing import FileCheck
6363

6464

65-
torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
66-
67-
6865
def vary_segments(test_method):
6966
"""A decorator that calls the test method with `extract_segments` set to
7067
True and False.

backends/test/test_backends_lifted.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
from torch.testing import FileCheck
6666

6767

68-
torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
69-
70-
7168
def get_testing_capture_config():
7269
return exir.CaptureConfig(pt2_mode=True, enable_aot=True, _unlift=False)
7370

backends/vulkan/test/TARGETS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ python_unittest(
88
preload_deps = [
99
"fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_fbcode",
1010
"//executorch/backends/vulkan:vulkan_backend_lib",
11+
"//executorch/kernels/portable:custom_ops_generated_lib",
1112
],
1213
deps = [
1314
"//caffe2:torch",
@@ -17,7 +18,6 @@ python_unittest(
1718
"//executorch/exir/serialize:lib",
1819
"//executorch/extension/pybindings:portable", # @manual
1920
"//executorch/extension/pytree:pylib",
20-
"//executorch/kernels/portable:custom_ops_generated_lib",
2121
"//executorch/runtime/executor/test:test_backend_compiler_lib",
2222
],
2323
)

exir/tests/TARGETS

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ python_unittest(
157157
srcs = [
158158
"test_op_convert.py",
159159
],
160-
deps = [
160+
preload_deps = [
161+
"//executorch/kernels/portable:custom_ops_generated_lib",
161162
":test_lib", # @manual
163+
],
164+
deps = [
162165
"//caffe2:torch",
163166
"//executorch/exir/operator:convert",
164-
"//executorch/kernels/portable:custom_ops_generated_lib",
165167
],
166168
)
167169

@@ -170,6 +172,9 @@ python_unittest(
170172
srcs = [
171173
"test_memory_planning.py",
172174
],
175+
preload_deps = [
176+
"//executorch/kernels/portable:custom_ops_generated_lib",
177+
],
173178
deps = [
174179
":asr_joiner",
175180
"//caffe2:torch",
@@ -181,7 +186,6 @@ python_unittest(
181186
"//executorch/exir:print_program",
182187
"//executorch/exir:schema",
183188
"//executorch/exir/passes:lib",
184-
"//executorch/kernels/portable:custom_ops_generated_lib",
185189
],
186190
)
187191

@@ -316,13 +320,15 @@ python_unittest(
316320
srcs = [
317321
"test_quant_fusion_pass.py",
318322
],
323+
preload_deps = [
324+
"//executorch/kernels/quantized:custom_ops_generated_lib",
325+
],
319326
deps = [
320327
":lib",
321328
"//caffe2:torch",
322329
"//executorch/exir:lib",
323330
"//executorch/exir:tracer",
324331
"//executorch/exir/passes:quant_fusion_pass",
325-
"//executorch/kernels/quantized:custom_ops_generated_lib",
326332
],
327333
)
328334

@@ -331,13 +337,15 @@ python_unittest(
331337
srcs = [
332338
"test_quantization.py",
333339
],
340+
preload_deps = [
341+
"//executorch/kernels/quantized:custom_ops_generated_lib",
342+
],
334343
deps = [
335344
"//caffe2:torch",
336345
"//executorch/exir:lib",
337346
"//executorch/exir:tracer",
338347
"//executorch/exir/passes:quant_fusion_pass",
339348
"//executorch/exir/passes:spec_prop_pass",
340-
"//executorch/kernels/quantized:custom_ops_generated_lib",
341349
"//pytorch/vision:torchvision",
342350
],
343351
)

exir/tests/test_op_convert.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
from executorch.exir.operator.convert import to_out_variant
1414
from torch._ops import OpOverload
1515

16-
torch.ops.load_library("//executorch/exir/tests:test_lib")
17-
torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
18-
1916

2017
class TestToOutVariant(unittest.TestCase):
2118
def test_already_out_var(self) -> None:

exir/tests/test_quant_fusion_pass.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131

3232
from torch.testing import FileCheck
3333

34-
# load executorch out variant ops
35-
torch.ops.load_library("//executorch/kernels/quantized:custom_ops_generated_lib")
36-
3734

3835
class TestQuantFusionPass(unittest.TestCase):
3936
@classmethod

0 commit comments

Comments
 (0)