-
Notifications
You must be signed in to change notification settings - Fork 623
[compiler toolkit] Port joint_ac_pass from simplefsdp #2051
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
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
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
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
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 |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| import torch | ||
| from torch._inductor.fx_passes.overlap_scheduling import schedule_overlap_bucketing | ||
| from torch.fx.passes.regional_inductor import regional_inductor | ||
| from torchtitan.experiments.simple_fsdp.reshard_after_forward import ( | ||
| annotate_fsdp_all_gather, | ||
| ) | ||
|
|
||
|
|
||
| def autobucketing_reordering_pass( | ||
|
|
@@ -39,8 +42,35 @@ def regional_inductor_pass( | |
| return regional_inductor(gm, example_inputs) | ||
|
|
||
|
|
||
| def validate_flex_attn_annotation_pass( | ||
| gm: torch.fx.GraphModule, | ||
| ) -> torch.fx.GraphModule: | ||
| """Verify user annotations show up in the graph.""" | ||
| for node in gm.graph.nodes: | ||
| if node.target in { | ||
| torch.ops.higher_order.flex_attention, | ||
| torch.ops.higher_order.flex_attention_backward, | ||
| }: | ||
| assert "compile_with_inductor" in node.meta.get("custom", {}) | ||
| return gm | ||
|
|
||
|
|
||
| # Apply activation checkpointing on joint graph before partitioner | ||
|
Contributor
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. We use the "joint_ac_pass" here to implement FSDP's |
||
| def fsdp_reshard_after_fwd_pass( | ||
| gm: torch.fx.GraphModule, reshard_after_forward: bool | ||
| ) -> torch.fx.GraphModule: | ||
| # this pass implements simplefsdp's fsdp_reshard_after_forward behavior | ||
| # when fsdp_reshard_after_forward set to True, it will annotate simple_fsdp AG | ||
| # to CheckpointPolicy.MUST_RECOMPUTE. | ||
| # when fsdp_reshard_after_forward set to False, it will annotate simple_fsdp AG | ||
| # to CheckpointPolicy.MUST_SAVE. | ||
| gm = annotate_fsdp_all_gather(gm, reshard_after_forward) | ||
| gm.recompile() | ||
| return gm | ||
|
|
||
|
|
||
| # Registry mapping pass names to pass functions | ||
| AVAILABLE_PASSES = { | ||
| AVAILABLE_COMPILER_PASSES = { | ||
| "autobucketing_reordering": autobucketing_reordering_pass, | ||
| "regional_inductor": regional_inductor_pass, | ||
| } | ||
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.
just out of curiosity: do we care about the order of passes applied in joint_custom_passes?
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.
we probably care the order of passes when later we have more joint_custom_passes.
Right now the
validate_flex_attn_annotation_passis just validating if flex attention nodes are annotated and will error out if it fails. So I put it at first.