Skip to content

Commit ec4d4e8

Browse files
guangy10facebook-github-bot
authored andcommitted
Create an initital recipe for xnnpack optimization (#145)
Summary: Pull Request resolved: #145 This is just a very initial attempt to define composable recipes for our demos. **The goal for this diff is just to move xnnpack specific stuff out from the `examples/models` to `examples/recipes/xnnpack_optimization`**. In follow-up diffs, we will continue moving pieces from `examples/backend` to create a complete recipe to demonstrate xnnpack optimization e2e. Reviewed By: kirklandsign Differential Revision: D48704007 fbshipit-source-id: ccda52a4a7b742a8dec16dc92413803f5e8417bb
1 parent 0f6bae0 commit ec4d4e8

File tree

9 files changed

+51
-22
lines changed

9 files changed

+51
-22
lines changed

.ci/scripts/gather_test_models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import os
1010
from typing import Any
1111

12-
from examples.models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS
12+
from examples.models import MODEL_NAME_TO_MODEL
13+
from examples.recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS
1314

1415
BUILD_TOOLS = [
1516
"buck2",

examples/backend/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def define_common_targets():
2222
],
2323
deps = [
2424
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
25-
"//executorch/examples/models:models",
25+
"//executorch/examples/recipes/xnnpack_optimization:models",
2626
"//executorch/examples/quantization:quant_utils",
2727
"//executorch/exir:lib",
2828
"//executorch/exir/backend:backend_api",

examples/backend/xnnpack_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
)
1717
from executorch.exir.backend.backend_api import to_backend
1818

19-
from ..models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS
19+
from ..models import MODEL_NAME_TO_MODEL
2020
from ..quantization.utils import quantize
21+
from ..recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS
2122

2223
logger = logging.getLogger(__name__)
2324
logger.setLevel(logging.INFO)

examples/models/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
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-
from .models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS
7+
from .models import MODEL_NAME_TO_MODEL
88

9-
__all__ = [MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS]
9+
__all__ = [MODEL_NAME_TO_MODEL]

examples/models/models.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,3 @@ def gen_resnet50_model_and_inputs() -> Tuple[torch.nn.Module, Any]:
142142
"resnet18": gen_resnet18_model_and_inputs,
143143
"resnet50": gen_resnet50_model_and_inputs,
144144
}
145-
146-
147-
@dataclass
148-
class OptimizationOptions(object):
149-
quantization: bool
150-
xnnpack_delegation: bool
151-
152-
153-
MODEL_NAME_TO_OPTIONS = {
154-
"linear": OptimizationOptions(True, True),
155-
"add": OptimizationOptions(True, True),
156-
"add_mul": OptimizationOptions(True, True),
157-
"mv2": OptimizationOptions(True, True),
158-
}

examples/quantization/example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
)
2727

2828
from ..export.export_example import export_to_pte
29-
30-
from ..models import MODEL_NAME_TO_MODEL, MODEL_NAME_TO_OPTIONS
31-
29+
from ..models import MODEL_NAME_TO_MODEL
30+
from ..recipes.xnnpack_optimization import MODEL_NAME_TO_OPTIONS
3231
from .utils import quantize
3332

3433

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
2+
3+
python_library(
4+
name = "models",
5+
srcs = [
6+
"__init__.py",
7+
"models.py",
8+
],
9+
deps = [
10+
"//executorch/examples/models:models", # @manual
11+
],
12+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
from .models import MODEL_NAME_TO_OPTIONS
8+
9+
__all__ = [MODEL_NAME_TO_OPTIONS]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
from dataclasses import dataclass
8+
9+
10+
@dataclass
11+
class OptimizationOptions(object):
12+
quantization: bool
13+
xnnpack_delegation: bool
14+
15+
16+
MODEL_NAME_TO_OPTIONS = {
17+
"linear": OptimizationOptions(True, True),
18+
"add": OptimizationOptions(True, True),
19+
"add_mul": OptimizationOptions(True, True),
20+
"mv2": OptimizationOptions(True, True),
21+
}

0 commit comments

Comments
 (0)