Commit 2866772
committed
[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- export
- tests
9 files changed
+1174
-911
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
39 | 62 | | |
40 | 63 | | |
41 | 64 | | |
| |||
48 | 71 | | |
49 | 72 | | |
50 | 73 | | |
| 74 | + | |
51 | 75 | | |
52 | | - | |
| 76 | + | |
| 77 | + | |
53 | 78 | | |
54 | 79 | | |
55 | 80 | | |
| |||
78 | 103 | | |
79 | 104 | | |
80 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
0 commit comments