Skip to content
Open
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
5 changes: 3 additions & 2 deletions backends/arm/operators/op_bmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
validate_valid_dtype(
self.target,
[*inputs, output],
[ts.DType.INT8, ts.DType.FP32],
[ts.DType.INT8, ts.DType.INT16, ts.DType.FP32],
output.tosa_spec,
)

Expand Down Expand Up @@ -93,7 +93,8 @@
if output.dtype == ts.DType.INT8:
output_qparams = get_output_qparams(node)[0]
final_output_scale = (
input_qparams[0].get_scale_per_tensor() * input_qparams[1].get_scale_per_tensor() # type: ignore[possibly-undefined] # pyre-ignore[61]
input_qparams[0].get_scale_per_tensor()

Check failure on line 96 in backends/arm/operators/op_bmm.py

View workflow job for this annotation

GitHub Actions / lintrunner / linux-job

MYPY possibly-undefined

Name "input_qparams" may be undefined To disable, use ` # type: ignore[possibly-undefined]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix mypy!

* input_qparams[1].get_scale_per_tensor() # type: ignore[possibly-undefined] # pyre-ignore[61]
) / output_qparams.get_scale_per_tensor()

build_rescale(
Expand Down
108 changes: 107 additions & 1 deletion backends/arm/test/ops/test_addmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@

from typing import Tuple

import pytest
import torch
from executorch.backends.arm.quantizer.arm_quantizer import (
get_symmetric_a16w8_quantization_config,
TOSAQuantizer,
)

from executorch.backends.arm.test import common
from executorch.backends.arm.test import common, conftest
from executorch.backends.arm.test.tester.test_pipeline import (
EthosU55PipelineINT,
EthosU85PipelineINT,
TosaPipelineFP,
TosaPipelineINT,
VgfPipeline,
)
from executorch.backends.arm.tosa_specification import TosaSpecification
from executorch.backends.xnnpack.test.tester import Quantize

aten_op = "torch.ops.aten.addmm.default"

Expand Down Expand Up @@ -182,3 +189,102 @@ def test_addmm_vgf_INT(test_data: input_t1):
tosa_version="TOSA-1.0+INT",
)
pipeline.run()


def get_symmetric_a16w8_addmm_quantizer(per_channel_quantization=False):
tosa_version = conftest.get_option("tosa_version")
tosa_profiles = {
"1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"),
}

quantizer = TOSAQuantizer(tosa_profiles[tosa_version])
quantizer.set_global(
get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization)
)

return Quantize(
quantizer,
get_symmetric_a16w8_quantization_config(
is_per_channel=per_channel_quantization
),
)


@common.parametrize("test_data", test_data_suite)
def test_addmm_16a8w_tosa_INT(test_data: input_t1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so this passes but linear doesn't, interesting :)

"""Test addmm (FC layer) operation with 16A8W quantization (16-bit activations, 8-bit weights)"""
per_channel_quantization = False

pipeline = TosaPipelineINT[input_t1](
Addmm(),
(*test_data,),
aten_op=[],
exir_op=[],
per_channel_quantization=per_channel_quantization,
use_to_edge_transform_and_lower=True,
tosa_extensions=["int16"],
)

pipeline.change_args(
"quantize",
get_symmetric_a16w8_addmm_quantizer(
per_channel_quantization=per_channel_quantization
),
)
pipeline.run()


@common.parametrize("test_data", test_data_suite)
@common.XfailIfNoCorstone300
@pytest.mark.xfail(
reason="Vela compilation fails with 'Invalid arguments' for int16 addmm operations"
)
def test_addmm_16a8w_u55_INT16(test_data: input_t1):
"""Test addmm (FC layer) operation with 16A8W quantization on U55 (16-bit activations, 8-bit weights)"""
per_channel_quantization = False

pipeline = EthosU55PipelineINT[input_t1](
Addmm(),
(*test_data,),
aten_ops=[],
exir_ops=[],
per_channel_quantization=per_channel_quantization,
use_to_edge_transform_and_lower=True,
run_on_fvp=True,
)

pipeline.change_args(
"quantize",
get_symmetric_a16w8_addmm_quantizer(
per_channel_quantization=per_channel_quantization
),
)
pipeline.run()


@common.parametrize("test_data", test_data_suite)
@common.XfailIfNoCorstone320
@pytest.mark.xfail(
reason="Vela compilation fails with 'Invalid arguments' for int16 addmm operations"
)
def test_addmm_16a8w_u85_INT16(test_data: input_t1):
"""Test addmm (FC layer) operation with 16A8W quantization on U85 (16-bit activations, 8-bit weights)"""
per_channel_quantization = False

pipeline = EthosU85PipelineINT[input_t1](
Addmm(),
(*test_data,),
aten_ops=[],
exir_ops=[],
per_channel_quantization=per_channel_quantization,
use_to_edge_transform_and_lower=True,
run_on_fvp=True,
)

pipeline.change_args(
"quantize",
get_symmetric_a16w8_addmm_quantizer(
per_channel_quantization=per_channel_quantization
),
)
pipeline.run()
1 change: 1 addition & 0 deletions backends/arm/test/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def define_arm_tests():
# Operators
test_files += [
"ops/test_add.py",
"ops/test_addmm.py",
"ops/test_avg_pool2d.py",
"ops/test_cat.py",
"ops/test_linear.py",
Expand Down
Loading