-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathtest_exp.py
More file actions
170 lines (143 loc) · 4.16 KB
/
test_exp.py
File metadata and controls
170 lines (143 loc) · 4.16 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# Copyright 2024-2026 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,
)
test_data_suite = {
# (test_name, test_data)
"zeros": lambda: torch.zeros(1, 10, 10, 10),
"ones": lambda: torch.ones(10, 10, 10),
"rand": lambda: torch.rand(10, 10) - 0.5,
"randn_pos": lambda: torch.randn(1, 4, 4, 4) + 10,
"randn_neg": lambda: torch.randn(10) - 10,
"ramp": lambda: torch.arange(-16, 16, 0.2),
}
test_data_suite_bf16 = {
"rand_bf16": lambda: torch.rand(6, 6, dtype=torch.bfloat16) - 0.5,
"ramp_bf16": lambda: torch.arange(-8, 8, 0.5, dtype=torch.bfloat16),
}
test_data_suite_fp16 = {
"rand_fp16": lambda: torch.rand(6, 6, dtype=torch.float16) - 0.5,
"ramp_fp16": lambda: torch.arange(-8, 8, 0.5, dtype=torch.float16),
}
aten_op = "torch.ops.aten.exp.default"
input_t1 = Tuple[torch.Tensor] # Input x
class Exp(torch.nn.Module):
def forward(self, x: torch.Tensor) -> torch.Tensor:
return torch.exp(x)
@common.parametrize(
"test_data", test_data_suite | test_data_suite_bf16 | test_data_suite_fp16
)
def test_exp_tosa_FP(test_data: Tuple):
pipeline = TosaPipelineFP[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_op=[],
tosa_extensions=["bf16"],
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
def test_exp_tosa_INT(test_data: Tuple):
pipeline = TosaPipelineINT[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_op=[],
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
@common.XfailIfNoCorstone300
def test_exp_u55_INT(test_data: Tuple):
pipeline = EthosU55PipelineINT[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_ops=[],
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
@common.XfailIfNoCorstone320
def test_exp_u85_INT(test_data: Tuple):
pipeline = EthosU85PipelineINT[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_ops=[],
)
pipeline.run()
@common.parametrize("test_data", test_data_suite | test_data_suite_fp16)
@common.SkipIfNoModelConverter
def test_exp_vgf_no_quant(test_data: Tuple):
data = test_data()
if data.dtype == torch.float16:
atol = 2e-2
rtol = 2e-2
else:
atol = 1e-3
rtol = 1e-3
pipeline = VgfPipeline[input_t1](
Exp(),
(data,),
aten_op,
exir_op=[],
quantize=False,
atol=atol,
rtol=rtol,
)
pipeline.run()
@common.parametrize("test_data", test_data_suite)
@common.SkipIfNoModelConverter
def test_exp_vgf_quant(test_data: Tuple):
pipeline = VgfPipeline[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_op=[],
quantize=True,
)
pipeline.run()
a16w8_exp_test_parameters = {
"rank1_rand": lambda: torch.rand(10),
"rank2_rand": lambda: torch.rand(8, 8) - 0.5,
"rank3_rand": lambda: torch.rand(1, 4, 4) * 2 - 1,
}
@common.parametrize("test_data", a16w8_exp_test_parameters)
@common.XfailIfNoCorstone300
def test_exp_a16w8_u55_INT(test_data: Tuple):
pipeline = EthosU55PipelineINT[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_ops=[],
symmetric_io_quantization=True,
a16w8_quantization=True,
qtol=128,
epsilon=2**-16,
)
pipeline.run()
@common.parametrize("test_data", a16w8_exp_test_parameters)
@common.XfailIfNoCorstone320
def test_exp_a16w8_u85_INT(test_data: Tuple):
pipeline = EthosU85PipelineINT[input_t1](
Exp(),
(test_data(),),
aten_op,
exir_ops=[],
symmetric_io_quantization=True,
a16w8_quantization=True,
qtol=128,
epsilon=2**-16,
)
pipeline.run()