Skip to content

Commit ab4c473

Browse files
committed
Add 16A8W support for view and transpose operations
Add 16A8W quantization support for view and transpose operations in ExecutorTorch ARM backend. This follows the pattern established for linear, mul, sigmoid, tanh, and slice operations, extending int16 support to view and transpose operations. Changes: - Add INT16 dtype validation support in op_transpose.py - Add test_view_tensor_16a8w_tosa_INT test function - Enable test_view.py in test targets configuration The 16A8W configuration uses 16-bit activations with 8-bit weights, enabling higher precision for activations while maintaining weight efficiency. Differential Revision: [D80511313](https://our.internmc.facebook.com/intern/diff/D80511313/) [ghstack-poisoned]
1 parent 8281869 commit ab4c473

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

backends/arm/test/ops/test_view.py

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99

1010
from typing import Tuple
1111

12+
import pytest
1213
import torch
14+
from executorch.backends.arm.quantizer.arm_quantizer import (
15+
get_symmetric_a16w8_quantization_config,
16+
TOSAQuantizer,
17+
)
1318

14-
from executorch.backends.arm.test import common
19+
from executorch.backends.arm.test import common, conftest
1520
from executorch.backends.arm.test.tester.test_pipeline import (
1621
EthosU55PipelineINT,
1722
EthosU85PipelineINT,
@@ -20,6 +25,8 @@
2025
TosaPipelineINT,
2126
VgfPipeline,
2227
)
28+
from executorch.backends.arm.tosa_specification import TosaSpecification
29+
from executorch.backends.xnnpack.test.tester import Quantize
2330

2431
aten_op = "torch.ops.aten.view.default"
2532

@@ -147,3 +154,105 @@ def test_view_u85_INT(test_data: Tuple):
147154
exir_ops=[],
148155
)
149156
pipeline.run()
157+
158+
159+
def get_symmetric_a16w8_view_quantizer(per_channel_quantization=False):
160+
tosa_version = conftest.get_option("tosa_version")
161+
tosa_profiles = {
162+
"1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"),
163+
}
164+
165+
quantizer = TOSAQuantizer(tosa_profiles[tosa_version])
166+
quantizer.set_global(
167+
get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization)
168+
)
169+
170+
return Quantize(
171+
quantizer,
172+
get_symmetric_a16w8_quantization_config(
173+
is_per_channel=per_channel_quantization
174+
),
175+
)
176+
177+
178+
@common.parametrize("test_data", View.needs_transpose_tests)
179+
def test_view_16a8w_tosa_INT(test_data: Tuple):
180+
"""Test view operation with 16A8W quantization (16-bit activations, 8-bit weights)"""
181+
per_channel_quantization = False
182+
test_tensor, new_shape = test_data()
183+
184+
pipeline = TosaPipelineINT[input_t1](
185+
View(new_shape),
186+
(test_tensor,),
187+
aten_op,
188+
exir_op=[],
189+
per_channel_quantization=per_channel_quantization,
190+
use_to_edge_transform_and_lower=True,
191+
tosa_extensions=["int16"],
192+
)
193+
194+
pipeline.change_args(
195+
"quantize",
196+
get_symmetric_a16w8_view_quantizer(
197+
per_channel_quantization=per_channel_quantization
198+
),
199+
)
200+
pipeline.run()
201+
202+
203+
@common.parametrize("test_data", View.needs_transpose_tests)
204+
@common.XfailIfNoCorstone300
205+
@pytest.mark.xfail(
206+
reason="Vela compilation fails with 'Invalid arguments' for int16 view operations"
207+
)
208+
def test_view_16a8w_u55_INT16(test_data: Tuple):
209+
"""Test view operation with 16A8W quantization on U55 (16-bit activations, 8-bit weights)"""
210+
per_channel_quantization = False
211+
test_tensor, new_shape = test_data()
212+
213+
pipeline = EthosU55PipelineINT[input_t1](
214+
View(new_shape),
215+
(test_tensor,),
216+
aten_op,
217+
exir_ops=[],
218+
per_channel_quantization=per_channel_quantization,
219+
use_to_edge_transform_and_lower=True,
220+
run_on_fvp=True,
221+
)
222+
223+
pipeline.change_args(
224+
"quantize",
225+
get_symmetric_a16w8_view_quantizer(
226+
per_channel_quantization=per_channel_quantization
227+
),
228+
)
229+
pipeline.run()
230+
231+
232+
@common.parametrize("test_data", View.needs_transpose_tests)
233+
@common.XfailIfNoCorstone320
234+
@pytest.mark.xfail(
235+
reason="Vela compilation fails with 'Invalid arguments' for int16 view operations"
236+
)
237+
def test_view_16a8w_u85_INT16(test_data: Tuple):
238+
"""Test view operation with 16A8W quantization on U85 (16-bit activations, 8-bit weights)"""
239+
per_channel_quantization = False
240+
test_tensor, new_shape = test_data()
241+
242+
pipeline = EthosU85PipelineINT[input_t1](
243+
View(new_shape),
244+
(test_tensor,),
245+
aten_op,
246+
exir_ops=[],
247+
per_channel_quantization=per_channel_quantization,
248+
use_to_edge_transform_and_lower=True,
249+
run_on_fvp=True,
250+
)
251+
252+
pipeline.change_args(
253+
"quantize",
254+
get_symmetric_a16w8_view_quantizer(
255+
per_channel_quantization=per_channel_quantization
256+
),
257+
)
258+
pipeline.run()

backends/arm/test/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def define_arm_tests():
2020
"ops/test_slice.py",
2121
"ops/test_sigmoid.py",
2222
"ops/test_tanh.py",
23+
"ops/test_view.py",
2324
"ops/test_cos.py",
2425
]
2526

0 commit comments

Comments
 (0)