Skip to content

Commit 2866772

Browse files
[ExecuTorch][Export][1/N] Export API pipeline re-architecture, making it composable
Pull Request resolved: #12936 RFC: #12660 This diff introduces composable architecture for the export pipeline. Changes: 1. Introduces notion of `PipelineArtifact` which encompasses stage artifacts and run context necessary to execute a stage and the pipeline. 1. Move all stages to new file to better architect the component 1. Export api will now accept `pipeline_stages` and honors the sequence if provided otherwise fallback to default sequence: `source_transform -> quantize -> torch.export -> to_edge_transform_and_lower -> to_executorch` 1. Validate if pipeline provided is valid, error out if not. 1. Add unittests to test pipeline sequence and stages With this one can execute a partial pipeline, for example, one can just do `TORCH_EXPORT -> TO_EDGE_TRANSFORM_AND_LOWER -> TO_EXECUTORCH` Current limitation: 1. `TORCH_EXPORT` stage is mandatory to avoid someone passing incorrect input such as `ExportedProgram` instead of nn.module, this enforcement will anchor the pipeline to have expected stages to run. - This limitation will be removed if we choose to add the support to take `ExportedProgram` as input. ## Default usage ``` recipe = ExportRecipe.get_recipe( XNNPackRecipeType.INT8_DYNAMIC_ACT_INT4_WEIGHT_PER_CHANNEL, group_size=32) export(eager_model, example_inputs, dynamic_shapes, recipe) ``` All default steps are run, `SOURCE_TRANSFORM -> QUANTIZE -> TORCH_EXPORT -> TO_EDGE_TRANSFORM_AND_LOWER -> TO_EXECUTORCH` ## Custom pipeline through recipe ``` recipe = ExportRecipe.get_recipe( XNNPackRecipeType.INT8_DYNAMIC_ACT_INT4_WEIGHT_PER_CHANNEL, group_size=32) # override stages (just for demonstration, usually recipe carries the stages that it wants to run) recipe.pipeline_stages = [ StageType.SOURCE_TRANSFORM, StageType.TORCH_EXPORT, StageType.TO_EDGE_TRANSFORM_AND_LOWER, StageType.TO_EXECUTORCH, ] export(eager_model, example_inputs, dynamic_shapes, recipe) ``` Only steps passed in are run. Note: 1. this diff is large because I moved stages to separate file and added bunch of unittests but core functionality that is added can be reviewed in `export.py` file. CC: @digantdesai 2. Export component was supposed to mimic stages design in tester and now it is. Fixes: #12928 ghstack-source-id: 300019404 @exported-using-ghexport Differential Revision: [D79120574](https://our.internmc.facebook.com/intern/diff/D79120574/)
1 parent f497f7f commit 2866772

File tree

9 files changed

+1174
-911
lines changed

9 files changed

+1174
-911
lines changed

export/TARGETS

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ runtime.python_library(
1515
"//caffe2:torch",
1616
"//executorch/exir/backend:backend_api",
1717
"//executorch/exir:pass_manager",
18-
"//executorch/devtools/backend_debug:delegation_info",
1918
"//executorch/extension/export_util:export_util",
2019
]
2120
)
@@ -31,11 +30,35 @@ runtime.python_library(
3130
],
3231
deps = [
3332
":recipe",
33+
":stages",
34+
":types",
3435
"//executorch/runtime:runtime",
3536
":recipe_registry"
3637
]
3738
)
3839

40+
41+
runtime.python_library(
42+
name = "stages",
43+
srcs = [
44+
"stages.py",
45+
],
46+
visibility = [
47+
"//executorch/...",
48+
"@EXECUTORCH_CLIENTS",
49+
],
50+
deps = [
51+
":recipe",
52+
":types",
53+
"//executorch/devtools/backend_debug:delegation_info",
54+
"//executorch/exir/backend:backend_api",
55+
"//executorch/exir:pass_manager",
56+
"//caffe2:torch",
57+
"//executorch/devtools/backend_debug:delegation_info",
58+
]
59+
)
60+
61+
3962
runtime.python_library(
4063
name = "lib",
4164
srcs = [
@@ -48,8 +71,10 @@ runtime.python_library(
4871
deps = [
4972
":export",
5073
":recipe",
74+
":stages",
5175
":recipe_registry",
52-
":recipe_provider"
76+
":recipe_provider",
77+
":types",
5378
],
5479
)
5580

@@ -78,3 +103,10 @@ runtime.python_library(
78103
":recipe",
79104
]
80105
)
106+
107+
runtime.python_library(
108+
name = "types",
109+
srcs = [
110+
"types.py",
111+
],
112+
)

export/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
from .recipe import ExportRecipe, QuantizationRecipe, RecipeType
1919
from .recipe_provider import BackendRecipeProvider
2020
from .recipe_registry import recipe_registry
21-
21+
from .types import StageType
2222

2323
__all__ = [
24+
"StageType",
2425
"ExportRecipe",
2526
"QuantizationRecipe",
2627
"ExportSession",

0 commit comments

Comments
 (0)