forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bugfix][XPU] Fix xpu tp by introducing XpuCommunicator (vllm-project…
…#10144) Signed-off-by: yan ma <yan.ma@intel.com>
- Loading branch information
Showing
2 changed files
with
65 additions
and
22 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,47 @@ | ||
import torch | ||
import torch.distributed as dist | ||
from torch.distributed import ProcessGroup | ||
|
||
from vllm.platforms import current_platform | ||
|
||
|
||
class XpuCommunicator: | ||
|
||
def __init__(self, group: ProcessGroup): | ||
if not current_platform.is_xpu(): | ||
self.disabled = True | ||
return | ||
self.disabled = False | ||
self.group = group | ||
self.world_size = dist.get_world_size(self.group) | ||
|
||
def all_reduce(self, x: torch.Tensor) -> torch.Tensor: | ||
dist.all_reduce(x, group=self.group) | ||
return x | ||
|
||
def gather(self, | ||
input_: torch.Tensor, | ||
rank_in_group: int, | ||
dst: int = 0, | ||
dim: int = -1): | ||
# For xpu path, gather doesn't work properly together with ray | ||
# cluster so we use all_gather instead for now. | ||
input_size = input_.size() | ||
# Allocate output tensor. | ||
output_tensor = torch.empty((self.world_size, ) + input_size, | ||
dtype=input_.dtype, | ||
device=input_.device) | ||
# All-gather. | ||
torch.distributed.all_gather_into_tensor(output_tensor, | ||
input_, | ||
group=self.group) | ||
if rank_in_group == dst: | ||
# Reshape | ||
output_tensor = output_tensor.movedim(0, dim) | ||
output_tensor = output_tensor.reshape(input_size[:dim] + | ||
(self.world_size * | ||
input_size[dim], ) + | ||
input_size[dim + 1:]) | ||
else: | ||
output_tensor = None | ||
return output_tensor |
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