Skip to content

Arm backend: Convert assert to throw TypeError in op_add #9897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
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
26 changes: 21 additions & 5 deletions backends/arm/operators/op_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ def define_node(
) -> None:
# Specification (0.80) states that input and output types
# should all be the same
assert inputs[0].dtype == inputs[1].dtype == output.dtype
if inputs[0].dtype != inputs[1].dtype or inputs[0].dtype != output.dtype:
raise TypeError(
f"All IO needs to have the same data type, got input 1: "
f"{inputs[0].dtype}, input 2: {inputs[1].dtype} and output: "
f"{output.dtype}"
)
# Handle int8 (quantized) and int32
assert inputs[0].dtype in [ts.DType.INT8, ts.DType.INT32]
supported_dtypes = [ts.DType.INT8, ts.DType.INT32]
if inputs[0].dtype not in supported_dtypes:
raise TypeError(
f'IO data type needs to be {supported_dtypes}, got "{inputs[0].dtype}"'
)

dim_order = (
inputs[0].dim_order
Expand Down Expand Up @@ -105,15 +114,22 @@ def define_node(
) -> None:
# Specification (0.80) states that input and output types
# should all be the same
assert inputs[0].dtype == inputs[1].dtype == output.dtype
if inputs[0].dtype != inputs[1].dtype or inputs[0].dtype != output.dtype:
raise TypeError(
f"All IO needs to have the same data type, got input 1: "
f"{inputs[0].dtype}, input 2: {inputs[1].dtype} and output: "
f"{output.dtype}"
)

if inputs[0].dtype in [ts.DType.INT8, ts.DType.INT32]:
# Call the inherited define_node for handling integers
super().define_node(node, tosa_graph, inputs, output)
else:
# FP32 Add lowering
assert inputs[0].dtype == ts.DType.FP32
assert output.dtype == ts.DType.FP32
if inputs[0].dtype != ts.DType.FP32:
raise TypeError(
f"Expected IO data type to be FP32, got {inputs[0].dtype}"
)

input1, input2 = tutils.reshape_for_broadcast(tosa_graph, inputs)

Expand Down
Loading