Skip to content

Commit 7dc517c

Browse files
Arm backend: Convert asserts to raise errors in op_minimum
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. Change-Id: I1bc2f001f1a5a75a57468263bc5343de1476b90f Signed-off-by: Sebastian Larsson <[email protected]>
1 parent c9c5481 commit 7dc517c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

backends/arm/operators/op_minimum.py

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

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

62+
# insert RESCALEs to int32
5663
operand_inputs, scale_back = tqutils.insert_rescale_ops_to_int32(
5764
tosa_graph, inputs, node
5865
)

0 commit comments

Comments
 (0)