Skip to content

Conversation

pytorchbot
Copy link
Collaborator

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

… 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/)
Copy link

pytorch-bot bot commented Aug 1, 2025

🔗 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 Pending

As of commit 1c71155 with merge base 43d90e5 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 1, 2025
Copy link

github-actions bot commented Aug 1, 2025

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

pytorchbot and others added 3 commits July 31, 2025 22:38
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>
@abhinaykukkadapu abhinaykukkadapu merged commit 4197fc1 into main Aug 1, 2025
101 checks passed
@abhinaykukkadapu abhinaykukkadapu deleted the gh/abhinaykukkadapu/1/orig branch August 1, 2025 06:32
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants