-
Notifications
You must be signed in to change notification settings - Fork 737
Add warning for deprecated to_edge() flow with CoreML #15963
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
Lokesh9106
wants to merge
4
commits into
pytorch:main
Choose a base branch
from
Lokesh9106:Lokesh9106-patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d99c31b
Add warning for deprecated to_edge() flow with CoreML
Lokesh9106 3a58575
Add call stack inspection to show warning only for deprecated to_edge…
Lokesh9106 f54dc1a
Add unit tests for deprecation warning
Lokesh9106 4f121fd
Merge branch 'main' into Lokesh9106-patch-1
metascroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| import copy | ||
| import sys | ||
| import unittest | ||
| import io | ||
| import logging | ||
|
|
||
| import coremltools as ct | ||
|
|
||
|
|
@@ -16,6 +18,7 @@ | |
| from executorch.backends.apple.coreml.compiler import CoreMLBackend | ||
| from executorch.backends.apple.coreml.partition import CoreMLPartitioner | ||
| from executorch.exir.backend.utils import format_delegated_graph | ||
| from executorch.exir import to_edge, to_edge_transform_and_lower | ||
|
|
||
|
|
||
| @torch.library.custom_op("unsupported::linear", mutates_args=()) | ||
|
|
@@ -346,3 +349,78 @@ def forward(self, x): | |
| test_runner.test_lower_full_graph() | ||
| # test_runner.test_symint_arg() | ||
| test_runner.test_take_over_constant_data_false() | ||
|
|
||
| def test_deprecation_warning_for_to_backend_workflow(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't these be methods inside TestCoreMLPartitioner? Then in the main section you can add test_runner.test_deprecation_warning_for_to_backend_workflow() and test_runner.test_no_warning_for_to_edge_transform_and_lower_workflow() |
||
| """ | ||
| Test that the deprecated to_edge + to_backend workflow shows a deprecation | ||
| warning. | ||
| """ | ||
| class SimpleModel(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.linear = torch.nn.Linear(10, 5) | ||
|
|
||
| def forward(self, x): | ||
| return self.linear(x) | ||
|
|
||
| model = SimpleModel() | ||
| x = torch.randn(1, 10) | ||
|
|
||
| exported_model = torch.export.export(model, (x,)) | ||
|
|
||
| # Capture log output to check for deprecation warning | ||
| log_capture_string = io.StringIO() | ||
| ch = logging.StreamHandler(log_capture_string) | ||
| ch.setLevel(logging.WARNING) | ||
|
|
||
| logger = logging.getLogger( | ||
| "executorch.backends.apple.coreml.partition.coreml_partitioner" | ||
| ) | ||
| logger.addHandler(ch) | ||
| logger.setLevel(logging.WARNING) | ||
|
|
||
| edge = to_edge(exported_model) | ||
| partitioner = CoreMLPartitioner() | ||
|
|
||
| edge.to_backend(partitioner) | ||
|
|
||
| log_contents = log_capture_string.getvalue() | ||
| self.assertIn("DEPRECATION WARNING", log_contents) | ||
| self.assertIn("to_edge() + to_backend()", log_contents) | ||
| self.assertIn("to_edge_transform_and_lower()", log_contents) | ||
|
|
||
| def test_no_warning_for_to_edge_transform_and_lower_workflow(self): | ||
| """ | ||
| Test that the recommended to_edge_transform_and_lower workflow does NOT | ||
| show a deprecation warning. | ||
| """ | ||
| class SimpleModel(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.linear = torch.nn.Linear(10, 5) | ||
|
|
||
| def forward(self, x): | ||
| return self.linear(x) | ||
|
|
||
| model = SimpleModel() | ||
| x = torch.randn(1, 10) | ||
|
|
||
| exported_model = torch.export.export(model, (x,)) | ||
|
|
||
| # Capture log output to check for deprecation warning | ||
| log_capture_string = io.StringIO() | ||
| ch = logging.StreamHandler(log_capture_string) | ||
| ch.setLevel(logging.WARNING) | ||
|
|
||
| logger = logging.getLogger( | ||
| "executorch.backends.apple.coreml.partition.coreml_partitioner" | ||
| ) | ||
| logger.addHandler(ch) | ||
| logger.setLevel(logging.WARNING) | ||
|
|
||
| partitioner = CoreMLPartitioner() | ||
|
|
||
| to_edge_transform_and_lower(exported_model, partitioner=[partitioner]) | ||
|
|
||
| log_contents = log_capture_string.getvalue() | ||
| self.assertNotIn("DEPRECATION WARNING", log_contents) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the indentation here is off. As written, this is defined inside init