Skip to content

Commit 64b174a

Browse files
committed
Update
[ghstack-poisoned]
2 parents c0f6224 + a9ed762 commit 64b174a

File tree

19 files changed

+94
-90
lines changed

19 files changed

+94
-90
lines changed

backends/apple/coreml/test/tester.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
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+
import functools
78
from typing import Any, List, Optional, Sequence, Tuple
89

910
import coremltools as ct
1011
import executorch
1112
import executorch.backends.test.harness.stages as BaseStages
12-
import functools
1313
import torch
1414

1515
from executorch.backends.apple.coreml.compiler import CoreMLBackend
@@ -21,7 +21,7 @@
2121
from executorch.exir.backend.partitioner import Partitioner
2222

2323

24-
def _get_static_int8_qconfig():
24+
def _get_static_int8_linear_qconfig():
2525
return ct.optimize.torch.quantization.LinearQuantizerConfig(
2626
global_config=ct.optimize.torch.quantization.ModuleLinearQuantizerConfig(
2727
quantization_scheme="symmetric",
@@ -42,22 +42,23 @@ def __init__(
4242
is_qat: Optional[bool] = False,
4343
):
4444
super().__init__(
45-
quantizer=quantizer or CoreMLQuantizer(quantization_config or _get_static_int8_qconfig()),
45+
quantizer=quantizer
46+
or CoreMLQuantizer(quantization_config or _get_static_int8_linear_qconfig()),
4647
calibrate=calibrate,
4748
calibration_samples=calibration_samples,
4849
is_qat=is_qat,
4950
)
5051

5152

52-
5353
class Partition(BaseStages.Partition):
5454
def __init__(
55-
self,
55+
self,
5656
partitioner: Optional[Partitioner] = None,
5757
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
5858
):
5959
super().__init__(
60-
partitioner=partitioner or CoreMLPartitioner(
60+
partitioner=partitioner
61+
or CoreMLPartitioner(
6162
compile_specs=CoreMLBackend.generate_compile_specs(
6263
minimum_deployment_target=minimum_deployment_target
6364
)
@@ -74,9 +75,9 @@ def __init__(
7475
):
7576
super().__init__(
7677
default_partitioner_cls=lambda: CoreMLPartitioner(
77-
compile_specs=CoreMLBackend.generate_compile_specs(
78+
compile_specs=CoreMLBackend.generate_compile_specs(
7879
minimum_deployment_target=minimum_deployment_target
79-
)
80+
)
8081
),
8182
partitioners=partitioners,
8283
edge_compile_config=edge_compile_config,
@@ -96,8 +97,13 @@ def __init__(
9697
executorch.backends.test.harness.Tester.default_stage_classes()
9798
| {
9899
StageType.QUANTIZE: Quantize,
99-
StageType.PARTITION: functools.partial(Partition, minimum_deployment_target=minimum_deployment_target),
100-
StageType.TO_EDGE_TRANSFORM_AND_LOWER: functools.partial(ToEdgeTransformAndLower, minimum_deployment_target=minimum_deployment_target),
100+
StageType.PARTITION: functools.partial(
101+
Partition, minimum_deployment_target=minimum_deployment_target
102+
),
103+
StageType.TO_EDGE_TRANSFORM_AND_LOWER: functools.partial(
104+
ToEdgeTransformAndLower,
105+
minimum_deployment_target=minimum_deployment_target,
106+
),
101107
}
102108
)
103109

backends/test/harness/stages/quantize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ def __init__(
2525
calibrate: bool = True,
2626
calibration_samples: Optional[Sequence[Any]] = None,
2727
is_qat: Optional[bool] = False,
28+
set_global: bool = True,
2829
):
2930
self.quantizer = quantizer
3031
self.quantization_config = quantization_config
3132
self.calibrate = calibrate
3233
self.calibration_samples = calibration_samples
3334

34-
if self.quantization_config is not None:
35+
if self.quantization_config is not None and set_global:
3536
self.quantizer.set_global(self.quantization_config)
3637

3738
self.converted_graph = None

backends/test/suite/flow.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,39 @@ class TestFlow:
2222

2323
backend: str
2424
""" The name of the target backend. """
25-
25+
2626
tester_factory: Callable[..., Tester]
2727
""" A factory function that returns a Tester instance for this lowering flow. """
2828

2929
quantize: bool = field(default=False)
3030
""" Whether to tester should run the quantize stage on the model. """
31-
31+
3232
quantize_stage_factory: Callable[..., Quantize] | None = None
3333
""" A factory function which instantiates a Quantize stage. Can be None to use the tester's default. """
3434

35+
3536
def all_flows() -> dict[str, TestFlow]:
3637
flows = []
37-
38+
3839
try:
39-
from executorch.backends.test.suite.flows.xnnpack import XNNPACK_TEST_FLOW, XNNPACK_STATIC_INT8_TEST_FLOW
40+
from executorch.backends.test.suite.flows.xnnpack import (
41+
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
42+
XNNPACK_TEST_FLOW,
43+
)
44+
4045
flows += [
4146
XNNPACK_TEST_FLOW,
42-
XNNPACK_STATIC_INT8_TEST_FLOW,
47+
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
4348
]
4449
except Exception as e:
4550
logger.info(f"Skipping XNNPACK flow registration: {e}")
4651

4752
try:
48-
from executorch.backends.test.suite.flows.coreml import COREML_TEST_FLOW, COREML_STATIC_INT8_TEST_FLOW
53+
from executorch.backends.test.suite.flows.coreml import (
54+
COREML_STATIC_INT8_TEST_FLOW,
55+
COREML_TEST_FLOW,
56+
)
57+
4958
flows += [
5059
COREML_TEST_FLOW,
5160
COREML_STATIC_INT8_TEST_FLOW,
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import coremltools
21
import functools
2+
from typing import Any
3+
4+
import coremltools
35

46
from executorch.backends.apple.coreml.test.tester import CoreMLTester
57
from executorch.backends.test.suite.flow import TestFlow
6-
from typing import Any
8+
79

810
def _create_coreml_flow(
9-
name: str,
10-
quantize: bool = False,
11-
minimum_deployment_target: Any = coremltools.target.iOS15
11+
name: str,
12+
quantize: bool = False,
13+
minimum_deployment_target: Any = coremltools.target.iOS15,
1214
) -> TestFlow:
1315
return TestFlow(
1416
name,
1517
backend="coreml",
16-
tester_factory=functools.partial(CoreMLTester, minimum_deployment_target=minimum_deployment_target),
18+
tester_factory=functools.partial(
19+
CoreMLTester, minimum_deployment_target=minimum_deployment_target
20+
),
1721
quantize=quantize,
1822
)
1923

24+
2025
COREML_TEST_FLOW = _create_coreml_flow("coreml")
2126
COREML_STATIC_INT8_TEST_FLOW = _create_coreml_flow(
22-
"coreml_static_int8",
27+
"coreml_static_int8",
2328
quantize=True,
24-
minimum_deployment_target=coremltools.target.iOS17)
29+
minimum_deployment_target=coremltools.target.iOS17,
30+
)
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
1+
import logging
2+
from typing import Callable
3+
14
from executorch.backends.test.harness.stages import Quantize
25
from executorch.backends.test.suite.flow import TestFlow
3-
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer import get_symmetric_quantization_config
6+
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer import (
7+
get_symmetric_quantization_config,
8+
)
49
from executorch.backends.xnnpack.test.tester import (
510
Quantize as XnnpackQuantize,
6-
Tester as XnnpackTester
11+
Tester as XnnpackTester,
712
)
8-
from typing import Callable
9-
10-
import logging
1113

1214
logger = logging.getLogger(__name__)
1315
logger.setLevel(logging.INFO)
1416

15-
def _create_xnnpack_flow_base(name: str, quantize_stage_factory: Callable[..., Quantize] | None = None) -> TestFlow:
17+
18+
def _create_xnnpack_flow_base(
19+
name: str, quantize_stage_factory: Callable[..., Quantize] | None = None
20+
) -> TestFlow:
1621
return TestFlow(
1722
name,
1823
backend="xnnpack",
1924
tester_factory=XnnpackTester,
2025
quantize=quantize_stage_factory is not None,
2126
quantize_stage_factory=quantize_stage_factory,
2227
)
23-
28+
29+
2430
def _create_xnnpack_flow() -> TestFlow:
2531
return _create_xnnpack_flow_base("xnnpack")
2632

27-
def _create_xnnpack_static_int8_flow() -> TestFlow:
33+
34+
def _create_xnnpack_static_int8_per_channel_flow() -> TestFlow:
2835
def create_quantize_stage() -> Quantize:
29-
qparams = get_symmetric_quantization_config(is_per_channel=True)
36+
qparams = get_symmetric_quantization_config(is_per_channel=True)
3037
return XnnpackQuantize(
3138
quantization_config=qparams,
3239
)
33-
return _create_xnnpack_flow_base("xnnpack_static_int8", create_quantize_stage)
40+
41+
return _create_xnnpack_flow_base("xnnpack_static_int8_per_channel", create_quantize_stage)
42+
3443

3544
XNNPACK_TEST_FLOW = _create_xnnpack_flow()
36-
XNNPACK_STATIC_INT8_TEST_FLOW = _create_xnnpack_static_int8_flow()
45+
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW = _create_xnnpack_static_int8_per_channel_flow()

backends/test/suite/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from typing import Any, Callable
1313

1414
import torch
15-
from executorch.backends.test.harness import Tester
1615
from executorch.backends.test.suite import get_test_flows
1716
from executorch.backends.test.suite.context import get_active_test_context, TestContext
1817
from executorch.backends.test.suite.flow import TestFlow

backends/test/suite/models/test_torchaudio.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# pyre-unsafe
88

99
import unittest
10-
from typing import Callable, Tuple
10+
from typing import Tuple
1111

1212
import torch
1313
import torchaudio
@@ -92,7 +92,10 @@ def test_wav2letter(
9292

9393
@unittest.skip("This model times out on all backends.")
9494
def test_wavernn(
95-
self, flow: TestFlow, dtype: torch.dtype, use_dynamic_shapes: bool,
95+
self,
96+
flow: TestFlow,
97+
dtype: torch.dtype,
98+
use_dynamic_shapes: bool,
9699
):
97100
model = torchaudio.models.WaveRNN(
98101
upsample_scales=[5, 5, 8], n_classes=512, hop_length=200

backends/test/suite/models/test_torchvision.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ def test_swin_v2_t(
154154
model = torchvision.models.swin_v2_t()
155155
self._test_cv_model(model, flow, dtype, use_dynamic_shapes)
156156

157-
def test_vgg11(
158-
self, flow: TestFlow, dtype: torch.dtype, use_dynamic_shapes: bool
159-
):
157+
def test_vgg11(self, flow: TestFlow, dtype: torch.dtype, use_dynamic_shapes: bool):
160158
model = torchvision.models.vgg11()
161159
self._test_cv_model(model, flow, dtype, use_dynamic_shapes)
162160

backends/test/suite/operators/test_gelu.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def forward(self, x):
2626
class TestGELU(OperatorTest):
2727
@dtype_test
2828
def test_gelu_dtype(self, flow: TestFlow, dtype) -> None:
29-
self._test_op(
30-
Model(), ((torch.rand(2, 10) * 10 - 5).to(dtype),), flow
31-
)
29+
self._test_op(Model(), ((torch.rand(2, 10) * 10 - 5).to(dtype),), flow)
3230

3331
def test_gelu_f32_single_dim(self, flow: TestFlow) -> None:
3432
self._test_op(Model(), (torch.randn(20),), flow)
@@ -37,9 +35,7 @@ def test_gelu_f32_multi_dim(self, flow: TestFlow) -> None:
3735
self._test_op(Model(), (torch.randn(2, 3, 4, 5),), flow)
3836

3937
def test_gelu_f32_tanh_approximation(self, flow: TestFlow) -> None:
40-
self._test_op(
41-
Model(approximate="tanh"), (torch.randn(3, 4, 5),), flow
42-
)
38+
self._test_op(Model(approximate="tanh"), (torch.randn(3, 4, 5),), flow)
4339

4440
def test_gelu_f32_boundary_values(self, flow: TestFlow) -> None:
4541
# Test with specific values spanning negative and positive ranges

backends/test/suite/operators/test_glu.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class TestGLU(OperatorTest):
2727
@dtype_test
2828
def test_glu_dtype(self, flow: TestFlow, dtype) -> None:
2929
# Input must have even number of elements in the specified dimension
30-
self._test_op(
31-
Model(), ((torch.rand(2, 10) * 10 - 5).to(dtype),), flow
32-
)
30+
self._test_op(Model(), ((torch.rand(2, 10) * 10 - 5).to(dtype),), flow)
3331

3432
def test_glu_f32_dim_last(self, flow: TestFlow) -> None:
3533
# Default dim is -1 (last dimension)

0 commit comments

Comments
 (0)