Skip to content

Arm backend: Support scalar_tensor op #9711

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
Mar 27, 2025
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
1 change: 1 addition & 0 deletions backends/arm/_passes/fuse_constant_ops_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def f(node_name_pre_computed):
exir_ops.edge.aten.arange.start_step,
exir_ops.edge.aten.eye.default,
exir_ops.edge.aten.linspace.default,
torch.ops.aten.scalar_tensor.default,
]

def __init__(self, exported_program: ExportedProgram) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def is_node_supported(
exir_ops.edge.aten.amin.default,
exir_ops.edge.aten.eye.default,
exir_ops.edge.aten.linspace.default,
torch.ops.aten.scalar_tensor.default,
]

return supported
Expand Down
5 changes: 2 additions & 3 deletions backends/arm/test/models/test_conformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class TestConformer(unittest.TestCase):
"executorch_exir_dialects_edge__ops_aten_where_self": 4,
"torch.ops.aten._assert_scalar.default": 10,
"torch.ops.aten._local_scalar_dense.default": 1,
"torch.ops.aten.scalar_tensor.default": 2,
"torch.ops.higher_order.executorch_call_delegate": 6,
}

Expand Down Expand Up @@ -92,7 +91,7 @@ def test_conformer_tosa_BI(self):
)
)

@conftest.expectedFailureOnFVP # TODO(MLETORCH-635)
@unittest.expectedFailure # TODO(MLETORCH-635)
def test_conformer_u55_BI(self):
tester = (
ArmTester(
Expand All @@ -114,7 +113,7 @@ def test_conformer_u55_BI(self):
inputs=get_test_inputs(self.dim, self.lengths, self.num_examples),
)

@conftest.expectedFailureOnFVP # TODO(MLETORCH-635)
@unittest.expectedFailure # TODO(MLETORCH-635)
def test_conformer_u85_BI(self):
tester = (
ArmTester(
Expand Down
91 changes: 91 additions & 0 deletions backends/arm/test/ops/test_scalar_tensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2024-2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import torch
from executorch.backends.arm.test import common

from executorch.backends.arm.test.tester.test_pipeline import (
EthosU55PipelineBI,
EthosU85PipelineBI,
TosaPipelineBI,
TosaPipelineMI,
)

float_test_data_suite = {
"scalar_tensor_float_1": (3.7, torch.float32, torch.rand((1, 2, 3, 4))),
"scalar_tensor_float_2": (66, torch.float32, torch.rand((1, 2, 3))),
}

int_test_data_suite = {
"scalar_tensor_int32": (
33,
torch.int32,
torch.randint(0, 10, (1, 2), dtype=torch.int32),
),
"scalar_tensor_int8": (
8,
torch.int8,
torch.rand(1, 2, 3),
),
"scalar_tensor_int16": (
16 * 16 * 16,
torch.int16,
torch.rand((1,)).unsqueeze(0), # Rank 0 inputs not supported
),
}


class ScalarTensor(torch.nn.Module):
aten_op = "torch.ops.aten.scalar_tensor.default"

def __init__(self, scalar, dtype=torch.float32):
super().__init__()
self.scalar = scalar
self.dtype = dtype

def forward(self, x: torch.Tensor):
return torch.scalar_tensor(self.scalar, dtype=self.dtype) + x


@common.parametrize("test_data", int_test_data_suite | float_test_data_suite)
def test_scalar_tensor_tosa_MI(test_data): # Note TOSA MI supports all types
scalar, dtype, data = test_data
TosaPipelineMI(ScalarTensor(scalar, dtype), tuple(data), ScalarTensor.aten_op).run()


@common.parametrize("test_data", int_test_data_suite | float_test_data_suite)
def test_scalar_tensor_tosa_BI(test_data):
scalar, dtype, data = test_data
pipeline: TosaPipelineBI = TosaPipelineBI(
ScalarTensor(scalar, dtype), tuple(data), ScalarTensor.aten_op
)
pipeline.pop_stage("check.quant_nodes")
pipeline.run()


@common.parametrize("test_data", float_test_data_suite)
@common.XfailIfNoCorstone300
def test_scalar_tensor_tosa_u55(test_data):
scalar, dtype, data = test_data
EthosU55PipelineBI(
ScalarTensor(scalar, dtype),
tuple(data),
ScalarTensor.aten_op,
symmetric_io_quantization=True,
run_on_fvp=True,
).run()


@common.parametrize("test_data", float_test_data_suite)
@common.XfailIfNoCorstone320
def test_scalar_tensor_tosa_u85(test_data):
scalar, dtype, data = test_data
EthosU85PipelineBI(
ScalarTensor(scalar, dtype),
tuple(data),
ScalarTensor.aten_op,
symmetric_io_quantization=True,
run_on_fvp=True,
).run()
Loading