Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions backends/arm/_passes/fuse_batchnorm2d_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion backends/arm/arm_vela.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<iiiiiiiii", *inp_pad, io_elem_size, io_offset, io_region
Expand Down
3 changes: 2 additions & 1 deletion backends/arm/common/arm_compile_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def validate(self):

def to_list(self):
"""Get the ArmCompileSpec in list form."""
assert self.tosa_spec
if not self.tosa_spec:
raise ValueError("tosa_spec must be set before calling to_list()")

# Always supply a TOSA version
compile_spec = [
Expand Down
23 changes: 18 additions & 5 deletions backends/arm/process_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,16 @@ def process_inputs_to_parameters(
) from e
parameter_data = get_param(edge_program, node)

assert isinstance(parameter_data, torch.Tensor), "Expect Attr to be tensor"
if not isinstance(parameter_data, torch.Tensor):
raise TypeError(
f"Expected parameter '{node.name}' to be a torch.Tensor, got "
f"{type(parameter_data).__name__}"
)
parameter_values = parameter_data.detach().numpy()

if tosa_arg.dtype == torch.float32:
assert tosa_spec.support_float(), f"{tosa_spec} doesn't support float"
if not tosa_spec.support_float():
raise ValueError(f"{tosa_spec} doesn't support float operations")

# Handle special case for INT48 tensors
special_type = node.meta.get(TosaSpecialDtype.meta_key(), None)
Expand Down Expand Up @@ -142,7 +147,11 @@ def process_inputs_to_buffers(
) from e
buffer_data = get_buffer(edge_program, node)

assert isinstance(buffer_data, torch.Tensor), "Expect Attr to be tensor"
if not isinstance(buffer_data, torch.Tensor):
raise TypeError(
f"Expected buffer '{node.name}' to be a torch.Tensor, got "
f"{type(buffer_data).__name__}"
)
buffer_values = buffer_data.detach().numpy()

# TODO: fragile code for temporary fix
Expand Down Expand Up @@ -183,8 +192,12 @@ def process_placeholder(
tosa_spec: TosaSpecification,
):
"""Wrapper for processing and serializing all types of placeholders"""
assert node.name == node.target, "Expect placeholder name and target to match"
assert 0 == len(node.args), "Can't handle default input values"
if node.name != node.target:
raise ValueError(
f"Placeholder name '{node.name}' does not match target '{node.target}'"
)
if len(node.args) != 0:
raise ValueError(f"Placeholder '{node.name}' must not have default values")

if node.name in edge_program.graph_signature.user_inputs:
process_inputs(node, tosa_graph, tosa_spec)
Expand Down
Loading