From 7dc517caa2a1b4152265a22bcaf00dff85ee303d Mon Sep 17 00:00:00 2001 From: Sebastian Larsson Date: Fri, 4 Apr 2025 10:38:05 +0200 Subject: [PATCH] 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 --- backends/arm/operators/op_minimum.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/backends/arm/operators/op_minimum.py b/backends/arm/operators/op_minimum.py index 1b8c1960411..4b1967955c4 100644 --- a/backends/arm/operators/op_minimum.py +++ b/backends/arm/operators/op_minimum.py @@ -39,20 +39,27 @@ def define_node( inputs: List[TosaArg], output: TosaArg, ) -> None: - assert inputs[0].dtype == inputs[1].dtype + if inputs[0].dtype != inputs[1].dtype and inputs[0].dtype != output.dtype: + raise TypeError( + f"Data type of inputs and output must be the same. Got input 0 dtype: " + f"{inputs[0].dtype}, input 1 dtype: {inputs[1].dtype} and output " + f"dtype: {output.dtype}" + ) scale_back = 1.0 min_output = output if inputs[0].dtype == ts.DType.INT8: input_qparams = get_input_qparams(node) - assert ( - len(input_qparams) == 2 - ), f"Both inputs needs to have quantization information for {node}" - # insert RESCALEs to int32 - assert ( - input_qparams[0] == input_qparams[1] - ), "Both inputs must have same quantization for MIN" + if len(input_qparams) != 2: + raise ValueError( + f"Both inputs need to have quantization information for {node}" + ) + if input_qparams[0] != input_qparams[1]: + raise ValueError( + "Both inputs must have the same quantization parameters for MIN" + ) + # insert RESCALEs to int32 operand_inputs, scale_back = tqutils.insert_rescale_ops_to_int32( tosa_graph, inputs, node )