[XPU] Enable XPU eplb (#44987)

Signed-off-by: mayuyuace <qiming1.zhang@intel.com>
Signed-off-by: Qiming Zhang <qiming1.zhang@intel.com>
This commit is contained in:
Qiming Zhang
2026-09-17 13:19:13 +08:00
committed by GitHub
parent 2743dc4f92
commit e6b1a5e5e3
16 changed files with 267 additions and 109 deletions
+78 -17
View File
@@ -22,6 +22,7 @@ from vllm.distributed.device_communicators.pynccl import PyNcclCommunicator
from vllm.distributed.device_communicators.pynccl_wrapper import (
ncclDataTypeEnum,
)
from vllm.distributed.eplb.eplb_utils import device_stream
from vllm.distributed.parallel_state import (
GroupCoordinator,
get_pp_group,
@@ -87,8 +88,8 @@ class EplbCommunicator(ABC):
communication buffers."""
return True
def set_stream(self, cuda_stream: torch.cuda.Stream | None) -> None:
self._cuda_stream = cuda_stream
def set_stream(self, stream: torch.Stream | None) -> None:
self._stream = stream
def _log_initialized(self) -> None:
if is_local_first_rank():
@@ -101,10 +102,10 @@ class TorchDistNcclEplbCommunicator(EplbCommunicator):
def __init__(
self,
ep_group: ProcessGroup,
cuda_stream: torch.cuda.Stream | None = None,
stream: torch.Stream | None = None,
) -> None:
self._ep_group = ep_group
self._cuda_stream = cuda_stream
self._stream = stream
self._p2p_ops: list[P2POp] = []
self._log_initialized()
@@ -144,7 +145,7 @@ class TorchDistNcclEplbCommunicator(EplbCommunicator):
if not self._p2p_ops:
return
try:
with torch.cuda.stream(self._cuda_stream):
with device_stream(self._stream):
reqs = batch_isend_irecv(self._p2p_ops)
for req in reqs:
req.wait()
@@ -158,10 +159,10 @@ class TorchDistGlooStagedEplbCommunicator(EplbCommunicator):
def __init__(
self,
cpu_group: ProcessGroup,
cuda_stream: torch.cuda.Stream | None = None,
stream: torch.Stream | None = None,
) -> None:
self._cpu_group = cpu_group
self._cuda_stream = cuda_stream
self._stream = stream
self._ops: list[tuple[str, torch.Tensor, int]] = []
self._log_initialized()
@@ -217,7 +218,7 @@ class TorchDistGlooStagedEplbCommunicator(EplbCommunicator):
recv_staging.append((tensor, cpu_tensor))
try:
with torch.cuda.stream(self._cuda_stream):
with device_stream(self._stream):
build_ops()
finally:
self._ops.clear()
@@ -225,10 +226,10 @@ class TorchDistGlooStagedEplbCommunicator(EplbCommunicator):
# Wait for all D2H copies to finish
# before issuing gloo batch_isend_irecv operations.
with gpu_sync_allowed():
if self._cuda_stream is not None:
self._cuda_stream.synchronize()
if self._stream is not None:
self._stream.synchronize()
else:
torch.cuda.current_stream().synchronize()
torch.accelerator.current_stream().synchronize()
reqs = batch_isend_irecv(p2p_ops)
for req in reqs:
@@ -236,11 +237,69 @@ class TorchDistGlooStagedEplbCommunicator(EplbCommunicator):
if not recv_staging:
return
with torch.cuda.stream(self._cuda_stream):
with device_stream(self._stream):
for dst_tensor, cpu_tensor in recv_staging:
dst_tensor.copy_(cpu_tensor, non_blocking=True)
class TorchDistXCCLStagedEplbCommunicator(EplbCommunicator):
"""EPLB communicator using XCCL device-to-device P2P on XPU."""
def __init__(
self,
ep_group: ProcessGroup,
stream: torch.Stream | None = None,
) -> None:
self._ep_group = ep_group
self._stream = stream
self._ops: list[tuple[str, torch.Tensor, int]] = []
self._log_initialized()
def add_send(
self,
tensors: list[torch.Tensor],
dst_rank: int,
expert_id: int, # unused by this backend
) -> None:
for tensor in tensors:
self._ops.append(("send", tensor, dst_rank))
def add_recv(
self,
tensors: list[torch.Tensor],
src_rank: int,
expert_id: int, # unused by this backend
) -> None:
for tensor in tensors:
self._ops.append(("recv", tensor, src_rank))
def execute(self) -> None:
if not self._ops:
return
p2p_ops: list[P2POp] = []
try:
for op, tensor, peer_rank in self._ops:
send_or_recv = (
torch.distributed.isend if op == "send" else torch.distributed.irecv
)
p2p_ops.append(
P2POp(
send_or_recv,
tensor,
peer_rank,
self._ep_group,
)
)
finally:
self._ops.clear()
with device_stream(self._stream):
reqs = batch_isend_irecv(p2p_ops)
for req in reqs:
req.wait()
class NixlEplbCommunicator(EplbCommunicator):
"""EPLB communicator backed by NIXL READ transfers."""
@@ -343,7 +402,7 @@ class NixlEplbCommunicator(EplbCommunicator):
uid = uuid.uuid4().hex[:8]
return f"eplb-{self._rank}{pp_suffix}-{uid}"
def set_stream(self, cuda_stream: torch.cuda.Stream | None) -> None:
def set_stream(self, stream: torch.Stream | None) -> None:
pass
def add_send(
@@ -602,10 +661,10 @@ class PyNcclEplbCommunicator(EplbCommunicator):
def __init__(
self,
pynccl_comm: PyNcclCommunicator,
cuda_stream: torch.cuda.Stream | None = None,
stream: torch.Stream | None = None,
) -> None:
self._pynccl_comm = pynccl_comm
self._cuda_stream = cuda_stream
self._stream = stream
self._group_started = False
self._log_initialized()
@@ -622,7 +681,7 @@ class PyNcclEplbCommunicator(EplbCommunicator):
) -> None:
self._ensure_group_started()
for tensor in tensors:
self._pynccl_comm.send(tensor, dst_rank, stream=self._cuda_stream)
self._pynccl_comm.send(tensor, dst_rank, stream=self._stream)
def add_recv(
self,
@@ -632,7 +691,7 @@ class PyNcclEplbCommunicator(EplbCommunicator):
) -> None:
self._ensure_group_started()
for tensor in tensors:
self._pynccl_comm.recv(tensor, src_rank, stream=self._cuda_stream)
self._pynccl_comm.recv(tensor, src_rank, stream=self._stream)
def execute(self) -> None:
if self._group_started:
@@ -750,6 +809,8 @@ def create_eplb_communicator(
return TorchDistGlooStagedEplbCommunicator(
cpu_group=group_coordinator.cpu_group,
)
elif backend == "torch_xccl":
return TorchDistXCCLStagedEplbCommunicator(ep_group=torch_group)
elif backend == "torch_nccl":
return TorchDistNcclEplbCommunicator(ep_group=torch_group)
elif backend == "pynccl":