Skip to content

remove exir.capture from example delegate test #3101

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
1 change: 0 additions & 1 deletion backends/example/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ python_unittest(
"//caffe2:torch",
"//executorch/exir:delegate",
"//executorch/exir:lib",
"//executorch/exir/backend:backend_api",
"//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
"//pytorch/vision:torchvision",
],
Expand Down
34 changes: 17 additions & 17 deletions backends/example/test_example_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from executorch import exir
from executorch.backends.example.example_partitioner import ExamplePartitioner
from executorch.backends.example.example_quantizer import ExampleQuantizer
from executorch.exir.backend.backend_api import to_backend
from executorch.exir import to_edge

from executorch.exir.backend.canonical_partitioners.duplicate_dequant_node_pass import (
DuplicateDequantNodePass,
)
from executorch.exir.delegate import executorch_call_delegate

from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
from torch.export import export

# @manual=//pytorch/vision:torchvision
from torchvision.models.quantization import mobilenet_v2


Expand All @@ -40,7 +40,6 @@ def get_example_inputs():

model = Conv2dModule()
example_inputs = Conv2dModule.get_example_inputs()
CAPTURE_CONFIG = exir.CaptureConfig(enable_aot=True)
EDGE_COMPILE_CONFIG = exir.EdgeCompileConfig(
_check_ir_validity=False,
)
Expand All @@ -59,24 +58,23 @@ def get_example_inputs():
m = convert_pt2e(m)

quantized_gm = m
exported_program = exir.capture(
quantized_gm, copy.deepcopy(example_inputs), CAPTURE_CONFIG
).to_edge(EDGE_COMPILE_CONFIG)
exported_program = to_edge(
export(quantized_gm, copy.deepcopy(example_inputs)),
compile_config=EDGE_COMPILE_CONFIG,
)

lowered_export_program = to_backend(
exported_program.exported_program,
lowered_export_program = exported_program.to_backend(
ExamplePartitioner(),
)

print("After lowering to qnn backend: ")
lowered_export_program.graph.print_tabular()
lowered_export_program.exported_program().graph.print_tabular()

def test_delegate_mobilenet_v2(self):
model = mobilenet_v2(num_classes=3)
model.eval()
example_inputs = (torch.rand(1, 3, 320, 240),)

CAPTURE_CONFIG = exir.CaptureConfig(enable_aot=True)
EDGE_COMPILE_CONFIG = exir.EdgeCompileConfig(
_check_ir_validity=False,
)
Expand All @@ -91,20 +89,22 @@ def test_delegate_mobilenet_v2(self):
m = convert_pt2e(m)

quantized_gm = m
exported_program = exir.capture(
quantized_gm, copy.deepcopy(example_inputs), CAPTURE_CONFIG
).to_edge(EDGE_COMPILE_CONFIG)
exported_program = to_edge(
export(quantized_gm, copy.deepcopy(example_inputs)),
compile_config=EDGE_COMPILE_CONFIG,
)

lowered_export_program = to_backend(
exported_program.transform(DuplicateDequantNodePass()).exported_program,
lowered_export_program = exported_program.transform(
[DuplicateDequantNodePass()]
).to_backend(
ExamplePartitioner(),
)

lowered_export_program.graph.print_tabular()
lowered_export_program.exported_program().graph.print_tabular()

call_deleage_node = [
node
for node in lowered_export_program.graph.nodes
for node in lowered_export_program.exported_program().graph.nodes
if node.target == executorch_call_delegate
]
self.assertEqual(len(call_deleage_node), 1)