Skip to content

[Backend Tester] Add portable test flow #13250

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

Open
wants to merge 2 commits into
base: gh/GregoryComer/112/head
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions backends/test/harness/stages/to_edge_transform_and_lower.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
class ToEdgeTransformAndLower(Stage):
def __init__(
self,
default_partitioner_cls: Type,
default_partitioner_cls: Type | None = None,
partitioners: Optional[List[Partitioner]] = None,
edge_compile_config: Optional[EdgeCompileConfig] = None,
):
self.partitioners = partitioners or [default_partitioner_cls()]
self.partitioners = (
partitioners or [default_partitioner_cls()]
if default_partitioner_cls is not None
else []
)
self.edge_compile_conf = edge_compile_config or EdgeCompileConfig()
self.edge_dialect_program = None

Expand Down
4 changes: 2 additions & 2 deletions backends/test/harness/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def __init__(
self,
module: torch.nn.Module,
example_inputs: Tuple[torch.Tensor],
stage_classes: Dict[StageType, Callable],
stage_classes: Dict[StageType, Callable] | None = None,
dynamic_shapes: Optional[Tuple[Any]] = None,
):
module.eval()

self.stage_classes = stage_classes
self.stage_classes = stage_classes or Tester.default_stage_classes()
self.original_module = module
self.example_inputs = example_inputs
self.dynamic_shapes = dynamic_shapes
Expand Down
11 changes: 10 additions & 1 deletion backends/test/suite/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,25 @@ class TestFlow:
tester_factory: Callable[..., Tester]
""" A factory function that returns a Tester instance for this lowering flow. """

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

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

is_delegated: bool = True
""" Indicates whether the flow is expected to generate CALL_DELEGATE nodes. """


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

from executorch.backends.test.suite.flows.portable import PORTABLE_TEST_FLOW

flows += [
PORTABLE_TEST_FLOW,
]

try:
from executorch.backends.test.suite.flows.xnnpack import (
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
Expand Down
19 changes: 19 additions & 0 deletions backends/test/suite/flows/portable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logging

from executorch.backends.test.harness import Tester
from executorch.backends.test.suite.flow import TestFlow

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


def _create_portable_flow() -> TestFlow:
return TestFlow(
"portable",
backend="portable",
tester_factory=Tester,
is_delegated=False,
)


PORTABLE_TEST_FLOW = _create_portable_flow()
4 changes: 2 additions & 2 deletions backends/test/suite/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def build_result(
if n.op == "call_function"
)

# Only run the runtime portion if something was delegated.
if is_delegated:
# Only run the runtime portion if something was delegated (or the flow doesn't delegate).
if is_delegated or not flow.is_delegated:
try:
tester.to_executorch().serialize()
extra_stats["pte_size_bytes"] = len(tester.get_artifact())
Expand Down
Loading