-
Notifications
You must be signed in to change notification settings - Fork 575
[Executorch][to_backend] Introduce preprocess_multimethod #9823
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
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cfe2462
Update
mcr229 64792f1
Update
mcr229 15bb0c6
Update
mcr229 3469a7b
Update
mcr229 db5141a
Update
mcr229 1fea741
Update
mcr229 cff2f0d
Update
mcr229 adc9d34
Update
mcr229 a80d14c
Update
mcr229 73c492b
Update
mcr229 ef6b34f
Update
mcr229 13409b0
Update
mcr229 518c261
Update
mcr229 3376338
Update
mcr229 ba4293b
Update
mcr229 39fbd68
Update
mcr229 793efb5
Update
mcr229 da8579a
Update
mcr229 8e55d73
Update
mcr229 da17865
Update
mcr229 50ee3a5
Update
mcr229 4ed3e44
[ExecuTorch][to_backend] Enable to_backend API to leverage preproce…
mcr229 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,15 +50,6 @@ class BackendDetails(ABC): | |
the decorators, this interface will be static, abstract and all inheritances are | ||
enforced to implement this method. | ||
|
||
Args: | ||
edge_program: The original exported program. It will not be modified in place. | ||
compile_specs: List of values needed for compilation | ||
|
||
Returns: | ||
PreprocessResult: It wraps the following information: | ||
processed_bytes -> bytes: A compiled blob - a binary that can run the desired program in the backend. | ||
debug_handle_map (Optional[Dict[int, Tuple[int]]]): For profiling purposes, a map from the node_id in the final graph (either EXIR or the user's self-defined IR) | ||
to debug handle id attached in the original exported program. | ||
""" | ||
|
||
@staticmethod | ||
|
@@ -70,6 +61,69 @@ def preprocess( | |
edge_program: ExportedProgram, | ||
compile_specs: List[CompileSpec], | ||
) -> PreprocessResult: | ||
""" | ||
Preprocesses an edge program and returns the preprocess result fo the given backend | ||
|
||
Args: | ||
edge_program: The original exported program. It will not be modified in place. | ||
compile_specs: List of values needed for compilation | ||
|
||
Returns: | ||
PreprocessResult: It wraps the following information: | ||
processed_bytes -> bytes: A compiled blob - a binary that can run the desired | ||
program in the backend. | ||
debug_handle_map (Optional[Dict[int, Tuple[int]]]): For profiling purposes, a | ||
map from the node_id in the final graph (either EXIR or the user's self-defined | ||
IR) to debug handle id attached in the original exported program. | ||
""" | ||
# Users should return a compiled blob - a binary that can run the desired | ||
# program in the backend. | ||
pass | ||
|
||
@classmethod | ||
def preprocess_multimethod( | ||
cls, | ||
edge_programs: Dict[str, List[ExportedProgram]], | ||
compile_specs: Dict[str, List[List[CompileSpec]]], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the finest granularity which I believe cover all the use cases. For majority of the use case, we probably can support |
||
) -> 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] | ||
|
||
|
||
""" | ||
preprocess_results = {} | ||
for method_name, programs in edge_programs.items(): | ||
assert ( | ||
method_name in compile_specs | ||
), f"Error: missing compile specs for {method_name}" | ||
compile_specs_for_method = compile_specs[method_name] | ||
assert len(compile_specs_for_method) == len( | ||
programs | ||
), f"Error: method {method_name} has {len(programs)} partitions but only {len(compile_specs_for_method)}" | ||
results_for_method = [] | ||
for program, compile_spec_for_program in zip( | ||
programs, compile_specs_for_method | ||
): | ||
preprocess_result = cls.preprocess(program, compile_spec_for_program) | ||
results_for_method.append(preprocess_result) | ||
|
||
preprocess_results[method_name] = results_for_method | ||
|
||
return preprocess_results |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it will be the default method if the backend didn't implement their own preprocess multimethod, is it correct? If so, let's add some tests.