Skip to content

[Backend Tester] Seed based on test name #13313

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 197 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from 123 commits
Commits
Show all changes
197 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
fd26fc7
Update
GregoryComer Jul 24, 2025
4ae840d
Update
GregoryComer Jul 24, 2025
710ea49
Update
GregoryComer Jul 24, 2025
32f54b0
Update
GregoryComer Jul 24, 2025
a27d18c
Update
GregoryComer Jul 24, 2025
2eb59fc
Update
GregoryComer Jul 24, 2025
5cc4941
Update
GregoryComer Jul 24, 2025
ef7af5c
Update
GregoryComer Jul 24, 2025
18e89c1
Update
GregoryComer Jul 24, 2025
4719c90
Update
GregoryComer Jul 25, 2025
dd09555
Update
GregoryComer Aug 8, 2025
f1db3a0
Update
GregoryComer Aug 8, 2025
e0700b2
Update
GregoryComer Aug 8, 2025
f260b50
Update
GregoryComer Aug 8, 2025
d62ee60
Update
GregoryComer Aug 8, 2025
b2ab3a5
Update
GregoryComer Aug 8, 2025
c23c3e9
Update
GregoryComer Aug 8, 2025
c99c41a
Update
GregoryComer Aug 9, 2025
bf57d6c
Update
GregoryComer Aug 9, 2025
f261355
Update
GregoryComer Aug 11, 2025
c3a24f9
Update
GregoryComer Aug 11, 2025
1697cbc
Update
GregoryComer Aug 11, 2025
b94b45e
Update
GregoryComer Aug 11, 2025
5740f0a
Update
GregoryComer Aug 11, 2025
ed6840d
Update
GregoryComer Aug 11, 2025
f2a7e1f
Update
GregoryComer Aug 11, 2025
0e162ab
Update
GregoryComer Aug 11, 2025
c6bd56b
Update
GregoryComer Aug 11, 2025
144a8ae
Update
GregoryComer Aug 12, 2025
6f85fc1
Update
GregoryComer Aug 12, 2025
2439022
Update
GregoryComer Aug 12, 2025
bd79ef2
Update
GregoryComer Aug 12, 2025
8932c29
Update
GregoryComer Aug 12, 2025
ea2549c
Update
GregoryComer Aug 12, 2025
ffaa1c3
Update
GregoryComer Aug 12, 2025
bba2fa9
Update
GregoryComer Aug 12, 2025
3a3e026
Update
GregoryComer Aug 12, 2025
2c4488f
Update
GregoryComer Aug 12, 2025
491ec2b
Update
GregoryComer Aug 12, 2025
375b076
Update
GregoryComer Aug 12, 2025
fc1c2a7
Update
GregoryComer Aug 12, 2025
78086b4
Update
GregoryComer Aug 12, 2025
285e058
Update
GregoryComer Aug 12, 2025
cfbc408
Update
GregoryComer Aug 12, 2025
f4b0dc2
Update
GregoryComer Aug 12, 2025
5e92884
Update
GregoryComer Aug 12, 2025
605a0ad
Update
GregoryComer Aug 12, 2025
aa27776
Update
GregoryComer Aug 12, 2025
90ce443
Update
GregoryComer Aug 12, 2025
67f60e4
Update
GregoryComer Aug 12, 2025
1b9315e
Update
GregoryComer Aug 12, 2025
54563ee
Update
GregoryComer Aug 12, 2025
94d89c4
Update
GregoryComer Aug 12, 2025
d79d1a8
Update
GregoryComer Aug 12, 2025
733d4f9
Update
GregoryComer Aug 12, 2025
1e3e79c
Update
GregoryComer Aug 12, 2025
6043952
Update
GregoryComer Aug 12, 2025
8f476ea
Update
GregoryComer Aug 12, 2025
1c136d7
Update
GregoryComer Aug 12, 2025
780519f
Update
GregoryComer Aug 12, 2025
a62c6d0
Update
GregoryComer Aug 12, 2025
7e1a002
Update
GregoryComer Aug 12, 2025
a628d29
Update
GregoryComer Aug 12, 2025
3615d89
Update
GregoryComer Aug 12, 2025
e994bc1
Update
GregoryComer Aug 12, 2025
0aba8e1
Update
GregoryComer Aug 12, 2025
4329bf6
Update
GregoryComer Aug 12, 2025
105aabc
Update
GregoryComer Aug 12, 2025
c1a51ee
Update
GregoryComer Aug 12, 2025
dd30127
Update
GregoryComer Aug 12, 2025
4216805
Update
GregoryComer Aug 12, 2025
092b8d1
Update
GregoryComer Aug 12, 2025
bd786cd
Update
GregoryComer Aug 12, 2025
1d34f49
Update
GregoryComer Aug 12, 2025
933fba2
Update
GregoryComer Aug 12, 2025
d468ae4
Update
GregoryComer Aug 12, 2025
acbd480
Update
GregoryComer Aug 12, 2025
e515bf1
Update
GregoryComer Aug 12, 2025
803db00
Update
GregoryComer Aug 12, 2025
ab18089
Update
GregoryComer Aug 12, 2025
49944fa
Update
GregoryComer Aug 12, 2025
60f3932
Update
GregoryComer Aug 12, 2025
fe201b8
Update
GregoryComer Aug 12, 2025
a807a90
Update
GregoryComer Aug 12, 2025
1897d4e
Update
GregoryComer Aug 12, 2025
f65d80f
Update
GregoryComer Aug 12, 2025
0d1f097
Update
GregoryComer Aug 12, 2025
f0c2490
Update
GregoryComer Aug 12, 2025
0046b02
Update
GregoryComer Aug 12, 2025
32e1029
Update
GregoryComer Aug 12, 2025
f4df9c9
Update
GregoryComer Aug 12, 2025
832cea5
Update
GregoryComer Aug 12, 2025
40819b9
Update
GregoryComer Aug 12, 2025
692f0fa
Update
GregoryComer Aug 12, 2025
871312a
Update
GregoryComer Aug 12, 2025
53990fe
Update
GregoryComer Aug 12, 2025
567d055
Update
GregoryComer Aug 12, 2025
cd998cf
Update
GregoryComer Aug 12, 2025
2a837ab
Update
GregoryComer Aug 12, 2025
51c392a
Update
GregoryComer Aug 12, 2025
f066d46
Update
GregoryComer Aug 12, 2025
ab5415f
Update
GregoryComer Aug 12, 2025
e96c2ef
Update
GregoryComer Aug 12, 2025
31bc137
Update
GregoryComer Aug 12, 2025
dae5d43
Update
GregoryComer Aug 12, 2025
06b5532
Update
GregoryComer Aug 12, 2025
a343abc
Update
GregoryComer Aug 12, 2025
778f7cd
Update
GregoryComer Aug 12, 2025
c19a8ea
Update
GregoryComer Aug 12, 2025
b4a8428
Update
GregoryComer Aug 12, 2025
8aa25c7
Update
GregoryComer Aug 12, 2025
637b8a2
Update
GregoryComer Aug 12, 2025
7141f6c
Update
GregoryComer Aug 12, 2025
4b43363
Update
GregoryComer Aug 12, 2025
88d1dd3
Update
GregoryComer Aug 12, 2025
c583fa1
Update
GregoryComer Aug 12, 2025
7ba2a7f
Update
GregoryComer Aug 12, 2025
e7b7975
Update
GregoryComer Aug 13, 2025
995c4b5
Update
GregoryComer Aug 13, 2025
0fc4475
Update
GregoryComer Aug 13, 2025
1fec71c
Update
GregoryComer Aug 13, 2025
ad8ab13
Update
GregoryComer Aug 13, 2025
f955b94
Update
GregoryComer Aug 13, 2025
a3c2dbe
Update
GregoryComer Aug 13, 2025
1008ad4
Update
GregoryComer Aug 13, 2025
e94e9ae
Update
GregoryComer Aug 13, 2025
0225d15
Update
GregoryComer Aug 13, 2025
98eee4d
Update
GregoryComer Aug 13, 2025
ad04155
Update
GregoryComer Aug 13, 2025
20574c3
Update
GregoryComer Aug 13, 2025
a5f702f
Update
GregoryComer Aug 13, 2025
569916c
Update
GregoryComer Aug 13, 2025
8303207
Update
GregoryComer Aug 13, 2025
b299659
Update
GregoryComer Aug 13, 2025
5a717d5
Update
GregoryComer Aug 13, 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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ if(EXECUTORCH_BUILD_PYBIND)
list(APPEND _dep_libs openvino_backend)
endif()

