-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[TPU] Support collective communications in XLA devices #6813
Merged
+70
−2
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
af3a259
[TPU] Support collective communications in XLA devices
WoosukKwon 0f2abea
Use current_platform
WoosukKwon 8ebea7e
is_xla -> is_tpu
WoosukKwon 782b182
Define TPU communicator
WoosukKwon 8087227
Fix
WoosukKwon f04e179
Address comments
WoosukKwon 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 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import torch | ||
import torch.distributed as dist | ||
from torch.distributed import ProcessGroup | ||
|
||
from vllm.platforms import current_platform | ||
|
||
if current_platform.is_tpu(): | ||
import torch_xla.core.xla_model as xm | ||
from torch_xla._internal import pjrt | ||
|
||
|
||
class TpuCommunicator: | ||
|
||
def __init__(self, group: ProcessGroup): | ||
if not current_platform.is_tpu(): | ||
self.disabled = True | ||
return | ||
self.disabled = False | ||
|
||
local_rank = dist.get_rank(group) | ||
world_size = dist.get_world_size(group) | ||
pjrt.initialize_multiprocess(local_rank, world_size) | ||
xm._init_world_size_ordinal() | ||
|
||
def all_reduce(self, x: torch.Tensor) -> torch.Tensor: | ||
return xm.all_reduce(xm.REDUCE_SUM, x) | ||
|
||
def all_gather(self, x: torch.Tensor, dim: int = -1) -> torch.Tensor: | ||
assert dim == -1, "TPUs only support dim=-1 for all-gather." | ||
return xm.all_gather(x, dim=dim) |
This file contains 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 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 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
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.
you can get rank and world size from the
group
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.
Thanks for letting me know! Updated the PR. PTAL.
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.
do you need to remove the code inside tpu worker? I don't know if pjrt and xm support initialization for multiple times.
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.
@youkaichao Good point. That's actually updated in #5871. In the current main branch, there's no code initializing the XLA's distributed runtime.