Skip to content

Commit b81e30b

Browse files
Arm backend: Convert asserts to raise errors in op_minimum (#10055)
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 8d8f677 commit b81e30b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

backends/arm/operators/op_minimum.py

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

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

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

0 commit comments

Comments
 (0)