[ExecuTorch][Export][1/N] Export API pipeline re-architecture, making it composable#13055
Merged
Conversation
… 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/)
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/13055
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 51 PendingAs of commit 1c71155 with merge base 43d90e5 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #12937 by @abhinaykukkadapu ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/2/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/2/head Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/1/orig Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/2/orig @diff-train-skip-merge Co-authored-by: Abhinay Kukkadapu <abhinayk@meta.com>
Co-authored-by: Abhinay Kukkadapu <abhinayk@meta.com>
Gasoonjia
approved these changes
Aug 1, 2025
abhinaykukkadapu
approved these changes
Aug 1, 2025
agrima1304
pushed a commit
to agrima1304/executorch
that referenced
this pull request
Aug 26, 2025
… it composable (pytorch#13055) Co-authored-by: Abhinay Kukkadapu <abhinayk@meta.com> Co-authored-by: Gasoonjia <gasoonjia@meta.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #12936 by @abhinaykukkadapu
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/1/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/1/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/main
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/abhinaykukkadapu/1/orig
@diff-train-skip-merge