|
5 | 5 |
|
6 | 6 | from typing import Tuple |
7 | 7 |
|
| 8 | +import pytest |
8 | 9 | import torch |
| 10 | +from executorch.backends.arm.quantizer.arm_quantizer import ( |
| 11 | + get_symmetric_a16w8_quantization_config, |
| 12 | + TOSAQuantizer, |
| 13 | +) |
9 | 14 |
|
10 | | -from executorch.backends.arm.test import common |
| 15 | +from executorch.backends.arm.test import common, conftest |
11 | 16 | from executorch.backends.arm.test.tester.test_pipeline import ( |
12 | 17 | EthosU55PipelineINT, |
13 | 18 | EthosU85PipelineINT, |
|
16 | 21 | VgfPipeline, |
17 | 22 | ) |
18 | 23 |
|
| 24 | +from executorch.backends.arm.tosa import TosaSpecification |
| 25 | +from executorch.backends.xnnpack.test.tester import Quantize |
| 26 | + |
19 | 27 | from torch.nn.quantizable.modules import rnn |
20 | 28 |
|
21 | 29 | input_t = Tuple[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]] # (h0, c0) |
@@ -134,3 +142,71 @@ def test_lstm_vgf_FP(): |
134 | 142 | use_to_edge_transform_and_lower=True, |
135 | 143 | ) |
136 | 144 | pipeline.run() |
| 145 | + |
| 146 | + |
| 147 | +def get_symmetric_a16w8_lstm_quantizer(per_channel_quantization=False): |
| 148 | + tosa_version = conftest.get_option("tosa_version") |
| 149 | + tosa_profiles = { |
| 150 | + "1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"), |
| 151 | + } |
| 152 | + |
| 153 | + quantizer = TOSAQuantizer(tosa_profiles[tosa_version]) |
| 154 | + quantizer.set_global( |
| 155 | + get_symmetric_a16w8_quantization_config( |
| 156 | + is_per_channel=per_channel_quantization, epsilon=2**-16 |
| 157 | + ) |
| 158 | + ) |
| 159 | + |
| 160 | + return Quantize( |
| 161 | + quantizer, |
| 162 | + get_symmetric_a16w8_quantization_config( |
| 163 | + is_per_channel=per_channel_quantization, epsilon=2**-16 |
| 164 | + ), |
| 165 | + ) |
| 166 | + |
| 167 | + |
| 168 | +def test_lstm_16a8w_tosa_INT(): |
| 169 | + """Test LSTM model with 16A8W quantization (16-bit activations, 8-bit weights)""" |
| 170 | + |
| 171 | + pipeline = TosaPipelineINT[input_t]( |
| 172 | + TestLSTM.lstm, |
| 173 | + TestLSTM.model_example_inputs, |
| 174 | + aten_op=[], |
| 175 | + exir_op=[], |
| 176 | + per_channel_quantization=False, |
| 177 | + use_to_edge_transform_and_lower=True, |
| 178 | + tosa_extensions=["int16"], |
| 179 | + ) |
| 180 | + |
| 181 | + pipeline.change_args("quantize", get_symmetric_a16w8_lstm_quantizer()) |
| 182 | + pipeline.run() |
| 183 | + |
| 184 | + |
| 185 | +@pytest.mark.xfail( |
| 186 | + reason="MLETORCH-1452: AssertionError: Output 0 does not match reference output." |
| 187 | +) |
| 188 | +@common.XfailIfNoCorstone300 |
| 189 | +def test_lstm_16a8w_u55_INT(): |
| 190 | + pipeline = EthosU55PipelineINT[input_t]( |
| 191 | + TestLSTM.lstm, |
| 192 | + TestLSTM.model_example_inputs, |
| 193 | + aten_ops=[], |
| 194 | + exir_ops=[], |
| 195 | + use_to_edge_transform_and_lower=True, |
| 196 | + ) |
| 197 | + |
| 198 | + pipeline.change_args("quantize", get_symmetric_a16w8_lstm_quantizer()) |
| 199 | + pipeline.run() |
| 200 | + |
| 201 | + |
| 202 | +@common.XfailIfNoCorstone320 |
| 203 | +def test_lstm_16a8w_u85_INT(): |
| 204 | + pipeline = EthosU85PipelineINT[input_t]( |
| 205 | + TestLSTM.lstm, |
| 206 | + TestLSTM.model_example_inputs, |
| 207 | + aten_ops=[], |
| 208 | + exir_ops=[], |
| 209 | + use_to_edge_transform_and_lower=True, |
| 210 | + ) |
| 211 | + pipeline.change_args("quantize", get_symmetric_a16w8_lstm_quantizer()) |
| 212 | + pipeline.run() |
0 commit comments