Skip to content

[Backend Tester] Add CSV report generation #12741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 71 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
f120e70
Update
GregoryComer Jul 18, 2025
0fb85e6
Update
GregoryComer Jul 18, 2025
4d8d844
Update
GregoryComer Jul 19, 2025
dc12b40
Update
GregoryComer Jul 21, 2025
ead0616
Update
GregoryComer Jul 22, 2025
0f13676
Update
GregoryComer Jul 22, 2025
b0b01f2
Update
GregoryComer Jul 22, 2025
8b9c9ef
Update
GregoryComer Jul 22, 2025
06bf03a
Update
GregoryComer Jul 22, 2025
2f8f49b
Update
GregoryComer Jul 22, 2025
8ca7766
Update
GregoryComer Jul 22, 2025
bffb95f
Update
GregoryComer Jul 22, 2025
d21492b
Update
GregoryComer Jul 22, 2025
e2c4ea5
Update
GregoryComer Jul 22, 2025
8230848
Update
GregoryComer Jul 22, 2025
2a1f564
Update
GregoryComer Jul 22, 2025
b35e7b1
Update
GregoryComer Jul 22, 2025
5c4c6ce
Update
GregoryComer Jul 22, 2025
9397803
Update
GregoryComer Jul 22, 2025
9dfeb5a
Update
GregoryComer Jul 22, 2025
ff5c4a5
Update
GregoryComer Jul 22, 2025
42a5de5
Update
GregoryComer Jul 22, 2025
402d8f5
Update
GregoryComer Jul 22, 2025
34d3ab3
Update
GregoryComer Jul 22, 2025
1105e04
Update
GregoryComer Jul 22, 2025
482bd21
Update
GregoryComer Jul 22, 2025
ea548b7
Update
GregoryComer Jul 23, 2025
4108f54
Update
GregoryComer Jul 23, 2025
7ef236b
Update
GregoryComer Jul 23, 2025
4a58c9d
Update
GregoryComer Jul 23, 2025
3b866b4
Update
GregoryComer Jul 23, 2025
5ba25cb
Update
GregoryComer Jul 23, 2025
19760fc
Update
GregoryComer Jul 23, 2025
81dfb07
Update
GregoryComer Jul 23, 2025
4d50265
Update
GregoryComer Jul 23, 2025
5f66043
Update
GregoryComer Jul 23, 2025
24e919d
Update
GregoryComer Jul 23, 2025
523cc20
Update
GregoryComer Jul 23, 2025
74c95fe
Update
GregoryComer Jul 23, 2025
5d437b1
Update
GregoryComer Jul 23, 2025
89757ce
Update
GregoryComer Jul 23, 2025
423f79a
Update
GregoryComer Jul 23, 2025
69f7f9c
Update
GregoryComer Jul 23, 2025
c0f6224
Update
GregoryComer Jul 23, 2025
e2ea2a3
Update
GregoryComer Jul 23, 2025
7a2fab5
Update
GregoryComer Jul 23, 2025
033c231
Update
GregoryComer Jul 23, 2025
a9ed762
Update
GregoryComer Jul 23, 2025
64b174a
Update
GregoryComer Jul 23, 2025
3976629
Update
GregoryComer Jul 23, 2025
27cd171
Update
GregoryComer Jul 23, 2025
7bdd3e5
Update
GregoryComer Jul 23, 2025
b1254cd
Update
GregoryComer Jul 23, 2025
f2e2289
Update
GregoryComer Jul 23, 2025
cdd15c1
Update
GregoryComer Jul 23, 2025
e2df06e
Update
GregoryComer Jul 23, 2025
4461bd8
Update
GregoryComer Jul 23, 2025
7e97fd0
Update
GregoryComer Jul 23, 2025
bcb697c
Update
GregoryComer Jul 23, 2025
11a5a02
Update
GregoryComer Jul 24, 2025
244b146
Update
GregoryComer Jul 24, 2025
de21ac2
Update
GregoryComer Jul 24, 2025
4ae840d
Update
GregoryComer Jul 24, 2025
710ea49
Update
GregoryComer Jul 24, 2025
32f54b0
Update
GregoryComer Jul 24, 2025
2eb59fc
Update
GregoryComer Jul 24, 2025
5cc4941
Update
GregoryComer Jul 24, 2025
dd09555
Update
GregoryComer Aug 8, 2025
f1db3a0
Update
GregoryComer Aug 8, 2025
f261355
Update
GregoryComer Aug 11, 2025
c3a24f9
Update
GregoryComer Aug 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions backends/apple/coreml/test/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,64 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from typing import Any, List, Optional, Tuple
from typing import Any, List, Optional, Sequence, Tuple

