Repository navigation
Samsung Exynos AI LiteCore - Lower more ops and add tests to support LLM models #22829
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
053d287
feat: add axis info for rms norm
Jiseong-oh d7b14f3
feat: add test cases for 6 ops
Jiseong-oh 9be04c1
Create MobileBERT export inputs directly on the target device
Jiseong-oh a42962e
Support aten.pixel_unshuffle
Jiseong-oh 80239f1
Fixed issues based on the code review
Jiseong-oh ddb7cbe
Merge branch 'main' into support_ops_llm
Jiseong-oh 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Copyright (c) 2025 Samsung Electronics Co. LTD | ||
| # All rights reserved | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
| from typing import cast, Dict | ||
|
|
||
| import torch | ||
| from executorch.backends.samsung.builders.node_visitor import ( | ||
| NodeVisitor, | ||
| register_node_visitor, | ||
| ) | ||
| from executorch.backends.samsung.serialization.enn_graph_schema import EnnGraph | ||
| from executorch.backends.transforms import get_shape | ||
|
|
||
|
|
||
| @register_node_visitor | ||
| class PixelUnshuffleVisitor(NodeVisitor): | ||
| target = "aten.pixel_unshuffle.default" | ||
|
|
||
| def __init__(self, *args) -> None: | ||
| super().__init__(*args) | ||
|
|
||
| def define_node( | ||
| self, | ||
| node: torch.fx.Node, | ||
| enn_graph: EnnGraph, | ||
| vals_to_ids: Dict[torch.Tensor, int], | ||
| ) -> bool: | ||
| if len(get_shape(node.args[0])) != 4: | ||
| return False | ||
|
|
||
| input_id = self.define_tensor(node.args[0], enn_graph, vals_to_ids) | ||
|
|
||
| downscale_factor = cast(int, node.args[1]) | ||
| params = {"block_size": downscale_factor, "mode": "CRD"} | ||
|
|
||
| output_id = self.define_tensor(node, enn_graph, vals_to_ids) | ||
|
|
||
| enn_graph.define_op( | ||
| node.name, "SPACE_TO_DEPTH", [input_id], [output_id], params | ||
| ) | ||
|
|
||
| return True | ||
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,47 @@ | ||
| # Copyright (c) Samsung Electronics Co. LTD | ||
| # All rights reserved | ||
| # | ||
| # Licensed under the BSD License (the "License"); you may not use this file | ||
| # except in compliance with the License. See the license file in the root | ||
| # directory of this source tree for more details. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.samsung.serialization.compile_options import ( | ||
| gen_samsung_backend_compile_spec, | ||
| ) | ||
| from executorch.backends.samsung.test.tester import SamsungTester | ||
| from executorch.backends.samsung.test.utils.utils import TestConfig | ||
|
|
||
|
|
||
| class HardSigmoid(torch.nn.Module): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.module = torch.nn.Hardsigmoid() | ||
|
|
||
| def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
| return self.module(x) | ||
|
|
||
|
|
||
| class TestHardSigmoid(unittest.TestCase): | ||
| def _test(self, module: torch.nn.Module, inputs): | ||
| tester = SamsungTester( | ||
| module, | ||
| inputs, | ||
| [gen_samsung_backend_compile_spec(TestConfig.chipset)], | ||
| ) | ||
| ( | ||
| tester.export() | ||
| .check_count({"torch.ops.aten.hardsigmoid.default": 1}) | ||
| .to_edge_transform_and_lower() | ||
| .check_not(["executorch_exir_dialects_edge__ops_aten_hardsigmoid_default"]) | ||
| .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) | ||
| .to_executorch() | ||
| .run_method_and_compare_outputs(inputs=inputs) | ||
| ) | ||
|
|
||
| def test_fp32_hard_sigmoid(self): | ||
| inputs = (torch.randn(1, 16, 32, 32),) | ||
| self._test(HardSigmoid(), inputs) |
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,47 @@ | ||
| # Copyright (c) Samsung Electronics Co. LTD | ||
| # All rights reserved | ||
| # | ||
| # Licensed under the BSD License (the "License"); you may not use this file | ||
| # except in compliance with the License. See the license file in the root | ||
| # directory of this source tree for more details. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.samsung.serialization.compile_options import ( | ||
| gen_samsung_backend_compile_spec, | ||
| ) | ||
| from executorch.backends.samsung.test.tester import SamsungTester | ||
| from executorch.backends.samsung.test.utils.utils import TestConfig | ||
|
|
||
|
|
||
| class HardSwish(torch.nn.Module): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.module = torch.nn.Hardswish() | ||
|
|
||
| def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
| return self.module(x) | ||
|
|
||
|
|
||
| class TestHardSwish(unittest.TestCase): | ||
| def _test(self, module: torch.nn.Module, inputs): | ||
| tester = SamsungTester( | ||
| module, | ||
| inputs, | ||
| [gen_samsung_backend_compile_spec(TestConfig.chipset)], | ||
| ) | ||
| ( | ||
| tester.export() | ||
| .check_count({"torch.ops.aten.hardswish.default": 1}) | ||
| .to_edge_transform_and_lower() | ||
| .check_not(["executorch_exir_dialects_edge__ops_aten_hardswish_default"]) | ||
| .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) | ||
| .to_executorch() | ||
| .run_method_and_compare_outputs(inputs=inputs, atol=0.002) | ||
| ) | ||
|
|
||
| def test_fp32_hard_swish(self): | ||
| inputs = (torch.randn(1, 16, 32, 32),) | ||
| self._test(HardSwish(), inputs) |
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,47 @@ | ||
| # Copyright (c) Samsung Electronics Co. LTD | ||
| # All rights reserved | ||
| # | ||
| # Licensed under the BSD License (the "License"); you may not use this file | ||
| # except in compliance with the License. See the license file in the root | ||
| # directory of this source tree for more details. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.samsung.serialization.compile_options import ( | ||
| gen_samsung_backend_compile_spec, | ||
| ) | ||
| from executorch.backends.samsung.test.tester import SamsungTester | ||
| from executorch.backends.samsung.test.utils.utils import TestConfig | ||
|
|
||
|
|
||
| class Hardtanh(torch.nn.Module): | ||
| def __init__(self, min_val, max_val) -> None: | ||
| super().__init__() | ||
| self.module = torch.nn.Hardtanh(min_val=min_val, max_val=max_val) | ||
|
|
||
| def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
| return self.module(x) | ||
|
|
||
|
|
||
| class TestHardtanh(unittest.TestCase): | ||
| def _test(self, module: torch.nn.Module, inputs): | ||
| tester = SamsungTester( | ||
| module, | ||
| inputs, | ||
| [gen_samsung_backend_compile_spec(TestConfig.chipset)], | ||
| ) | ||
| ( | ||
| tester.export() | ||
| .check_count({"torch.ops.aten.hardtanh.default": 1}) | ||
| .to_edge_transform_and_lower() | ||
| .check_not(["executorch_exir_dialects_edge__ops_aten_hardtanh_default"]) | ||
| .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) | ||
| .to_executorch() | ||
| .run_method_and_compare_outputs(inputs=inputs) | ||
| ) | ||
|
|
||
| def test_fp32_hardtanh(self): | ||
| inputs = (torch.randn(1, 3, 16, 16),) | ||
| self._test(Hardtanh(min_val=0, max_val=1), inputs) |
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,47 @@ | ||
| # Copyright (c) Samsung Electronics Co. LTD | ||
| # All rights reserved | ||
| # | ||
| # Licensed under the BSD License (the "License"); you may not use this file | ||
| # except in compliance with the License. See the license file in the root | ||
| # directory of this source tree for more details. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.samsung.serialization.compile_options import ( | ||
| gen_samsung_backend_compile_spec, | ||
| ) | ||
| from executorch.backends.samsung.test.tester import SamsungTester | ||
| from executorch.backends.samsung.test.utils.utils import TestConfig | ||
|
|
||
|
|
||
| class LayerNorm(torch.nn.Module): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.module = torch.nn.LayerNorm(10) | ||
|
|
||
| def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
| return self.module(x) | ||
|
|
||
|
|
||
| class TestLayerNorm(unittest.TestCase): | ||
| def _test(self, module: torch.nn.Module, inputs): | ||
| tester = SamsungTester( | ||
| module, | ||
| inputs, | ||
| [gen_samsung_backend_compile_spec(TestConfig.chipset)], | ||
| ) | ||
| ( | ||
| tester.export() | ||
| .check_count({"torch.ops.aten.layer_norm.default": 1}) | ||
| .to_edge_transform_and_lower() | ||
| .check_not(["executorch_exir_dialects_edge__ops_aten_layer_norm_default"]) | ||
| .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) | ||
| .to_executorch() | ||
| .run_method_and_compare_outputs(inputs=inputs) | ||
| ) | ||
|
|
||
| def test_fp32_layer_norm(self): | ||
| inputs = (torch.randn(1, 32, 10),) | ||
| self._test(LayerNorm(), inputs) |
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,46 @@ | ||
| # Copyright (c) Samsung Electronics Co. LTD | ||
| # All rights reserved | ||
| # | ||
| # Licensed under the BSD License (the "License"); you may not use this file | ||
| # except in compliance with the License. See the license file in the root | ||
| # directory of this source tree for more details. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.samsung.serialization.compile_options import ( | ||
| gen_samsung_backend_compile_spec, | ||
| ) | ||
| from executorch.backends.samsung.test.tester import SamsungTester | ||
| from executorch.backends.samsung.test.utils.utils import TestConfig | ||
|
|
||
|
|
||
| class Maximum(torch.nn.Module): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
|
|
||
| def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: | ||
| return torch.maximum(x, y) | ||
|
|
||
|
|
||
| class TestMaximum(unittest.TestCase): | ||
| def _test(self, module: torch.nn.Module, inputs): | ||
| tester = SamsungTester( | ||
| module, | ||
| inputs, | ||
| [gen_samsung_backend_compile_spec(TestConfig.chipset)], | ||
| ) | ||
| ( | ||
| tester.export() | ||
| .check_count({"torch.ops.aten.maximum.default": 1}) | ||
| .to_edge_transform_and_lower() | ||
| .check_not(["executorch_exir_dialects_edge__ops_aten_maximum_default"]) | ||
| .check_count({"torch.ops.higher_order.executorch_call_delegate": 1}) | ||
| .to_executorch() | ||
| .run_method_and_compare_outputs(inputs=inputs) | ||
| ) | ||
|
|
||
| def test_fp32_maximum(self): | ||
| inputs = (torch.randn(1, 3, 56, 56), torch.randn(1, 3, 56, 56)) | ||
| self._test(Maximum(), inputs) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Could we validate the input rank before reporting this node as supported?
aten.pixel_unshuffleaccepts rank-3 and higher inputs, while ENNSPACE_TO_DEPTHmay only support 4-D tensors. Since the support checker trusts the visitor return value, unsupported ranks could be delegated incorrectly. Please reject unsupported ranks or add tests confirming ENN supports them.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.
Thanks @psiddh it's good point. I updated it.