[Neuron] Add Neuron device communicator for vLLM v1 (#14085)

This commit is contained in:
gnovack
2025-03-10 18:37:04 -07:00
committed by GitHub
parent 485afdd3cb
commit d6123170d5
3 changed files with 127 additions and 0 deletions
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
import torch
from vllm.distributed.device_communicators.base_device_communicator import (
DeviceCommunicatorBase)
from vllm.platforms import current_platform
if current_platform.is_neuron():
import torch_xla.core.xla_model as xm
class NeuronCommunicator(DeviceCommunicatorBase):
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, "Neuron only supports dim=-1 for all-gather."
return xm.all_gather(x, dim=dim)
+8
View File
@@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, Optional
from vllm import envs
from vllm.logger import init_logger
from .interface import Platform, PlatformEnum
@@ -56,6 +57,13 @@ class NeuronPlatform(Platform):
logger.warning("Pin memory is not supported on Neuron.")
return False
@classmethod
def get_device_communicator_cls(cls) -> str:
if envs.VLLM_USE_V1:
return "vllm.distributed.device_communicators.neuron_communicator.NeuronCommunicator" # noqa
else:
return Platform.get_device_communicator_cls()
@classmethod
def use_all_gather(cls) -> bool:
return True