Skip to content

Commit ea0d0d1

Browse files
committed
[Backend Tester] Add portable test flow
ghstack-source-id: d8c5133 ghstack-comment-id: 3169541265 Pull-Request: #13250
1 parent cf97d24 commit ea0d0d1

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

backends/test/harness/stages/to_edge_transform_and_lower.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
class ToEdgeTransformAndLower(Stage):
1616
def __init__(
1717
self,
18-
default_partitioner_cls: Type,
18+
default_partitioner_cls: Type | None = None,
1919
partitioners: Optional[List[Partitioner]] = None,
2020
edge_compile_config: Optional[EdgeCompileConfig] = None,
2121
):
22-
self.partitioners = partitioners or [default_partitioner_cls()]
22+
self.partitioners = (
23+
partitioners or [default_partitioner_cls()]
24+
if default_partitioner_cls is not None
25+
else []
26+
)
2327
self.edge_compile_conf = edge_compile_config or EdgeCompileConfig()
2428
self.edge_dialect_program = None
2529

backends/test/harness/tester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def __init__(
3434
self,
3535
module: torch.nn.Module,
3636
example_inputs: Tuple[torch.Tensor],
37-
stage_classes: Dict[StageType, Callable],
37+
stage_classes: Dict[StageType, Callable] | None = None,
3838
dynamic_shapes: Optional[Tuple[Any]] = None,
3939
):
4040
module.eval()
4141

42-
self.stage_classes = stage_classes
42+
self.stage_classes = stage_classes or Tester.default_stage_classes()
4343
self.original_module = module
4444
self.example_inputs = example_inputs
4545
self.dynamic_shapes = dynamic_shapes

backends/test/suite/flow.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,25 @@ class TestFlow:
2626
tester_factory: Callable[..., Tester]
2727
""" A factory function that returns a Tester instance for this lowering flow. """
2828

29-
quantize: bool = field(default=False)
29+
quantize: bool = False
3030
""" Whether to tester should run the quantize stage on the model. """
3131

3232
quantize_stage_factory: Callable[..., Quantize] | None = None
3333
""" A factory function which instantiates a Quantize stage. Can be None to use the tester's default. """
3434

35+
is_delegated: bool = True
36+
""" Indicates whether the flow is expected to generate CALL_DELEGATE nodes. """
37+
3538

3639
def all_flows() -> dict[str, TestFlow]:
3740
flows = []
3841

42+
from executorch.backends.test.suite.flows.portable import PORTABLE_TEST_FLOW
43+
44+
flows += [
45+
PORTABLE_TEST_FLOW,
46+
]
47+
3948
try:
4049
from executorch.backends.test.suite.flows.xnnpack import (
4150
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,

backends/test/suite/flows/portable.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import logging
2+
3+
from executorch.backends.test.harness import Tester
4+
from executorch.backends.test.suite.flow import TestFlow
5+
6+
logger = logging.getLogger(__name__)
7+
logger.setLevel(logging.INFO)
8+
9+
10+
def _create_portable_flow() -> TestFlow:
11+
return TestFlow(
12+
"portable",
13+
backend="portable",
14+
tester_factory=Tester,
15+
is_delegated=False,
16+
)
17+
18+
19+
PORTABLE_TEST_FLOW = _create_portable_flow()

backends/test/suite/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def build_result(
125125
if n.op == "call_function"
126126
)
127127

128-
# Only run the runtime portion if something was delegated.
129-
if is_delegated:
128+
# Only run the runtime portion if something was delegated (or the flow doesn't delegate).
129+
if is_delegated or not flow.is_delegated:
130130
try:
131131
tester.to_executorch().serialize()
132132
extra_stats["pte_size_bytes"] = len(tester.get_artifact())

0 commit comments

Comments
 (0)