Skip to content

Commit 8e08b7c

Browse files
Arm backend: Convert asserts to raise errors in op_maximum (#10102)
Asserts are converted to proper raises to ensure graph integrity. Improve error messages and add additional check that both inputs and outputs have the same data type. Signed-off-by: Sebastian Larsson <[email protected]>
1 parent 1505903 commit 8e08b7c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

backends/arm/operators/op_maximum.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,27 @@ def define_node(
3636
inputs: List[TosaArg],
3737
output: TosaArg,
3838
) -> None:
39-
assert inputs[0].dtype == inputs[1].dtype
39+
if inputs[0].dtype != inputs[1].dtype and inputs[0].dtype != output.dtype:
40+
raise TypeError(
41+
f"Data type of inputs and output must be the same. Got input 0 dtype: "
42+
f"{inputs[0].dtype}, input 1 dtype: {inputs[1].dtype} and output "
43+
f"dtype: {output.dtype}"
44+
)
4045

4146
scale_back = 1.0
4247
max_output = output
4348
if inputs[0].dtype == ts.DType.INT8:
4449
input_qparams = get_input_qparams(node)
45-
assert (
46-
len(input_qparams) == 2
47-
), f"Both inputs needs to have quantization information for {node}"
48-
# insert RESCALEs to int32
49-
assert (
50-
input_qparams[0] == input_qparams[1]
51-
), "Both inputs must have same quantization for MAX"
50+
if len(input_qparams) != 2:
51+
raise ValueError(
52+
f"Both inputs need to have quantization information for {node}"
53+
)
54+
if input_qparams[0] != input_qparams[1]:
55+
raise ValueError(
56+
"Both inputs must have the same quantization parameters for MAX"
57+
)
5258

59+
# insert RESCALEs to int32
5360
operand_inputs, scale_back = tqutils.insert_rescale_ops_to_int32(
5461
tosa_graph, inputs, node
5562
)

0 commit comments

Comments
 (0)