Skip to content

[ExecuTorch][to_backend] Enable to_backend API to leverage preprocess_multimethod #9824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 16, 2025

Conversation

mcr229
Copy link
Contributor

@mcr229 mcr229 commented Apr 1, 2025

Summary

We add a new to_backend api which for multi method models. Specifically, we pass in a dictionary mapping MethodName to ExportedProgram, as well as a dictionary mapping MethodName to Partitioner. We then return a dictionary mapping MethodName to the partitioned and lowered exported program.

In addition, we also provide a new preprocess API for backends to implement. This API is preprocess_multimethod. The signature of the new method is as follows:

    def preprocess_multimethod(
        cls,
        edge_programs: Dict[str, List[ExportedProgram]],
        compile_specs: Dict[str, List[List[CompileSpec]]],
    ) -> Dict[str, list[PreprocessResult]]:
        """
        Runs preprocess on all partitioned Edge Programs across multiple methods. This allows
        backends to share information across partitioned graphs. Backend can serialize shared
        data by putting the shared data into the data_store_output of the preprocess results.
        This will record the shared data used by that specific partition.

        Default implementation is running the existing preprocess implementation on all

        Args:
            edge_programs: Dictionary mapping the method name to a list of all the partitioned
                           edge_programs from that method to be lowered.
            compile_specs: Dictionary mapping the method name to a list of compile_specs. The
                           list of compile specs maps directly to the list of edge_programs for the
                           same given method name i.e. edge_program[method_name][i] --> compile_specs[method_name][i]

        Returns:
            Dictionary mapping the method name to a list of PreprocessResults. The list of
            PreprocessResults maps directly to the list of edge_programs for the same given
            method name. i.e. edge_program[method_name][i] --> result[method_name][i]
        """

This new API enableds backends to preprocess all partitions/methods at once. This way, while processing blobs, they can identify shared components between preprocessed blobs. Shared components can be serialized within the NamedDataStore.

The key change in backend infra, is that when partitioning, we now have to identify all the partitioned graphs to be lowered at once, and pass them to preprocess_multimethod at once. Previously, as we found lowerable partitions, we preprocessed and embedded them into the graph.

Testing

python -m unittest exir.backend.test.test_to_backend_multi_method

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Apr 1, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9824

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit f23ecf3 with merge base ae2d822 (image):
💚 Looks good so far! There are no failures yet. 💚

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

mcr229 added a commit that referenced this pull request Apr 1, 2025
…_all

ghstack-source-id: f0f8445
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
@facebook-github-bot facebook-github-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 Apr 1, 2025
@mcr229 mcr229 requested review from digantdesai and cccclai April 1, 2025 23:48
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 1, 2025
…_all

ghstack-source-id: 8c4373f
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
@mcr229 mcr229 changed the title [ExecuTorch][to_backend] Enable to_backend API to leverage preprocess_all [ExecuTorch][to_backend] Enable to_backend API to leverage preprocess_multimethod Apr 2, 2025
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 2, 2025
…_all

ghstack-source-id: 85ee576
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 3, 2025
…_all

ghstack-source-id: 25d6d5e
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 5, 2025
…_all

ghstack-source-id: 49510c5
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 8, 2025
…_all

ghstack-source-id: 1661eb0
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 8, 2025
…_all

ghstack-source-id: 0ce6cc2
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 8, 2025
…_all

ghstack-source-id: faf11a2
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 9, 2025
…_all

ghstack-source-id: d8cce96
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
@mcr229
Copy link
Contributor Author

mcr229 commented Apr 10, 2025

 pytest devtools/inspector/tests/inspector_utils_test.py::TestInspectorUtils::test_compare_results_uint8 
============================================================================================================================================================ test session starts ============================================================================================================================================================
platform darwin -- Python 3.11.4, pytest-8.3.5, pluggy-1.5.0
rootdir: /Users/maxren/Desktop/oss/executorch
configfile: pytest.ini
plugins: cov-4.1.0, xdist-3.3.1, rerunfailures-15.0, hypothesis-6.84.2
collected 1 item                                                                                                                                                                                                                                                                                                                            

devtools/inspector/tests/inspector_utils_test.py .                                                                                                                                                                                                                                                                                    [100%]

============================================================================================================================================================ 1 passed in 15.11s =============================================================================================================================================================

for the failing test, let me rebase and resubmit

[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 10, 2025
…_all

ghstack-source-id: e982c88
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
Copy link
Contributor

@cccclai cccclai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you for being patient and all the effort!

[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 15, 2025
…_all

ghstack-source-id: 5ed4df7
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
[ghstack-poisoned]
mcr229 added a commit that referenced this pull request Apr 16, 2025
…_all

ghstack-source-id: 13291a9
ghstack-comment-id: 2770905773
Pull Request resolved: #9824
@mcr229 mcr229 merged commit 4ed3e44 into gh/mcr229/21/head Apr 16, 2025
84 of 158 checks passed
@mcr229 mcr229 deleted the gh/mcr229/22/head branch April 16, 2025 16:10
mcr229 added a commit that referenced this pull request Apr 16, 2025
### summary

We introduce a new preprocess_multimethod. This takes the place of
preprocess all in the following discussion:
#8230

This is a class method so that we can allow the default implementation
to leverage the static preprocess method. The default implementation
just applies preprocess on all the exported programs given.

### Testing
Testing done in follow up PR 
#9824
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
### summary

We introduce a new preprocess_multimethod. This takes the place of
preprocess all in the following discussion:
pytorch#8230

This is a class method so that we can allow the default implementation
to leverage the static preprocess method. The default implementation
just applies preprocess on all the exported programs given.

### Testing
Testing done in follow up PR 
pytorch#9824
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