diff --git a/.ci/scripts/gather_test_models.py b/.ci/scripts/gather_test_models.py index 0f193b6db9b..91f2369ad33 100644 --- a/.ci/scripts/gather_test_models.py +++ b/.ci/scripts/gather_test_models.py @@ -9,7 +9,8 @@ import os from typing import Any -from examples.models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS +from examples.models import MODEL_NAME_TO_MODEL +from examples.recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS BUILD_TOOLS = [ "buck2", diff --git a/examples/backend/targets.bzl b/examples/backend/targets.bzl index a6662ea9aa7..62682cdaaee 100644 --- a/examples/backend/targets.bzl +++ b/examples/backend/targets.bzl @@ -22,7 +22,7 @@ def define_common_targets(): ], deps = [ "//executorch/backends/xnnpack/partition:xnnpack_partitioner", - "//executorch/examples/models:models", + "//executorch/examples/recipes/xnnpack_optimization:models", "//executorch/examples/quantization:quant_utils", "//executorch/exir:lib", "//executorch/exir/backend:backend_api", diff --git a/examples/backend/xnnpack_examples.py b/examples/backend/xnnpack_examples.py index 1f0f3edcee3..40e9cb20255 100644 --- a/examples/backend/xnnpack_examples.py +++ b/examples/backend/xnnpack_examples.py @@ -16,8 +16,9 @@ ) from executorch.exir.backend.backend_api import to_backend -from ..models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS +from ..models import MODEL_NAME_TO_MODEL from ..quantization.utils import quantize +from ..recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) diff --git a/examples/models/__init__.py b/examples/models/__init__.py index 5e3cff0eba2..77e2b4f46d7 100644 --- a/examples/models/__init__.py +++ b/examples/models/__init__.py @@ -4,6 +4,6 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -from .models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS +from .models import MODEL_NAME_TO_MODEL -__all__ = [MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS] +__all__ = [MODEL_NAME_TO_MODEL] diff --git a/examples/models/models.py b/examples/models/models.py index e76b98a5948..6e13c4df75c 100644 --- a/examples/models/models.py +++ b/examples/models/models.py @@ -142,17 +142,3 @@ def gen_resnet50_model_and_inputs() -> Tuple[torch.nn.Module, Any]: "resnet18": gen_resnet18_model_and_inputs, "resnet50": gen_resnet50_model_and_inputs, } - - -@dataclass -class OptimizationOptions(object): - quantization: bool - xnnpack_delegation: bool - - -MODEL_NAME_TO_OPTIONS = { - "linear": OptimizationOptions(True, True), - "add": OptimizationOptions(True, True), - "add_mul": OptimizationOptions(True, True), - "mv2": OptimizationOptions(True, True), -} diff --git a/examples/quantization/example.py b/examples/quantization/example.py index 4ee1dc9495b..6210ee268dc 100644 --- a/examples/quantization/example.py +++ b/examples/quantization/example.py @@ -26,9 +26,8 @@ ) from ..export.export_example import export_to_pte - -from ..models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS - +from ..models import MODEL_NAME_TO_MODEL +from ..recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS from .utils import quantize diff --git a/examples/recipes/xnnpack_optimization/TARGETS b/examples/recipes/xnnpack_optimization/TARGETS new file mode 100644 index 00000000000..8b25df013bf --- /dev/null +++ b/examples/recipes/xnnpack_optimization/TARGETS @@ -0,0 +1,12 @@ +load("@fbcode_macros//build_defs:python_library.bzl", "python_library") + +python_library( + name = "models", + srcs = [ + "__init__.py", + "models.py", + ], + deps = [ + "//executorch/examples/models:models", # @manual + ], +) diff --git a/examples/recipes/xnnpack_optimization/__init__.py b/examples/recipes/xnnpack_optimization/__init__.py new file mode 100644 index 00000000000..95a9180bd55 --- /dev/null +++ b/examples/recipes/xnnpack_optimization/__init__.py @@ -0,0 +1,9 @@ +# 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 .models import MODEL_NAME_TO_OPTIONS + +__all__ = [MODEL_NAME_TO_OPTIONS] diff --git a/examples/recipes/xnnpack_optimization/models.py b/examples/recipes/xnnpack_optimization/models.py new file mode 100644 index 00000000000..797e1eb956c --- /dev/null +++ b/examples/recipes/xnnpack_optimization/models.py @@ -0,0 +1,21 @@ +# 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 dataclasses import dataclass + + +@dataclass +class OptimizationOptions(object): + quantization: bool + xnnpack_delegation: bool + + +MODEL_NAME_TO_OPTIONS = { + "linear": OptimizationOptions(True, True), + "add": OptimizationOptions(True, True), + "add_mul": OptimizationOptions(True, True), + "mv2": OptimizationOptions(True, True), +}