-
Notifications
You must be signed in to change notification settings - Fork 975
Expand file tree
/
Copy pathtest_multihead_attention.py
More file actions
141 lines (124 loc) · 3.6 KB
/
test_multihead_attention.py
File metadata and controls
141 lines (124 loc) · 3.6 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
# 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.
import torch
from executorch.backends.arm.test import common
from executorch.backends.arm.test.tester.test_pipeline import (
EthosU55PipelineINT,
EthosU85PipelineINT,
TosaPipelineFP,
TosaPipelineINT,
VgfPipeline,
)
class MultiheadAttention(torch.nn.MultiheadAttention):
def forward(self, *args, **kwargs):
return super().forward(*args, **kwargs)
input_t1 = tuple[torch.Tensor, torch.nn.Module]
test_suite = {
# test_name, (x,), embed_dim, num_heads, batch_first
"rand_2d": lambda: (
(torch.rand(6, 3),),
MultiheadAttention(embed_dim=3, num_heads=3, batch_first=True),
),
"randn_2d": lambda: (
(torch.randn(2, 4),),
MultiheadAttention(embed_dim=4, num_heads=2, batch_first=True),
),
"randn_3d": lambda: (
(torch.randn(3, 2, 4),),
MultiheadAttention(embed_dim=4, num_heads=2, batch_first=False),
),
}
@common.parametrize(
"test_data",
test_suite,
)
def test_multihead_attention_tosa_FP(test_data: input_t1):
test_data, module = test_data()
pipeline = TosaPipelineFP(module, (*test_data, *test_data, *test_data), [], [])
pipeline.run()
@common.parametrize(
"test_data",
test_suite,
)
def test_multihead_attention_tosa_INT(test_data):
test_data, module = test_data()
pipeline = TosaPipelineINT(
module,
(*test_data, *test_data, *test_data),
[],
[],
# TODO: Per-channel quantization is broken (MLETORCH-1144)
per_channel_quantization=False,
)
pipeline.run()
@common.parametrize(
"test_data",
test_suite,
)
@common.XfailIfNoCorstone300
def test_multihead_attention_u55_INT(test_data: input_t1):
test_data, module = test_data()
pipeline = EthosU55PipelineINT(
module,
(*test_data, *test_data, *test_data),
[],
[],
use_to_edge_transform_and_lower=True,
run_on_fvp=True,
# TODO: Per-channel quantization is broken (MLETORCH-1144)
per_channel_quantization=False,
)
pipeline.pop_stage("check_count.exir")
pipeline.run()
@common.parametrize(
"test_data",
test_suite,
)
@common.XfailIfNoCorstone320
def test_multihead_attention_u85_INT(test_data: input_t1):
test_data, module = test_data()
pipeline = EthosU85PipelineINT(
module,
(*test_data, *test_data, *test_data),
[],
[],
use_to_edge_transform_and_lower=True,
run_on_fvp=True,
# TODO: Per-channel quantization is broken (MLETORCH-1144)
per_channel_quantization=False,
)
pipeline.run()
@common.parametrize(
"test_data",
test_suite,
)
@common.SkipIfNoModelConverter
def test_multihead_attention_vgf_FP(test_data: input_t1):
test_data_vals, module = test_data()
pipeline = VgfPipeline[input_t1](
module,
(*test_data_vals, *test_data_vals, *test_data_vals),
[],
[],
tosa_version="TOSA-1.0+FP",
)
pipeline.run()
@common.parametrize(
"test_data",
test_suite,
)
@common.SkipIfNoModelConverter
def test_multihead_attention_vgf_INT(test_data: input_t1):
test_data_vals, module = test_data()
pipeline = VgfPipeline[input_t1](
module,
(*test_data_vals, *test_data_vals, *test_data_vals),
[],
[],
tosa_version="TOSA-1.0+INT",
# TODO: Per-channel quantization is broken (MLETORCH-1144)
per_channel_quantization=False,
)
pipeline.run()