Skip to content

Commit 9338dd4

Browse files
committed
[Backend Tester] Add additional quantized test flows for XNNPACK and Vulkan
ghstack-source-id: c049cfd ghstack-comment-id: 3203339209 Pull-Request: #13534
1 parent c91069c commit 9338dd4

File tree

5 files changed

+102
-9
lines changed

5 files changed

+102
-9
lines changed

.github/workflows/nightly.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ jobs:
4242
strategy:
4343
fail-fast: false
4444
matrix:
45-
flow: [qualcomm, qualcomm_16a16w, qualcomm_16a8w, qualcomm_16a4w, qualcomm_16a4w_block, qualcomm_8a8w, vulkan, xnnpack, xnnpack_static_int8_per_channel]
45+
flow: [
46+
qualcomm, qualcomm_16a16w, qualcomm_16a8w, qualcomm_16a4w, qualcomm_16a4w_block, qualcomm_8a8w,
47+
vulkan, vulkan_static_int8_per_channel,
48+
xnnpack, xnnpack_dynamic_int8_per_channel, xnnpack_static_int8_per_channel, xnnpack_static_int8_per_tensor
49+
]
4650
suite: [models, operators]
4751
with:
4852
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

backends/test/suite/flow.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ def all_flows() -> dict[str, TestFlow]:
4747

4848
try:
4949
from executorch.backends.test.suite.flows.xnnpack import (
50+
XNNPACK_DYNAMIC_INT8_PER_CHANNEL_TEST_FLOW,
5051
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
52+
XNNPACK_STATIC_INT8_PER_TENSOR_TEST_FLOW,
5153
XNNPACK_TEST_FLOW,
5254
)
5355

5456
flows += [
5557
XNNPACK_TEST_FLOW,
58+
XNNPACK_DYNAMIC_INT8_PER_CHANNEL_TEST_FLOW,
5659
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
60+
XNNPACK_STATIC_INT8_PER_TENSOR_TEST_FLOW,
5761
]
5862
except Exception as e:
5963
logger.info(f"Skipping XNNPACK flow registration: {e}")
@@ -72,10 +76,14 @@ def all_flows() -> dict[str, TestFlow]:
7276
logger.info(f"Skipping Core ML flow registration: {e}")
7377

7478
try:
75-
from executorch.backends.test.suite.flows.vulkan import VULKAN_TEST_FLOW
79+
from executorch.backends.test.suite.flows.vulkan import (
80+
VULKAN_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
81+
VULKAN_TEST_FLOW,
82+
)
7683

7784
flows += [
7885
VULKAN_TEST_FLOW,
86+
VULKAN_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
7987
]
8088
except Exception as e:
8189
logger.info(f"Skipping Vulkan flow registration: {e}")

backends/test/suite/flows/vulkan.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1+
from typing import Callable
2+
3+
from executorch.backends.test.harness.stages import Quantize
14
from executorch.backends.test.suite.flow import TestFlow
2-
from executorch.backends.vulkan.test.tester import VulkanTester
5+
from executorch.backends.vulkan.quantizer.vulkan_quantizer import (
6+
get_symmetric_quantization_config as get_symmetric_quantization_config_vulkan,
7+
)
8+
from executorch.backends.vulkan.test.tester import (
9+
Quantize as VulkanQuantize,
10+
VulkanTester,
11+
)
312

413

