Skip to content

Fix export config in tests #34

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: 1 addition & 0 deletions examples/export/test/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ python_unittest(
"//executorch/examples/export:utils",
"//executorch/examples/models:models",
"//executorch/exir:lib",
"//executorch/extension/pybindings:portable", # @manual
],
)
15 changes: 11 additions & 4 deletions examples/export/test/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@

import torch

from executorch.examples.export.utils import _EDGE_COMPILE_CONFIG
from executorch.examples.export.utils import _CAPTURE_CONFIG, _EDGE_COMPILE_CONFIG
from executorch.examples.models import MODEL_NAME_TO_MODEL

# pyre-ignore[21]: Could not find module `executorch.extension.pybindings.portable`.
from executorch.extension.pybindings.portable import ( # @manual
_load_for_executorch_from_buffer,
)


class ExportTest(unittest.TestCase):
def _assert_eager_lowered_same_result(
self, eager_model: torch.nn.Module, example_inputs
):
import executorch.exir as exir

capture_config = exir.CaptureConfig(enable_dynamic_shape=False)
edge_model = exir.capture(eager_model, example_inputs, capture_config).to_edge(
edge_model = exir.capture(eager_model, example_inputs, _CAPTURE_CONFIG).to_edge(
_EDGE_COMPILE_CONFIG
)

executorch_model = edge_model.to_executorch()
# pyre-ignore
pte_model = _load_for_executorch_from_buffer(executorch_model.buffer)

with torch.no_grad():
eager_output = eager_model(*example_inputs)
with torch.no_grad():
executorch_output = executorch_model.graph_module(*example_inputs)
executorch_output = pte_model.forward(example_inputs)
self.assertTrue(
torch.allclose(eager_output, executorch_output[0], rtol=1e-5, atol=1e-5)
)
Expand Down
2 changes: 1 addition & 1 deletion examples/export/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Reason is that there memory allocation ops with symbolic shape nodes.
# and when evaulating shape, it doesnt seem that we presenting them with shape env
# that contain those variables.
_CAPTURE_CONFIG = exir.CaptureConfig(enable_aot=True, _unlift=False)
_CAPTURE_CONFIG = exir.CaptureConfig(enable_aot=True)
_EDGE_COMPILE_CONFIG = exir.EdgeCompileConfig(
_check_ir_validity=False,
)
4 changes: 2 additions & 2 deletions exir/capture/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
class CaptureConfig:
pt2_mode: bool = True
enable_functionalization: bool = True
enable_dynamic_shape: bool = False
enable_aot: bool = False
enable_dynamic_shape: bool = False # This flag does nothing if enable_aot is True
enable_aot: bool = False # When it's true it implies automatic dynamic shapes via default dynamo config
_dynamo_config: "ExirDynamoConfig" = field(default_factory=ExirDynamoConfig)
_unlift: bool = False
_use_old_decomp_table: bool = False
Expand Down