Skip to content

Commit 451de74

Browse files
committed
Apply review comment
- split test into PowScalar and PowTensor - raise RuntimeError when expected nodes aren't found. - fix perf mode on aot_compiler.py. - added -> None to define_node. Signed-off-by: jiseong.oh <jiseong.oh@samsung.com>
1 parent de3bae4 commit 451de74

6 files changed

Lines changed: 55 additions & 13 deletions

File tree

backends/samsung/_passes/compose_rms_norm.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,38 @@ class RecomposeRmsNorm(ExportPass):
1919
def __init__(self):
2020
super().__init__()
2121

22+
_ADD_TARGETS = (
23+
exir_ops.edge.aten.add.Tensor,
24+
exir_ops.edge.aten.add.Scalar,
25+
torch.ops.aten.add.Tensor,
26+
torch.ops.aten.add.Scalar,
27+
)
28+
2229
def _get_eps_node(self, nodes):
2330
# eps: one of inputs of add node
24-
add_node = [n for n in nodes if hasattr(n, "name") and "add" in n.name][0]
31+
add_nodes = [
32+
n
33+
for n in nodes
34+
if isinstance(n, torch.fx.Node)
35+
and n.op == "call_function"
36+
and n.target in self._ADD_TARGETS
37+
]
38+
if not add_nodes:
39+
raise RuntimeError("Failed to locate add node in RMSNorm partition")
40+
add_node = add_nodes[0]
2541
for a in add_node.args:
26-
if isinstance(a, float) or a.op != "call_function":
42+
if isinstance(a, float) or (
43+
isinstance(a, torch.fx.Node) and a.op != "call_function"
44+
):
2745
return a
46+
raise RuntimeError("Failed to locate eps argument in RMSNorm add node")
2847

2948
def _get_gamma_node(self, output_node):
3049
# gamma: one of inputs of output node
3150
for a in output_node.args:
32-
if a.op != "call_function":
51+
if isinstance(a, torch.fx.Node) and a.op != "call_function":
3352
return a
53+
raise RuntimeError("Failed to locate gamma argument in RMSNorm output node")
3454

3555
def call(self, graph_module: torch.fx.GraphModule):
3656
graph = graph_module.graph

backends/samsung/builders/op_split_with_sizes_copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def define_node(
2323
node: torch.fx.Node,
2424
enn_graph: EnnGraph,
2525
vals_to_ids: Dict[torch.Tensor, int],
26-
):
26+
) -> None:
2727
input = node.args[0]
2828
input_id = self.define_tensor(input, enn_graph, vals_to_ids)
2929

backends/samsung/builders/op_topk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def define_node(
6767
raise AssertionError("Not supported largest = False.")
6868

6969
if len(node.args) > 4:
70-
sorted = cast(bool, node.args[4])
71-
if not sorted:
70+
is_sorted = cast(bool, node.args[4])
71+
if not is_sorted:
7272
raise AssertionError("Not supported sorted = False.")
7373

7474
enn_graph.define_op(node.name, "TopK", [input_id], all_output_tensors, params)

backends/samsung/serialization/compile_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from enum import IntEnum, unique
1313

1414
from importlib.resources import files
15+
from typing import Optional
1516

1617
from executorch.exir._serialize._dataclass import _DataclassEncoder
1718
from executorch.exir._serialize._flatbuffer import _flatc_compile
@@ -73,7 +74,7 @@ def gen_samsung_backend_compile_spec_core(options: EnnExecuTorchOptions) -> Comp
7374

7475
def gen_samsung_backend_compile_spec(
7576
chipset: str,
76-
perf_mode: PerformanceMode = None,
77+
perf_mode: Optional[PerformanceMode] = None,
7778
):
7879
"""
7980
A function to generate an ExecuTorch binary for Samsung Backend.

backends/samsung/test/ops/test_pow.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,43 @@
1616
from executorch.backends.samsung.test.utils.utils import TestConfig
1717

1818

19-
class Pow(torch.nn.Module):
19+
class PowScalar(torch.nn.Module):
2020
def __init__(self) -> None:
2121
super().__init__()
2222

2323
def forward(self, x: torch.Tensor) -> torch.Tensor:
2424
return x**2.0
2525

2626

27+
class PowTensor(torch.nn.Module):
28+
def __init__(self) -> None:
29+
super().__init__()
30+
31+
def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
32+
return torch.pow(x, y)
33+
34+
2735
class TestPow(unittest.TestCase):
28-
def _test(self, module: torch.nn.Module, inputs):
36+
def _test(self, module: torch.nn.Module, inputs, expected_op: str):
2937
tester = SamsungTester(
3038
module,
3139
inputs,
3240
[gen_samsung_backend_compile_spec(TestConfig.chipset)],
3341
)
3442
(
3543
tester.export()
36-
.check_count({"torch.ops.aten.pow.Tensor_Scalar": 1})
44+
.check_count({expected_op: 1})
3745
.to_edge_transform_and_lower()
3846
.check_not(["executorch_exir_dialects_edge__ops_aten_pow_default"])
3947
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
4048
.to_executorch()
4149
.run_method_and_compare_outputs()
4250
)
4351

44-
def test_fp32_pow(self):
52+
def test_fp32_pow_scalar(self):
4553
inputs = (torch.randn(1, 1, 16, 8),)
46-
self._test(Pow(), inputs)
54+
self._test(PowScalar(), inputs, "torch.ops.aten.pow.Tensor_Scalar")
55+
56+
def test_fp32_pow_tensor(self):
57+
inputs = (torch.randn(1, 1, 16, 8), torch.randn(1, 1, 16, 8))
58+
self._test(PowTensor(), inputs, "torch.ops.aten.pow.Tensor_Tensor")

examples/samsung/aot_compiler.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
help=f"Model name. Valid ones: {SUPPORT_MODEL_NAMES}",
5656
)
5757
parser.add_argument("-o", "--output_dir", default=".", help="output directory")
58+
parser.add_argument(
59+
"--perf_mode",
60+
default=PerformanceMode.DEFAULT.name,
61+
choices=[m.name for m in PerformanceMode],
62+
help=(
63+
"Performance mode. HIGH_PERFORMANCE is experimental and must be "
64+
"verified on the exynos device farm before deploying on a phone."
65+
),
66+
)
5867

5968
args = parser.parse_args()
6069

@@ -78,7 +87,7 @@
7887
compile_specs = [
7988
gen_samsung_backend_compile_spec(
8089
args.chipset,
81-
PerformanceMode.HIGH_PERFORMANCE,
90+
PerformanceMode[args.perf_mode],
8291
)
8392
]
8493
edge = to_edge_transform_and_lower_to_enn(

0 commit comments

Comments
 (0)