import coremltools as ct
import executorch
import executorch.backends.test.harness.stages as BaseStages

import functools
import torch

from executorch.backends.apple.coreml.compiler import CoreMLBackend
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
from executorch.backends.apple.coreml.quantizer import CoreMLQuantizer
from executorch.backends.test.harness import Tester as TesterBase
from executorch.backends.test.harness.stages import StageType
from executorch.exir import EdgeCompileConfig
from executorch.exir.backend.partitioner import Partitioner


def _get_static_int8_qconfig():
return ct.optimize.torch.quantization.LinearQuantizerConfig(
global_config=ct.optimize.torch.quantization.ModuleLinearQuantizerConfig(
quantization_scheme="symmetric",
activation_dtype=torch.quint8,
weight_dtype=torch.qint8,
weight_per_channel=True,
)
)


class Quantize(BaseStages.Quantize):
def __init__(
self,
quantizer: Optional[CoreMLQuantizer] = None,
quantization_config: Optional[Any] = None,
calibrate: bool = True,
calibration_samples: Optional[Sequence[Any]] = None,
is_qat: Optional[bool] = False,
):
super().__init__(
quantizer=quantizer or CoreMLQuantizer(quantization_config or _get_static_int8_qconfig()),
calibrate=calibrate,
calibration_samples=calibration_samples,
is_qat=is_qat,
)



class Partition(BaseStages.Partition):
def __init__(self, partitioner: Optional[Partitioner] = None):
def __init__(
self,
partitioner: Optional[Partitioner] = None,
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
):
super().__init__(
partitioner=partitioner or CoreMLPartitioner,
partitioner=partitioner or CoreMLPartitioner(
compile_specs=CoreMLBackend.generate_compile_specs(
minimum_deployment_target=minimum_deployment_target
)
),
)


Expand All @@ -29,9 +70,14 @@ def __init__(
self,
partitioners: Optional[List[Partitioner]] = None,
edge_compile_config: Optional[EdgeCompileConfig] = None,
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
):
super().__init__(
default_partitioner_cls=CoreMLPartitioner,
default_partitioner_cls=lambda: CoreMLPartitioner(
compile_specs=CoreMLBackend.generate_compile_specs(
minimum_deployment_target=minimum_deployment_target
)
),
partitioners=partitioners,
edge_compile_config=edge_compile_config,
)
Expand All @@ -43,13 +89,15 @@ def __init__(
module: torch.nn.Module,
example_inputs: Tuple[torch.Tensor],
dynamic_shapes: Optional[Tuple[Any]] = None,
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
):
# Specialize for XNNPACK
stage_classes = (
executorch.backends.test.harness.Tester.default_stage_classes()
| {
StageType.PARTITION: Partition,
StageType.TO_EDGE_TRANSFORM_AND_LOWER: ToEdgeTransformAndLower,
StageType.QUANTIZE: Quantize,
StageType.PARTITION: functools.partial(Partition, minimum_deployment_target=minimum_deployment_target),
StageType.TO_EDGE_TRANSFORM_AND_LOWER: functools.partial(ToEdgeTransformAndLower, minimum_deployment_target=minimum_deployment_target),
}
)

Expand Down
10 changes: 10 additions & 0 deletions backends/qualcomm/tests/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ python_library(
"//executorch/backends/qualcomm/debugger:utils",
],
)

