-
Notifications
You must be signed in to change notification settings - Fork 9
Move autoparallel to use leaner export API #181
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 all commits
Commits
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 |
|---|---|---|
|
|
@@ -8,9 +8,10 @@ | |
| import warnings | ||
| from contextlib import ExitStack, contextmanager | ||
| from types import MethodType | ||
| from typing import Optional, Union | ||
| from typing import Any, Optional, Tuple, Union | ||
|
|
||
| import torch | ||
| from torch._dynamo.functional_export import _dynamo_graph_capture_for_export | ||
| from torch._functorch.aot_autograd import ( | ||
| aot_compile_joint_with_descriptors, | ||
| aot_export_joint_with_descriptors, | ||
|
|
@@ -22,6 +23,7 @@ | |
| from torch._subclasses import FakeTensorMode | ||
| from torch.distributed.fsdp import MixedPrecisionPolicy | ||
| from torch.distributed.tensor import DeviceMesh | ||
| from torch.export._trace import _restore_state_dict | ||
| from torch.export._unlift import _assign_attr | ||
| from torch.export.unflatten import _AttrKind | ||
|
|
||
|
|
@@ -163,6 +165,21 @@ def enable_local_map_wrapping(): | |
| yield | ||
|
|
||
|
|
||
| def _export(model: torch.nn.Module, inputs: Tuple[Any]) -> torch.nn.Module: | ||
| """ | ||
| Thin wrapper around graph capture output that restores the | ||
| original calling convention and attribute fqn. TODO: | ||
| 1) Use bytecode for calling convention instead of pytree for more | ||
| seamless UX. | ||
| 2) Attach guards | ||
| 3) Be more careful about tensor constants names. | ||
| """ | ||
| with torch._dynamo.config.patch(install_free_tensors=True): | ||
| gm = _dynamo_graph_capture_for_export(model)(*inputs) | ||
| _restore_state_dict(model, gm) | ||
|
Contributor
Author
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. autoparallel wants the original fqn to be stored. |
||
| return gm | ||
|
|
||
|
|
||
| class AutoParallel: | ||
| """ | ||
| Args: | ||
|
|
@@ -279,13 +296,10 @@ def build_model_graph(self): | |
| with set_dtype_cast( | ||
| True | ||
| ), enable_local_map_wrapping(), torch._dynamo.utils._disable_saved_tensors_hooks_during_tracing(): | ||
| with torch._dynamo.config.patch( | ||
| install_free_tensors=True | ||
| ), monkey_patch_export_verifier(): | ||
| ep = torch.export.export(self.model, inputs, strict=True) | ||
| torch_ir_with_fqn = _export(self.model, inputs) | ||
| self.joint_with_descriptors = aot_export_joint_with_descriptors( | ||
| self.stack, | ||
| ep.module(), | ||
| torch_ir_with_fqn, | ||
| inputs, | ||
| decompositions=decomp_table, | ||
| fw_compiler=self.compiler_fn, | ||
|
|
||
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.
This function is used for new strict export and it adds implicitly sets up right calling convention using pytree. We might need to change this a bit to rely on bytecode instead.
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.
cc: @SherlockNoMad