-
Notifications
You must be signed in to change notification settings - Fork 827
Qualcomm arange #16833
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
JacobSzwejbka
wants to merge
2
commits into
main
Choose a base branch
from
qualcomm-arange
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.
Open
Qualcomm arange #16833
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |||||
| InsertReshapeForReduceOps, | ||||||
| RemoveRedundancy, | ||||||
| ) | ||||||
|
|
||||||
| from executorch.exir import to_edge | ||||||
| from executorch.exir.dialects._ops import ops as exir_ops | ||||||
|
|
||||||
|
|
@@ -149,6 +148,91 @@ def test_mha_to_sha(self): | |||||
| f"Output {i} mismatch: got {out}, expected {ref}", | ||||||
| ) | ||||||
|
|
||||||
| def test_arange_dtype_from_kwargs(self): | ||||||
|
Collaborator
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. Could you reuse original unit test for arange op?
|
||||||
| """Test that op_arange builder respects dtype from node kwargs.""" | ||||||
| from collections import defaultdict | ||||||
|
|
||||||
| import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager | ||||||
| from executorch.backends.qualcomm._passes.qnn_pass_manager import QnnPassManager | ||||||
| from executorch.backends.qualcomm.builders.node_visitor_manager import ( | ||||||
| get_node_visitors, | ||||||
| ) | ||||||
| from executorch.backends.qualcomm.utils.utils import capture_program | ||||||
|
|
||||||
| class ArangeWithDtype(torch.nn.Module): | ||||||
| def __init__(self, dtype): | ||||||
| super().__init__() | ||||||
| self.dtype = dtype | ||||||
|
|
||||||
| def forward(self, x): | ||||||
| return torch.arange(0, 10, 1, dtype=self.dtype) + x | ||||||
|
|
||||||
| # Map torch dtypes to expected QNN data types | ||||||
| dtype_to_qnn = { | ||||||
| torch.float32: PyQnnManager.Qnn_DataType_t.QNN_DATATYPE_FLOAT_32, | ||||||
| torch.int64: PyQnnManager.Qnn_DataType_t.QNN_DATATYPE_INT_64, | ||||||
| torch.int32: PyQnnManager.Qnn_DataType_t.QNN_DATATYPE_INT_32, | ||||||
| } | ||||||
|
|
||||||
| test_cases = [ | ||||||
| (torch.float32, dtype_to_qnn[torch.float32]), | ||||||
| (torch.int64, dtype_to_qnn[torch.int64]), | ||||||
| (torch.int32, dtype_to_qnn[torch.int32]), | ||||||
| (None, dtype_to_qnn[torch.int64]), # None uses torch default (int64) | ||||||
| ] | ||||||
|
|
||||||
| for input_dtype, expected_qnn_dtype in test_cases: | ||||||
| with self.subTest(input_dtype=input_dtype): | ||||||
| mod = ArangeWithDtype(input_dtype) | ||||||
| # Use appropriate input tensor dtype | ||||||
| if input_dtype == torch.float32: | ||||||
| x = torch.zeros(10, dtype=torch.float32) | ||||||
| else: | ||||||
| x = torch.zeros(10, dtype=torch.int64) | ||||||
|
|
||||||
| sample_input = (x,) | ||||||
| delegated_program = capture_program(mod, sample_input) | ||||||
|
|
||||||
| # Transform graph through QNN pass manager | ||||||
| graph_module = QnnPassManager().transform_for_preprocess_pipeline( | ||||||
| delegated_program.exported_program | ||||||
| ) | ||||||
|
|
||||||
| # Get node visitors (builders) | ||||||
| nodes_to_wrappers = defaultdict(dict) | ||||||
| node_visitors = get_node_visitors( | ||||||
| delegated_program.exported_program, enable_tensor_dump=False | ||||||
| ) | ||||||
|
|
||||||
| # Find and process the arange node through the builder | ||||||
| for node in graph_module.graph.nodes: | ||||||
| if node.op == "call_function" and "arange" in node.target.__name__: | ||||||
| # Invoke the Arange builder's define_node | ||||||
| node_visitors[node.target.__name__].define_node( | ||||||
| node, nodes_to_wrappers | ||||||
| ) | ||||||
|
|
||||||
| # Check that a tensor wrapper was created | ||||||
| self.assertIn( | ||||||
| node.name, | ||||||
| nodes_to_wrappers, | ||||||
| f"No tensor wrapper created for arange node", | ||||||
| ) | ||||||
|
|
||||||
| # Get the tensor wrapper and verify its dtype | ||||||
| tensor_wrapper = nodes_to_wrappers[node.name][0] | ||||||
| actual_dtype = tensor_wrapper.GetDataType() | ||||||
|
|
||||||
| self.assertEqual( | ||||||
| actual_dtype, | ||||||
| expected_qnn_dtype, | ||||||
| f"QNN dtype mismatch for input_dtype={input_dtype}: " | ||||||
| f"got {actual_dtype}, expected {expected_qnn_dtype}", | ||||||
| ) | ||||||
| break | ||||||
| else: | ||||||
| self.fail("No arange node found in graph") | ||||||
|
|
||||||
|
|
||||||
| if __name__ == "__main__": | ||||||
| unittest.main() | ||||||
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.
How about use
node.meta["val"].dtype? I think it will not be None.