if(EXECUTORCH_BUILD_VULKAN)
list(APPEND _dep_libs vulkan_backend)
endif()

if(EXECUTORCH_BUILD_XNNPACK)
# need to explicitly specify XNNPACK and xnnpack-microkernels-prod here
# otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
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"
]
)
91 changes: 91 additions & 0 deletions backends/qualcomm/tests/tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 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_htp_compiler_spec,
generate_qnn_executorch_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, generate_etrecord: bool = False
) -> 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,
generate_etrecord=generate_etrecord,
)


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,
)
99 changes: 99 additions & 0 deletions backends/test/harness/error_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from dataclasses import dataclass

import torch
from torch.ao.ns.fx.utils import compute_sqnr


@dataclass
class TensorStatistics:
"""Contains summary statistics for a tensor."""

shape: torch.Size
""" The shape of the tensor. """

numel: int
""" The number of elements in the tensor. """

median: float
""" The median of the tensor. """

mean: float
""" The mean of the tensor. """

max: torch.types.Number
""" The maximum element of the tensor. """

min: torch.types.Number
""" The minimum element of the tensor. """

@classmethod
def from_tensor(cls, tensor: torch.Tensor) -> "TensorStatistics":
"""Creates a TensorStatistics object from a tensor."""
flattened = torch.flatten(tensor)
return cls(
shape=tensor.shape,
numel=tensor.numel(),
median=torch.quantile(flattened, q=0.5).item(),
mean=flattened.mean().item(),
max=flattened.max().item(),
min=flattened.min().item(),
)


