forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TPU] Support collective communications in XLA devices (vllm-project#…
- Loading branch information
1 parent
7c1b18a
commit 164bbdf
Showing
4 changed files
with
70 additions
and
2 deletions.
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