-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[cp] dispatch flex_attention to CP impl in TorchDispatchMode #151497
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
Open
XilunWu
wants to merge
21
commits into
gh/XilunWu/133/base
Choose a base branch
from
gh/XilunWu/133/head
base: gh/XilunWu/133/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+627
−109
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6bfb512
DTensor HOP dispatch
XilunWu 0e1171f
Update on "DTensor HOP dispatch"
XilunWu efc5e67
Update on "DTensor HOP dispatch"
XilunWu 4f8e9d4
Update on "DTensor HOP dispatch"
XilunWu 19ac1ce
Update on "DTensor HOP dispatch"
XilunWu 9ecc674
Update on "DTensor HOP dispatch"
XilunWu c71ff48
Update
XilunWu 2836766
Update
XilunWu 103f0ef
Update
XilunWu bdda34a
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 929f157
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 0ba9169
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 644ec19
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 048010a
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 6ad5a79
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu bced5f0
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 177f177
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 446fb80
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu ddd1ab5
Update
XilunWu 43c91ff
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 362b6e8
Update on "[cp] dispatch flex_attention to CP impl in TorchDispatchMode"
XilunWu 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,12 @@ | |
import re | ||
import weakref | ||
from collections import defaultdict | ||
from typing import Any | ||
from typing import Any, Callable | ||
|
||
import torch | ||
import torch.nn | ||
from torch._guards import detect_fake_mode | ||
from torch._higher_order_ops import flex_attention as flex_attention_hop | ||
from torch.autograd.graph import register_multi_grad_hook | ||
from torch.distributed._tools.mod_tracker import ModTracker | ||
from torch.distributed.tensor._api import DTensor | ||
|
@@ -733,3 +734,30 @@ def __torch_dispatch__(self, func, types, args=(), kwargs=None): | |
].append(operation_dict) | ||
|
||
return out | ||
|
||
|
||
# register flex_attention HOP to CommDebugMode | ||
@flex_attention_hop.py_impl(CommDebugMode) | ||
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. why one need to register a hop here? |
||
def flex_attention_comm_debug_mode( | ||
mode: CommDebugMode, | ||
query: torch.Tensor, | ||
key: torch.Tensor, | ||
value: torch.Tensor, | ||
score_mod: Callable, | ||
block_mask: tuple, | ||
scale: float, | ||
kernel_options: dict[str, Any], | ||
score_mod_other_buffers: tuple = (), | ||
mask_mod_other_buffers: tuple = (), | ||
) -> tuple[torch.Tensor, torch.Tensor]: | ||
return flex_attention_hop( | ||
query, | ||
key, | ||
value, | ||
score_mod, | ||
block_mask, | ||
scale, | ||
kernel_options, | ||
score_mod_other_buffers, | ||
mask_mod_other_buffers, | ||
) |
Oops, something went wrong.
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 think exposing a way for user to control how the mask is being partitioned is fine. But I don't think we should do it in the current way, specifically I don't think we should leak the concept of "Sharder" as it would confuse with user its relationship with the Shard placement in DTensor.