5-
def _create_vulkan_flow(
6-
name: str,
7-
quantize: bool = False,
14+
def _create_vulkan_flow_base(
15+
name: str, quantize_stage_factory: Callable[..., Quantize] | None = None
816
) -> TestFlow:
917
return TestFlow(
1018
name,
1119
backend="vulkan",
1220
tester_factory=VulkanTester,
13-
quantize=quantize,
21+
quantize=quantize_stage_factory is not None,
22+
quantize_stage_factory=quantize_stage_factory,
23+
)
24+
25+
26+
def _create_vulkan_flow() -> TestFlow:
27+
return _create_vulkan_flow_base("vulkan")
28+
29+
30+
def _create_vulkan_static_int8_per_channel_flow() -> TestFlow:
31+
def create_quantize_stage() -> Quantize:
32+
qparams = get_symmetric_quantization_config_vulkan()
33+
return VulkanQuantize(
34+
quantization_config=qparams,
35+
)
36+
37+
return _create_vulkan_flow_base(
38+
"vulkan_static_int8_per_channel", create_quantize_stage
1439
)
1540

1641

17-
VULKAN_TEST_FLOW = _create_vulkan_flow("vulkan")
42+
VULKAN_TEST_FLOW = _create_vulkan_flow()
43+
VULKAN_STATIC_INT8_PER_CHANNEL_TEST_FLOW = _create_vulkan_static_int8_per_channel_flow()

backends/test/suite/flows/xnnpack.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ def _create_xnnpack_flow() -> TestFlow:
3131
return _create_xnnpack_flow_base("xnnpack")
3232

3333

34+
def _create_xnnpack_dynamic_int8_per_channel_flow() -> TestFlow:
35+
def create_quantize_stage() -> Quantize:
36+
qparams = get_symmetric_quantization_config(
37+
is_per_channel=True, is_dynamic=True
38+
)
39+
return XnnpackQuantize(
40+
quantization_config=qparams,
41+
)
42+
43+
return _create_xnnpack_flow_base(
44+
"xnnpack_dynamic_int8_per_channel", create_quantize_stage
45+
)
46+
47+
3448
def _create_xnnpack_static_int8_per_channel_flow() -> TestFlow:
3549
def create_quantize_stage() -> Quantize:
3650
qparams = get_symmetric_quantization_config(is_per_channel=True)
@@ -43,7 +57,23 @@ def create_quantize_stage() -> Quantize:
4357
)
4458

4559

60+
def _create_xnnpack_static_int8_per_tensor_flow() -> TestFlow:
61+
def create_quantize_stage() -> Quantize:
62+
qparams = get_symmetric_quantization_config(is_per_channel=False)
63+
return XnnpackQuantize(
64+
quantization_config=qparams,
65+
)
66+
67+
return _create_xnnpack_flow_base(
68+
"xnnpack_static_int8_per_tensor", create_quantize_stage
69+
)
70+
71+
4672
XNNPACK_TEST_FLOW = _create_xnnpack_flow()
73+
XNNPACK_DYNAMIC_INT8_PER_CHANNEL_TEST_FLOW = (
74+
_create_xnnpack_dynamic_int8_per_channel_flow()
75+
)
4776
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW = (
4877
_create_xnnpack_static_int8_per_channel_flow()
4978
)
79+
XNNPACK_STATIC_INT8_PER_TENSOR_TEST_FLOW = _create_xnnpack_static_int8_per_tensor_flow()

backends/vulkan/test/tester.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
from typing import Any, List, Optional, Tuple
7+
from typing import Any, List, Optional, Sequence, Tuple
88

99
import executorch
1010
import executorch.backends.test.harness.stages as BaseStages
@@ -13,8 +13,33 @@
1313
from executorch.backends.test.harness import Tester as TesterBase
1414
from executorch.backends.test.harness.stages import StageType
1515
from executorch.backends.vulkan.partitioner.vulkan_partitioner import VulkanPartitioner
16+
from executorch.backends.vulkan.quantizer.vulkan_quantizer import (
17+
get_symmetric_quantization_config as get_symmetric_quantization_config_vulkan,
18+
VulkanQuantizer,
19+
)
1620
from executorch.exir import EdgeCompileConfig
1721
from executorch.exir.backend.partitioner import Partitioner
22+
from torchao.quantization.pt2e.quantizer import Quantizer
23+
24+
25+
class Quantize(BaseStages.Quantize):
26+
def __init__(
27+
self,
28+
quantizer: Optional[Quantizer] = None,
29+
quantization_config: Any | None = None,
30+
calibrate: bool = True,
31+
calibration_samples: Optional[Sequence[Any]] = None,
32+
is_qat: Optional[bool] = False,
33+
):
34+
super().__init__(
35+
quantizer=quantizer or VulkanQuantizer(),
36+
quantization_config=(
37+
quantization_config or get_symmetric_quantization_config_vulkan()
38+
),
39+
calibrate=calibrate,
40+
calibration_samples=calibration_samples,
41+
is_qat=is_qat,
42+
)
1843

1944

2045
class Partition(BaseStages.Partition):

0 commit comments

Comments
 (0)