Skip to content

Commit 2f2eb9e

Browse files
oscarandersson8218Teo Bergkvist
andauthored
Arm backend: Add support for fill_.Scalar (#14501)
Adds support for fill_.Scalar. fill_.scalar is decomposed to full_like which is already supported by Arm backend. Signed-off-by: Oscar Andersson <[email protected]> Co-authored-by: Teo Bergkvist <[email protected]>
1 parent df5bfd5 commit 2f2eb9e

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

backends/arm/quantizer/quantization_annotator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def _match_pattern(
360360
torch.ops.aten.max_pool2d.default,
361361
torch.ops.aten.full.default,
362362
torch.ops.aten.full,
363+
torch.ops.aten.fill_.Scalar,
363364
torch.ops.aten.flatten.using_ints,
364365
torch.ops.aten.dropout.default,
365366
torch.ops.aten.dropout_.default,
@@ -625,6 +626,7 @@ def annotate_graph( # type: ignore[return]
625626
torch.ops.aten.full_like.default,
626627
torch.ops.aten.full.default,
627628
torch.ops.aten.full,
629+
torch.ops.aten.fill_.Scalar,
628630
torch.ops.aten.scalar_tensor.default,
629631
]:
630632
node.kwargs = {}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates.
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
from typing import Tuple
7+
8+
import torch
9+
from executorch.backends.arm.test import common
10+
from executorch.backends.arm.test.tester.test_pipeline import (
11+
EthosU55PipelineINT,
12+
EthosU85PipelineINT,
13+
TosaPipelineFP,
14+
TosaPipelineINT,
15+
VgfPipeline,
16+
)
17+
18+
aten_op = "torch.ops.aten.fill_.Scalar"
19+
exir_op = "executorch_exir_dialects_edge__ops_aten_full_like_default"
20+
21+
input_t1 = Tuple[torch.Tensor]
22+
23+
test_data_suite = {
24+
"ones_float": [torch.ones(2, 3), 5.0],
25+
"ones_int": [torch.ones(2, 3), -3],
26+
}
27+
28+
29+
class FillScalar(torch.nn.Module):
30+
def __init__(self):
31+
super().__init__()
32+
33+
def forward(self, y: torch.Tensor, fill_value: int | float):
34+
mask = torch.full_like(y, 0)
35+
mask.fill_(fill_value)
36+
return mask * y
37+
38+
39+
@common.parametrize("test_data", test_data_suite)
40+
def test_fill_scalar_tosa_FP(test_data: Tuple):
41+
pipeline = TosaPipelineFP[input_t1](
42+
FillScalar(),
43+
(*test_data,),
44+
aten_op=aten_op,
45+
exir_op=exir_op,
46+
)
47+
pipeline.run()
48+
49+
50+
@common.parametrize("test_data", test_data_suite)
51+
def test_fill_scalar_tosa_INT(test_data: Tuple):
52+
pipeline = TosaPipelineINT[input_t1](
53+
FillScalar(),
54+
(*test_data,),
55+
aten_op=aten_op,
56+
exir_op=exir_op,
57+
)
58+
pipeline.run()
59+
60+
61+
@common.XfailIfNoCorstone300
62+
@common.parametrize("test_data", test_data_suite)
63+
def test_fill_scalar_u55_INT(test_data: Tuple):
64+
pipeline = EthosU55PipelineINT[input_t1](
65+
FillScalar(),
66+
(*test_data,),
67+
aten_ops=[aten_op],
68+
exir_ops=exir_op,
69+
)
70+
pipeline.run()
71+
72+
73+
@common.XfailIfNoCorstone320
74+
@common.parametrize("test_data", test_data_suite)
75+
def test_fill_scalar_u85_INT(test_data: Tuple):
76+
pipeline = EthosU85PipelineINT[input_t1](
77+
FillScalar(),
78+
(*test_data,),
79+
aten_ops=[aten_op],
80+
exir_ops=exir_op,
81+
)
82+
pipeline.run()
83+
84+
85+
@common.parametrize("test_data", test_data_suite)
86+
@common.SkipIfNoModelConverter
87+
def test_fill_scalar_vgf_FP(test_data: input_t1):
88+
pipeline = VgfPipeline[input_t1](
89+
FillScalar(),
90+
(*test_data,),
91+
aten_op,
92+
exir_op,
93+
tosa_version="TOSA-1.0+FP",
94+
)
95+
pipeline.run()
96+
97+
98+
@common.parametrize("test_data", test_data_suite)
99+
@common.SkipIfNoModelConverter
100+
def test_fill_scalar_vgf_INT(test_data: input_t1):
101+
pipeline = VgfPipeline[input_t1](
102+
FillScalar(),
103+
(*test_data,),
104+
aten_op,
105+
exir_op,
106+
tosa_version="TOSA-1.0+INT",
107+
)
108+
pipeline.run()

0 commit comments

Comments
 (0)