Skip to content

Commit bf39e66

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 0e17df8 + 561ee80 commit bf39e66

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

backends/xnnpack/recipes/xnnpack_recipe_types.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
class XNNPackRecipeType(RecipeType):
1313
"""XNNPACK-specific recipe types"""
1414

15-
FP32 = "fp32"
15+
FP32 = "xnnpack_fp32"
1616

1717
## PT2E-based quantization recipes
1818
# INT8 Dynamic Quantization
19-
PT2E_INT8_DYNAMIC_PER_CHANNEL = "pt2e_int8_dynamic_per_channel"
19+
PT2E_INT8_DYNAMIC_PER_CHANNEL = "xnnpack_pt2e_int8_dynamic_per_channel"
2020
# INT8 Static Quantization, needs calibration dataset
21-
PT2E_INT8_STATIC_PER_CHANNEL = "pt2e_int8_static_per_channel"
22-
PT2E_INT8_STATIC_PER_TENSOR = "pt2e_int8_static_per_tensor"
21+
PT2E_INT8_STATIC_PER_CHANNEL = "xnnpack_pt2e_int8_static_per_channel"
22+
PT2E_INT8_STATIC_PER_TENSOR = "xnnpack_pt2e_int8_static_per_tensor"
2323

2424
## TorchAO-based quantization recipes
2525
# INT8 Dynamic Activations INT4 Weight Quantization, Axis = 0
2626
TORCHAO_INT8_DYNAMIC_ACT_INT4_WEIGHT_PER_CHANNEL = (
27-
"torchao_int8da_int4w_per_channel"
27+
"xnnpack_torchao_int8da_int4w_per_channel"
2828
)
2929
# INT8 Dynamic Activations INT4 Weight Quantization, default group_size = 32
3030
# can be overriden by group_size kwarg
31-
TORCHAO_INT8_DYNAMIC_ACT_INT4_WEIGHT_PER_TENSOR = "torchao_int8da_int4w_per_tensor"
31+
TORCHAO_INT8_DYNAMIC_ACT_INT4_WEIGHT_PER_TENSOR = (
32+
"xnnpack_torchao_int8da_int4w_per_tensor"
33+
)
3234

3335
@classmethod
3436
def get_backend_name(cls) -> str:

export/recipe.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ def _combine_recipes( # noqa: C901
301301
edge_compile_config=edge_compile_config or EdgeCompileConfig(),
302302
)
303303

304+
recipe_name = recipe_name or "_".join(
305+
[r.name for r in backend_recipes if r.name is not None]
306+
)
304307
return cls(
305308
name=recipe_name,
306309
quantization_recipe=combined_quantization_recipe,

0 commit comments

Comments
 (0)