From f24b442d4235930ec4ab1ee73c4fbb55f306bfeb Mon Sep 17 00:00:00 2001 From: Sebastian Larsson Date: Wed, 2 Apr 2025 16:17:05 +0200 Subject: [PATCH] Arm backend: Convert assert to throw ValueError in op_log Asserts are converted to proper raises to ensure graph integrity. It should not be possible for log 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. torch.log supports more data types than fp32, which is why it should be checked. Change-Id: I83181cb2b733390acfce7bc875c846057c71d6f5 Signed-off-by: Sebastian Larsson --- backends/arm/operators/op_log.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backends/arm/operators/op_log.py b/backends/arm/operators/op_log.py index 34911075065..9942cbf4702 100644 --- a/backends/arm/operators/op_log.py +++ b/backends/arm/operators/op_log.py @@ -33,7 +33,14 @@ def define_node( inputs: List[TosaArg], output: TosaArg, ) -> None: - assert len(node.all_input_nodes) == 1 - assert inputs[0].dtype == output.dtype == ts.DType.FP32 + if len(node.all_input_nodes) != 1: + raise ValueError( + f"Expected 1 input for {self.target}, got {len(node.all_input_nodes)}" + ) + if inputs[0].dtype != ts.DType.FP32 or output.dtype != ts.DType.FP32: + raise ValueError( + f"Input and output for {self.target} need to be FP32, got input_dtype: " + f"{inputs[0].dtype} and output_dtype: {output.dtype}" + ) tosa_graph.addOperator(ts.TosaOp.Op().LOG, [inputs[0].name], [output.name])