forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fill_scalar.py
More file actions
108 lines (88 loc) · 2.62 KB
/
test_fill_scalar.py
File metadata and controls
108 lines (88 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright 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.
from typing import Tuple
import torch
from executorch.backends.arm.test import common
from executorch.backends.arm.test.tester.test_pipeline import (
EthosU55PipelineINT,
EthosU85PipelineINT,
TosaPipelineFP,
TosaPipelineINT,
VgfPipeline,
)
aten_op = "torch.ops.aten.fill_.Scalar"
exir_op = "executorch_exir_dialects_edge__ops_aten_full_like_default"
input_t1 = Tuple[torch.Tensor]
test_data_suite = {
"ones_float": [torch.ones(2, 3), 5.0],
"ones_int": [torch.ones(2, 3), -3],
}
class FillScalar(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, y: torch.Tensor, fill_value: int | float):
mask = torch.full_like(y, 0)
mask.fill_(fill_value)
return mask * y
@common.parametrize("test_data", test_data_suite)
def test_fill_scalar_tosa_FP(test_data: Tuple):
pipeline = TosaPipelineFP[input_t1](
FillScalar(),
(*test_data,),
aten_op=aten_op,
exir_op=exir_op,
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
def test_fill_scalar_tosa_INT(test_data: Tuple):
pipeline = TosaPipelineINT[input_t1](
FillScalar(),
(*test_data,),
aten_op=aten_op,
exir_op=exir_op,
)
pipeline.run()
@common.XfailIfNoCorstone300
@common.parametrize("test_data", test_data_suite)
def test_fill_scalar_u55_INT(test_data: Tuple):
pipeline = EthosU55PipelineINT[input_t1](
FillScalar(),
(*test_data,),
aten_ops=[aten_op],
exir_ops=exir_op,
)
pipeline.run()
@common.XfailIfNoCorstone320
@common.parametrize("test_data", test_data_suite)
def test_fill_scalar_u85_INT(test_data: Tuple):
pipeline = EthosU85PipelineINT[input_t1](
FillScalar(),
(*test_data,),
aten_ops=[aten_op],
exir_ops=exir_op,
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
@common.SkipIfNoModelConverter
def test_fill_scalar_vgf_FP(test_data: input_t1):
pipeline = VgfPipeline[input_t1](
FillScalar(),
(*test_data,),
aten_op,
exir_op,
tosa_version="TOSA-1.0+FP",
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
@common.SkipIfNoModelConverter
def test_fill_scalar_vgf_INT(test_data: input_t1):
pipeline = VgfPipeline[input_t1](
FillScalar(),
(*test_data,),
aten_op,
exir_op,
tosa_version="TOSA-1.0+INT",
)
pipeline.run()