Skip to content

Commit 19a5994

Browse files
dbortfacebook-github-bot
authored andcommitted
Remove direct calls to serialize_to_flatbuffer
Summary: Users should prefer `to_executorch().buffer`. Reviewed By: JacobSzwejbka Differential Revision: D48366595 fbshipit-source-id: 9db517cd33c0493729be049fec6f9f3a359fd1cb
1 parent 8079496 commit 19a5994

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

backends/vulkan/test/TARGETS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ python_unittest(
1515
"//executorch/backends/vulkan:vulkan_preprocess",
1616
"//executorch/exir:lib",
1717
"//executorch/exir/backend:backend_api",
18-
"//executorch/exir/serialize:lib",
1918
"//executorch/extension/pybindings:portable", # @manual
2019
"//executorch/extension/pytree:pylib",
2120
"//executorch/kernels/portable:custom_ops_generated_lib",

backends/vulkan/test/test_vulkan_delegate.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
# import the vulkan backend implementation
1515
from executorch.backends.vulkan.vulkan_preprocess import VulkanBackend
16-
from executorch.exir.backend.backend_api import to_backend
1716

18-
from executorch.exir.serialize import serialize_to_flatbuffer
17+
from executorch.exir import ExecutorchProgram
18+
from executorch.exir.backend.backend_api import to_backend
1919

2020
ctypes.CDLL("libvulkan.so.1")
2121

@@ -72,24 +72,21 @@ def __init__(self):
7272
def forward(self, *args):
7373
return self.one_module(*args)
7474

75-
program = (
75+
executorch_program: ExecutorchProgram = (
7676
exir.capture(WrappedModule(), sample_inputs, exir.CaptureConfig())
7777
.to_edge()
7878
.to_executorch()
79-
.program
8079
)
8180

8281
# Assert the backend name is vulkan
8382
self.assertEqual(
84-
program.execution_plan[0].delegates[0].id,
83+
executorch_program.program.execution_plan[0].delegates[0].id,
8584
VulkanBackend.__name__,
8685
)
8786

88-
buffer = serialize_to_flatbuffer(program)
89-
9087
# Test the model with executor
91-
# pyre-ignore
92-
executorch_module = _load_for_executorch_from_buffer(buffer)
88+
# pyre-ignore[16]: Module `executorch.extension.pybindings` has no attribute `portable`.
89+
executorch_module = _load_for_executorch_from_buffer(executorch_program.buffer)
9390
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
9491
inputs_flattened, _ = tree_flatten(sample_inputs)
9592

profiler/test/test_profiler_e2e.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313

1414
import torch
1515

16-
# torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
17-
1816
from executorch import exir
19-
from executorch.exir.serialize import serialize_to_flatbuffer
2017

2118
# pyre-ignore: Undefined import [21]: Could not find a module corresponding to import `executorch.extension.pybindings.portable`.
2219
from executorch.extension.pybindings.portable import (
@@ -51,10 +48,16 @@ class TestCustomOps(unittest.TestCase):
5148
def setUpClass(cls) -> None:
5249
model = Module()
5350
inputs = (torch.ones(2, 2, dtype=torch.float),)
54-
program = exir.capture(model, inputs).to_edge().to_executorch().program
55-
cls.flatbuff_without_stacktrace = serialize_to_flatbuffer(program)
51+
52+
# The serialized program file. This must live longer than cls.module,
53+
# because the C++ pybindings will have a pointer to it. But none of the
54+
# tests should need to touch it.
55+
cls.__buffer: bytes = (
56+
exir.capture(model, inputs).to_edge().to_executorch().buffer
57+
)
58+
5659
# pyre-ignore: Undefined attribute [16]: Module `executorch.extension.pybindings` has no attribute `portable`.
57-
cls.module = _load_for_executorch_from_buffer(cls.flatbuff_without_stacktrace)
60+
cls.module = _load_for_executorch_from_buffer(cls.__buffer)
5861

5962
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
6063
cls.inputs_flattened, _ = tree_flatten(inputs)

test/end2end/test_end2end.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
ToOutVarPass,
4646
)
4747
from executorch.exir.print_program import pretty_print, print_program
48-
from executorch.exir.serialize import serialize_to_flatbuffer
4948
from executorch.exir.tensor import make_tensor_value, TensorSpec
5049
from executorch.exir.tests.control_flow_models import (
5150
FTCondBasic,

0 commit comments

Comments
 (0)