@dataclass
class ErrorStatistics:
"""Contains statistics derived from the difference of two tensors."""

reference_stats: TensorStatistics
""" Statistics for the reference tensor. """

actual_stats: TensorStatistics
""" Statistics for the actual tensor. """

error_l2_norm: float | None
""" The L2 norm of the error between the actual and reference tensor. """

error_mae: float | None
""" The mean absolute error between the actual and reference tensor. """

error_max: float | None
""" The maximum absolute elementwise error between the actual and reference tensor. """

error_msd: float | None
""" The mean signed deviation between the actual and reference tensor. """

sqnr: float | None
""" The signal-to-quantization-noise ratio between the actual and reference tensor. """

@classmethod
def from_tensors(
cls, actual: torch.Tensor, reference: torch.Tensor
) -> "ErrorStatistics":
"""Creates an ErrorStatistics object from two tensors."""
actual = actual.to(torch.float64)
reference = reference.to(torch.float64)

if actual.shape != reference.shape:
return cls(
reference_stats=TensorStatistics.from_tensor(reference),
actual_stats=TensorStatistics.from_tensor(actual),
error_l2_norm=None,
error_mae=None,
error_max=None,
error_msd=None,
sqnr=None,
)

error = actual - reference
flat_error = torch.flatten(error)

return cls(
reference_stats=TensorStatistics.from_tensor(reference),
actual_stats=TensorStatistics.from_tensor(actual),
error_l2_norm=torch.linalg.norm(flat_error).item(),
error_mae=torch.mean(torch.abs(flat_error)).item(),
error_max=torch.max(torch.abs(flat_error)).item(),
error_msd=torch.mean(flat_error).item(),
# Torch sqnr implementation requires float32 due to decorator logic
sqnr=compute_sqnr(actual.to(torch.float), reference.to(torch.float)).item(),
)
5 changes: 4 additions & 1 deletion backends/test/harness/stages/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
try:
from executorch.extension.pybindings.portable_lib import ( # @manual
_load_for_executorch_from_buffer,
Verification,
)
except ImportError as e:
logger.warning(f"{e=}")
Expand All @@ -39,7 +40,9 @@ def graph_module(self) -> None:

def run_artifact(self, inputs):
inputs_flattened, _ = tree_flatten(inputs)
executorch_module = _load_for_executorch_from_buffer(self.buffer)
executorch_module = _load_for_executorch_from_buffer(
self.buffer, program_verification=Verification.Minimal
)
executorch_output = copy.deepcopy(
executorch_module.run_method("forward", tuple(inputs_flattened))
)
Expand Down
18 changes: 14 additions & 4 deletions backends/test/harness/stages/to_edge_transform_and_lower.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,38 @@
to_edge_transform_and_lower,
)
from executorch.exir.backend.partitioner import Partitioner

from torch.export import ExportedProgram


class ToEdgeTransformAndLower(Stage):
def __init__(
self,
default_partitioner_cls: Type,
default_partitioner_cls: Type | None = None,
partitioners: Optional[List[Partitioner]] = None,
edge_compile_config: Optional[EdgeCompileConfig] = None,
):
self.partitioners = partitioners or [default_partitioner_cls()]
self.edge_compile_conf = edge_compile_config or EdgeCompileConfig()
self.partitioners = (
partitioners or [default_partitioner_cls()]
if default_partitioner_cls is not None
else []
)
self.edge_compile_conf = edge_compile_config or EdgeCompileConfig(
_check_ir_validity=False
)
self.edge_dialect_program = None

def stage_type(self) -> StageType:
return StageType.TO_EDGE_TRANSFORM_AND_LOWER

def run(self, artifact: ExportedProgram, inputs=None) -> None:
def run(
self, artifact: ExportedProgram, inputs=None, generate_etrecord: bool = False
) -> None:
self.edge_dialect_program = to_edge_transform_and_lower(
artifact,
compile_config=self.edge_compile_conf,
partitioner=self.partitioners,
generate_etrecord=generate_etrecord,
)

@property
Expand Down
Loading
Loading