-
Notifications
You must be signed in to change notification settings - Fork 699
NXP backend: Add infrastructure for context dependant partitioning #14373
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
Merged
MartinPavella
merged 2 commits into
pytorch:main
from
nxp-upstream:upstream/main-nxp/EIEX-528-add-context-dependent-partitioning-conditions
Oct 1, 2025
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Copyright 2025 NXP | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import unittest | ||
|
|
||
| import numpy as np | ||
| import torch | ||
|
|
||
| from executorch.backends.nxp.backend.ir.converter.node_converters.ops_converters import ( | ||
| ViewCopyConverter, | ||
| ) | ||
| from executorch.backends.nxp.tests.executorch_pipeline import to_quantized_edge_program | ||
| from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops | ||
| from executorch.exir.dialects._ops import ops as exir_ops | ||
|
|
||
|
|
||
| class SingleViewCopyModule(torch.nn.Module): | ||
| def __init__(self, new_shape: list[int]): | ||
| super().__init__() | ||
| self.new_shape = new_shape | ||
|
|
||
| def forward(self, x): | ||
| return torch.reshape(x, self.new_shape) | ||
|
|
||
|
|
||
| class TestContextSensitiveDelegation(unittest.TestCase): | ||
| __test__ = False # Prevent interfering with PyTest tests. | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| torch.manual_seed(23) | ||
| np.random.seed(42) | ||
|
|
||
| def test_single_view_copy_partition(self): | ||
| input_shape = (2, 10) | ||
| module = SingleViewCopyModule([1, 20]) | ||
|
|
||
| ep = to_quantized_edge_program(module, input_shape).exported_program() | ||
|
|
||
| # Make sure the `view_copy` was not delegated. | ||
| assert graph_contains_any_of_ops( | ||
| ep.graph, [exir_ops.edge.aten.view_copy.default] | ||
| ) | ||
| assert not any("delegate" in n.name for n in ep.graph.nodes) | ||
|
|
||
| def test_single_view_copy_partition__forced_delegation(self): | ||
| input_shape = (2, 10) | ||
| module = SingleViewCopyModule([1, 20]) | ||
|
|
||
| def _supported_partitioning(*_): | ||
| return True | ||
|
|
||
| # Replace the partition support check function, to accept anything. | ||
| original_supports_partitioning_result = ( | ||
| ViewCopyConverter.supports_partitioning_result | ||
| ) | ||
| ViewCopyConverter.supports_partitioning_result = _supported_partitioning | ||
|
|
||
| with self.assertRaises(RuntimeError) as e: | ||
| to_quantized_edge_program(module, input_shape).exported_program() | ||
| assert ( | ||
| str(e.exception) | ||
| == "Model converted with neutron-converter does not contain a NeutronGraph node." | ||
| ) | ||
|
|
||
| # Return to the original partition support check function. | ||
| ViewCopyConverter.supports_partitioning_result = ( | ||
| original_supports_partitioning_result | ||
| ) |
Oops, something went wrong.
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.
For any practical model the contion is enough, but in theory not right.
Thinking loudly:
So I would say, the correct condition is there must be at least 1 compute operator, that is the partition must not contain only view_copy and clone ops (any number).
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.
Good catch.
I will create a ticket for this, as it is not trivial to determine which nodes will end up being "noops". And it would require another PR to be merged first.