From f2fe72a1c74397d82bd3555574e95a2906a4e889 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Mon, 29 Sep 2025 12:33:44 -0700 Subject: [PATCH] delete qnnpack backend Summary: Afaik this is unused and not maintained Reviewed By: larryliu0820 Differential Revision: D83448512 --- backends/backends.bzl | 3 - exir/_serialize/TARGETS | 1 - exir/backend/test/demos/TARGETS | 25 --- .../test/demos/test_xnnpack_qnnpack.py | 190 ------------------ .../core/exec_aten/testing_util/targets.bzl | 1 - 5 files changed, 220 deletions(-) delete mode 100644 exir/backend/test/demos/test_xnnpack_qnnpack.py diff --git a/backends/backends.bzl b/backends/backends.bzl index 5ca30a83b54..42aed059f22 100644 --- a/backends/backends.bzl +++ b/backends/backends.bzl @@ -6,7 +6,6 @@ def get_all_cpu_backend_targets(): """ return [ "//executorch/backends/xnnpack:xnnpack_backend", - "//executorch/backends/fb/qnnpack:qnnpack_backend", ] def get_all_cpu_aot_and_backend_targets(): @@ -18,6 +17,4 @@ def get_all_cpu_aot_and_backend_targets(): return [ "//executorch/backends/xnnpack:xnnpack_preprocess", "//executorch/backends/xnnpack/partition:xnnpack_partitioner", - "//executorch/backends/fb/qnnpack:qnnpack_preprocess", - "//executorch/backends/fb/qnnpack/partition:qnnpack_partitioner", ] + get_all_cpu_backend_targets() diff --git a/exir/_serialize/TARGETS b/exir/_serialize/TARGETS index 83a2d4957ce..1b8b76b7835 100644 --- a/exir/_serialize/TARGETS +++ b/exir/_serialize/TARGETS @@ -10,7 +10,6 @@ runtime.cxx_python_extension( "bindings.cpp", ], visibility = [ - "//executorch/backends/fb/qnnpack/...", "//executorch/backends/vulkan/...", "//executorch/backends/xnnpack/...", "//executorch/devtools/bundled_program/...", diff --git a/exir/backend/test/demos/TARGETS b/exir/backend/test/demos/TARGETS index f18d57ab1c7..d3cc5d62710 100644 --- a/exir/backend/test/demos/TARGETS +++ b/exir/backend/test/demos/TARGETS @@ -1,30 +1,5 @@ load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest") -python_unittest( - name = "test_xnnpack_qnnpack", - srcs = [ - "test_xnnpack_qnnpack.py", - ], - preload_deps = [ - "//executorch/kernels/portable:custom_ops_generated_lib", - "//executorch/kernels/quantized:custom_ops_generated_lib", - ], - deps = [ - "//caffe2:torch", - "//executorch/backends/fb/qnnpack:qnnpack_backend", - "//executorch/backends/fb/qnnpack:qnnpack_preprocess", - "//executorch/backends/fb/qnnpack/partition:qnnpack_partitioner", - "//executorch/backends/xnnpack:xnnpack_backend", - "//executorch/backends/xnnpack:xnnpack_preprocess", - "//executorch/backends/xnnpack/partition:xnnpack_partitioner", - "//executorch/exir:lib", - "//executorch/exir/backend:backend_api", - "//executorch/exir/passes:spec_prop_pass", - "//executorch/extension/pybindings:portable_lib", # @manual - "//executorch/extension/pytree:pylib", - ], -) - python_unittest( name = "test_delegate_aten_mode", srcs = [ diff --git a/exir/backend/test/demos/test_xnnpack_qnnpack.py b/exir/backend/test/demos/test_xnnpack_qnnpack.py deleted file mode 100644 index 7600988e19d..00000000000 --- a/exir/backend/test/demos/test_xnnpack_qnnpack.py +++ /dev/null @@ -1,190 +0,0 @@ -# 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. - -import tempfile -import unittest - -from typing import Tuple - -import executorch.exir as exir - -import torch -from executorch.backends.fb.qnnpack.partition.qnnpack_partitioner import ( - QnnpackPartitioner, -) -from executorch.backends.fb.qnnpack.qnnpack_preprocess import QnnpackBackend -from executorch.backends.xnnpack.partition.xnnpack_partitioner import ( - XnnpackFloatingPointPartitioner, -) - -# import the xnnpack backend implementation -from executorch.backends.xnnpack.xnnpack_preprocess import XnnpackBackend - -from executorch.exir import ( - CaptureConfig, - EdgeCompileConfig, - EdgeProgramManager, - to_edge_transform_and_lower, -) - -from executorch.exir.backend.backend_api import to_backend, validation_disabled -from executorch.exir.passes.spec_prop_pass import SpecPropPass - -from executorch.extension.pybindings.portable_lib import ( # @manual - _load_for_executorch_from_buffer, -) -from executorch.extension.pytree import tree_flatten -from torch.ao.quantization.backend_config.executorch import ( - get_executorch_backend_config, -) -from torch.ao.quantization.observer import ( - default_dynamic_quant_observer, - default_per_channel_weight_observer, -) -from torch.ao.quantization.qconfig_mapping import QConfig, QConfigMapping -from torch.ao.quantization.quantize_fx import ( - _convert_to_reference_decomposed_fx, - prepare_fx, -) - - -class TestXnnQnnBackends(unittest.TestCase): - def test_add_xnnpack_and_dqlinear_qnn(self): - qconfig_mapping = QConfigMapping().set_object_type( - torch.nn.Linear, - QConfig( - activation=default_dynamic_quant_observer, - weight=default_per_channel_weight_observer, - ), - ) - in_size = 1 - in_features = 3 - out_features = 4 - - class LinearAndAdd(torch.nn.Module): - def __init__(self): - super().__init__() - self.linear = torch.nn.Linear(in_features, out_features) - - def forward(self, x, y): - return self.linear(x) + y - - linear_and_add_mod = LinearAndAdd() - - example_inputs = ( - torch.ones(in_size, in_features, dtype=torch.float), - torch.ones(in_size, out_features, dtype=torch.float), - ) - - prepared_mod = prepare_fx( - linear_and_add_mod, - qconfig_mapping, - example_inputs, - backend_config=get_executorch_backend_config(), - ) - - converted_mod: torch.fx.GraphModule = _convert_to_reference_decomposed_fx( - prepared_mod - ) - - # Step 2: EXIR capturing - capture_config = CaptureConfig(enable_dynamic_shape=False) - captured_mod = exir.capture( - converted_mod, example_inputs, config=capture_config - ).to_edge( - exir.EdgeCompileConfig( - _check_ir_validity=False, - ) - ) - - # Step 3.1: Lower dynamic quant linear to qnnpack - with validation_disabled(): - module_with_qnnpack_delegate = captured_mod - module_with_qnnpack_delegate.exported_program = to_backend( - captured_mod.exported_program, QnnpackPartitioner() - ) - - # Step 3.2: Lower add to xnnpack - with validation_disabled(): - module_with_xnn_and_qnn = module_with_qnnpack_delegate - module_with_xnn_and_qnn.exported_program = to_backend( - module_with_qnnpack_delegate.exported_program, - XnnpackFloatingPointPartitioner(), - ) - - program_with_delegates = module_with_xnn_and_qnn.to_executorch( - exir.ExecutorchBackendConfig(passes=[SpecPropPass()]), - ) - # The first delegate backend is Qnnpack - self.assertEqual( - program_with_delegates.program.execution_plan[0].delegates[0].id, - QnnpackBackend.__name__, - ) - # The second delegate backend is Xnnpack - self.assertEqual( - program_with_delegates.program.execution_plan[0].delegates[1].id, - XnnpackBackend.__name__, - ) - - executorch_module = _load_for_executorch_from_buffer( - program_with_delegates.buffer - ) - inputs_flattened, _ = tree_flatten(example_inputs) - - model_output = executorch_module.run_method("forward", tuple(inputs_flattened)) - ref_output = captured_mod(*example_inputs) - - # Compare the result from executor and eager mode direclty - self.assertTrue( - torch.allclose(model_output[0], ref_output, atol=1e-03, rtol=1e-03) - ) - - def test_serde(self): - # The module with blank_logprobs() function - class BlankLogProbsModule(torch.nn.Module): - def __init__(self) -> None: - super().__init__() - self.linear = torch.nn.Linear(768, 1) - self.log_sigmoid = torch.nn.LogSigmoid() - - def forward(self, joint_encodings: torch.Tensor) -> torch.Tensor: - tanh_out = torch.tanh(joint_encodings) - linear_out = self.linear(tanh_out) - blank_output = self.log_sigmoid(linear_out) - return blank_output - - def get_blank_logprobs_inputs_fn() -> Tuple[torch.Tensor, ...]: - """ - Get the input to the blank_logprobs() and nonblank_logprobs() functions. - """ - return (torch.randn(1, 1, 1, 768),) - - model = BlankLogProbsModule() - # Get the inputs for the logprobs function - logprobs_fake_inputs = get_blank_logprobs_inputs_fn() - - # Export and partition - aten_prog = torch.export.export(model, logprobs_fake_inputs, strict=True) - partitioned_prog: EdgeProgramManager = to_edge_transform_and_lower( - aten_prog, - partitioner=[XnnpackFloatingPointPartitioner()], - compile_config=EdgeCompileConfig( - _check_ir_validity=False, - _use_edge_ops=True, - ), - ) - - with tempfile.NamedTemporaryFile(suffix=".pt2") as f: - exir.save(partitioned_prog.exported_program(), f.name) - f.seek(0) - loaded_model = exir.load(f.name) - - self.assertTrue( - torch.allclose( - model(*logprobs_fake_inputs), - loaded_model.module()(*logprobs_fake_inputs), - ) - ) diff --git a/runtime/core/exec_aten/testing_util/targets.bzl b/runtime/core/exec_aten/testing_util/targets.bzl index 6198a09c2cb..e5ebdc8788a 100644 --- a/runtime/core/exec_aten/testing_util/targets.bzl +++ b/runtime/core/exec_aten/testing_util/targets.bzl @@ -33,7 +33,6 @@ def define_common_targets(): "//executorch/kernels/fb/custom_ops/...", "//executorch/runtime/core/test/...", "//executorch/test/...", - "//executorch/backends/fb/qnnpack/test/...", "//executorch/extension/kernel_util/test/...", "@EXECUTORCH_CLIENTS", ],