Skip to content

Commit 410bec5

Browse files
Sebastian-Larssonkirklandsign
authored andcommitted
Arm backend: Convert assert to raise ValueError in op_clamp (#9932)
Asserts are converted to proper raises to ensure graph integrity. It should not be possible for clamp to have more than 1 input for a correctly formatted graph, but in the node visitor we cannot know for sure that the graph is formatted correctly. Signed-off-by: Sebastian Larsson <sebastian.larsson@arm.com>
1 parent 74eac1a commit 410bec5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

backends/arm/operators/op_clamp.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def cast_type(value: Any) -> int | float:
6363
# Attempt to cast to float
6464
return float(value)
6565

66-
assert 2 <= len(node.args) <= 3
66+
if len(node.args) != 2 and len(node.args) != 3:
67+
raise ValueError(f"Expected len(node.args) to be 2 or 3, got {node.args}")
6768

6869
min_arg = dtype_min
6970
max_arg = dtype_max
@@ -84,7 +85,10 @@ def define_node(
8485
inputs: List[TosaArg],
8586
output: TosaArg,
8687
) -> None:
87-
assert len(node.all_input_nodes) == 1
88+
if len(node.all_input_nodes) != 1:
89+
raise ValueError(
90+
f"Expected 1 input for {self.target}, got {len(node.all_input_nodes)}"
91+
)
8892

8993
min_int8, max_int8 = self._get_min_max_arguments(
9094
node,
@@ -122,7 +126,10 @@ def define_node(
122126
inputs: List[TosaArg],
123127
output: TosaArg,
124128
) -> None:
125-
assert len(node.all_input_nodes) == 1
129+
if len(node.all_input_nodes) != 1:
130+
raise ValueError(
131+
f"Expected 1 input for {self.target}, got {len(node.all_input_nodes)}"
132+
)
126133

127134
if inputs[0].dtype == ts.DType.INT8:
128135
# Call the inherited define_node for handling integers

0 commit comments

Comments
 (0)