diff --git a/backends/arm/_passes/fuse_batchnorm2d_pass.py b/backends/arm/_passes/fuse_batchnorm2d_pass.py index be884585d4d..8be6b61d25c 100644 --- a/backends/arm/_passes/fuse_batchnorm2d_pass.py +++ b/backends/arm/_passes/fuse_batchnorm2d_pass.py @@ -12,6 +12,7 @@ create_node, get_first_fake_tensor, ) +from executorch.backends.arm.common.debug import get_node_debug_info from executorch.backends.transforms.utils import ( create_constant_placeholder, delete_constant_placeholder, @@ -60,8 +61,16 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult: # noqa: C901 input_node = node.all_input_nodes[0] is_single_user = len(input_node.users) == 1 bn_weight_node, bn_bias_node, bn_mean_node, bn_var_node = node.args[1:5] - assert bn_mean_node is not None, "Batchnorm mean node cannot be None." - assert bn_var_node is not None, "Batchnorm var node cannot be None." + if bn_mean_node is None: + raise RuntimeError( + "BatchNorm mean buffer missing for node: " + f"{get_node_debug_info(node, graph_module)}" + ) + if bn_var_node is None: + raise RuntimeError( + "BatchNorm variance buffer missing for node: " + f"{get_node_debug_info(node, graph_module)}" + ) epsilon = node.args[-1] @@ -133,14 +142,23 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult: # noqa: C901 input_node = new_input_node else: input_weight_node, input_bias_node = input_node.args[1:3] - assert ( + if not ( isinstance(input_weight_node, Node) and input_weight_node.op == "placeholder" - ), "Parameter weight of convolution must be a placeholder" - assert (input_bias_node is None) or ( - isinstance(input_weight_node, Node) - and input_weight_node.op == "placeholder" - ), "Parameter bias of convolution must be a placeholder or None" + ): + raise RuntimeError( + "Parameter weight of convolution must be a placeholder" + ) + if not ( + (input_bias_node is None) + or ( + isinstance(input_weight_node, Node) + and input_weight_node.op == "placeholder" + ) + ): + raise RuntimeError( + "Parameter bias of convolution must be a placeholder or None" + ) input_weight_tensor = torch.Tensor( get_param(self.exported_program, input_weight_node) diff --git a/backends/arm/arm_vela.py b/backends/arm/arm_vela.py index 90f9dcb8324..cc53c711dca 100644 --- a/backends/arm/arm_vela.py +++ b/backends/arm/arm_vela.py @@ -34,7 +34,10 @@ def vela_bin_pack_io(prefix, data): io_elem_size = data[prefix + "_elem_size"][i] io_offset = data[prefix + "_offset"][i] io_region = data[prefix + "_region"][i] - assert len(io_shape) == vela_io_shape_dims + if len(io_shape) != vela_io_shape_dims: + raise ValueError( + f"Expected {vela_io_shape_dims}D shape, got {len(io_shape)}D" + ) inp_pad = io_shape.tolist() io_struct = struct.pack( "