python_library(
name = "tester",
srcs = [
"tester.py",
],
deps = [
":test_qnn_delegate"
]
)
87 changes: 87 additions & 0 deletions backends/qualcomm/tests/tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from typing import Any, List, Optional, Tuple

import executorch
import executorch.backends.test.harness.stages as BaseStages

import torch
from executorch.backends.qualcomm._passes.qnn_pass_manager import QnnPassManager
from executorch.backends.qualcomm.partition.qnn_partitioner import QnnPartitioner
from executorch.backends.qualcomm.utils.utils import (
generate_qnn_executorch_compiler_spec,
generate_htp_compiler_spec,
get_soc_to_chipset_map,
)
from executorch.backends.test.harness import Tester as TesterBase
from executorch.backends.test.harness.stages import StageType
from executorch.exir import EdgeCompileConfig, to_edge_transform_and_lower
from executorch.exir.backend.partitioner import Partitioner
from torch.export import ExportedProgram


class Partition(BaseStages.Partition):
def __init__(self, partitioner: Optional[Partitioner] = None):
super().__init__(
partitioner=partitioner or QnnPartitioner,
)


class ToEdgeTransformAndLower(BaseStages.ToEdgeTransformAndLower):
def __init__(
self,
partitioners: Optional[List[Partitioner]] = None,
edge_compile_config: Optional[EdgeCompileConfig] = None,
soc_model: str = "SM8650"
):
backend_options = generate_htp_compiler_spec(use_fp16=True)
self.chipset = get_soc_to_chipset_map()[soc_model]
self.compiler_specs = generate_qnn_executorch_compiler_spec(
soc_model=self.chipset,
backend_options=backend_options,
)

super().__init__(
partitioners=partitioners or [QnnPartitioner(self.compiler_specs)],
edge_compile_config=edge_compile_config or EdgeCompileConfig(_check_ir_validity=False),
default_partitioner_cls=QnnPartitioner,
)

def run(self, artifact: ExportedProgram, inputs=None) -> None:
ep = QnnPassManager().transform_for_export_pipeline(artifact)
transform_passes = QnnPassManager().get_to_edge_transform_passes(ep)

self.edge_dialect_program = to_edge_transform_and_lower(
ep,
transform_passes=transform_passes,
partitioner=self.partitioners,
compile_config=self.edge_compile_conf,
)


class QualcommTester(TesterBase):
def __init__(
self,
module: torch.nn.Module,
example_inputs: Tuple[torch.Tensor],
dynamic_shapes: Optional[Tuple[Any]] = None,
):
# Specialize for Qualcomm
stage_classes = (
executorch.backends.test.harness.Tester.default_stage_classes()
| {
StageType.PARTITION: Partition,
StageType.TO_EDGE_TRANSFORM_AND_LOWER: ToEdgeTransformAndLower,
}
)

super().__init__(
module=module,
stage_classes=stage_classes,
example_inputs=example_inputs,
dynamic_shapes=dynamic_shapes,
)
3 changes: 2 additions & 1 deletion backends/test/harness/stages/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(
self.calibrate = calibrate
self.calibration_samples = calibration_samples

self.quantizer.set_global(self.quantization_config)
if self.quantization_config is not None:
self.quantizer.set_global(self.quantization_config)

self.converted_graph = None
self.is_qat = is_qat
Expand Down
6 changes: 3 additions & 3 deletions backends/test/harness/tester.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
from collections import Counter, OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Type
from typing import Any, Callable, Dict, List, Optional, Tuple

import torch

Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(
self,
module: torch.nn.Module,
example_inputs: Tuple[torch.Tensor],
stage_classes: Dict[StageType, Type],
stage_classes: Dict[StageType, Callable],
dynamic_shapes: Optional[Tuple[Any]] = None,
):
module.eval()
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
self.stage_output = None

@staticmethod
def default_stage_classes() -> Dict[StageType, Type]:
def default_stage_classes() -> Dict[StageType, Callable]:
"""
Returns a map of StageType to default Stage implementation.
"""
Expand Down
Loading
Loading