Skip to content

Commit 6f491b5

Browse files
Update on "[Executorch][target recipes] Add target based recipes for lowering models to a target device"
This diff introduces multi backend/ target based recipes to lower a model with very less code. Target recipes provide pre-configured backend recipes to use them and retarget if needed. See RFC: #13732 ## Usage ``` from executorch.export import export from executorch.export.target_recipes import get_ios_recipe # CoreML + XNNPACK (FP32) recipe = get_ios_recipe() # default = "ios-arm64-coreml-fp16" session = export(model, recipe, example_inputs) session.save_pte_file("model.pte") ``` ## Advanced usage to combine specific recipes of one or two or backends one can directly use `ExportRecipe.combine_recipes()` to combine specific backend recipes. ``` recipe1 = ExportRecipe.get_recipe(CoreMLRecipeType.FP32) recipe2 = ExportRecipe.get_recipe(XNNPackRecipeType.FP32) combined_recipe = ExportRecipe.combine( [recipe1, recipe2], recipe_name="multi_backend_coreml_xnnpack_fp32" ) session = export(model, combined_recipe, example_inputs) ``` Additional changes: 1. Relaxed kwarg validation in the backend providers to just ignore them instead of erroring out. Fixes: #13732 Differential Revision: [D81297451](https://our.internmc.facebook.com/intern/diff/D81297451/) [ghstack-poisoned]
2 parents bf39e66 + 048e6d2 commit 6f491b5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

export/tests/TARGETS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ runtime.python_test(
4141
"//executorch/export:lib",
4242
"//executorch/export:target_recipes",
4343
"//executorch/runtime:runtime",
44+
"//executorch/backends/xnnpack/recipes:xnnpack_recipes",
45+
"//executorch/backends/apple/coreml:coreml_recipes",
4446
]
4547
)

export/tests/test_target_recipes.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,28 @@
1010
import unittest
1111

1212
import torch
13-
from executorch.export import export
13+
from executorch.backends.apple.coreml.recipes import CoreMLRecipeProvider # pyre-ignore
14+
from executorch.backends.xnnpack.recipes.xnnpack_recipe_provider import (
15+
XNNPACKRecipeProvider,
16+
)
17+
from executorch.export import export, recipe_registry
1418
from executorch.export.target_recipes import get_ios_recipe
1519
from executorch.runtime import Runtime
1620

1721

1822
class TestTargetRecipes(unittest.TestCase):
1923
"""Test target recipes."""
2024

25+
def setUp(self) -> None:
26+
torch._dynamo.reset()
27+
super().setUp()
28+
recipe_registry.register_backend_recipe_provider(XNNPACKRecipeProvider())
29+
# pyre-ignore
30+
recipe_registry.register_backend_recipe_provider(CoreMLRecipeProvider())
31+
32+
def tearDown(self) -> None:
33+
super().tearDown()
34+
2135
def test_ios_fp32_recipe_with_xnnpack_fallback(self) -> None:
2236
# Linear ops skipped by coreml but handled by xnnpack
2337
class Model(torch.nn.Module):
@@ -93,7 +107,7 @@ def forward(self, x, y):
93107
et_output = session.run_method("forward", example_inputs[0])
94108
logging.info(f"et output {et_output}")
95109

96-
def test_ios_int8_recipe(self) -> None:
110+
def test_ios_quant_recipes(self) -> None:
97111
class Model(torch.nn.Module):
98112
def __init__(self):
99113
super().__init__()

0 commit comments

Comments
 (0)