### What this PR does / why we need it?
**Scope of Changes**:
| File Path |
| :--- |
|`vllm_ascend/ops/layer_shard_linear.py`|
|`vllm_ascend/ops/linear.py`|
|`vllm_ascend/ops/linear_op.py`|
|`vllm_ascend/worker/worker.py`|
| ` vllm_ascend/patch/worker/patch_bert.py` |
| ` vllm_ascend/patch/worker/patch_deepseek.py` |
| ` vllm_ascend/patch/worker/patch_distributed.py` |
| ` vllm_ascend/patch/worker/patch_module.py` |
| ` vllm_ascend/patch/worker/patch_multimodal_merge.py` |
| ` vllm_ascend/patch/worker/patch_qwen3_next.py` |
| ` vllm_ascend/patch/worker/patch_qwen3_next_mtp.py` |
| ` vllm_ascend/patch/worker/patch_rejection_sampler.py` |
| ` vllm_ascend/patch/worker/patch_rope.py` |
| ` vllm_ascend/patch/worker/patch_triton.py` |
| ` vllm_ascend/patch/worker/patch_unquantized_gemm.py` |
| ` vllm_ascend/patch/worker/patch_v2_egale.py` |
|` vllm_ascend/worker/npu_input_batch.py`|
|` vllm_ascend/worker/v2/aclgraph_utils.py`|
|` vllm_ascend/worker/v2/attn_utils.py`|
|` vllm_ascend/worker/v2/model_runner.py`|
|` vllm_ascend/worker/v2/sample/gumbel.py`|
|` vllm_ascend/worker/v2/sample/penalties.py`|
|` vllm_ascend/worker/v2/sample/sampler.py`|
|` vllm_ascend/worker/v2/spec_decode/__init__.py`|
|` vllm_ascend/worker/v2/spec_decode/eagle.py`|
|` vllm_ascend/worker/v2/states.py`|
### Does this PR introduce _any_ user-facing change?
### How was this patch tested?
- vLLM version: v0.14.0
- vLLM main:
d68209402d
Signed-off-by: MrZ20 <2609716663@qq.com>
Signed-off-by: SILONG ZENG <2609716663@qq.com>
Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com>
Co-authored-by: wangxiyuan <wangxiyuan1007@gmail.com>
116 lines
4.4 KiB
Python
116 lines
4.4 KiB
Python
#
|
|
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
|
|
# This file is a part of the vllm-ascend project.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
|
|
|
|
import torch
|
|
import vllm
|
|
from torch.distributed import Backend
|
|
from vllm.distributed.parallel_state import GroupCoordinator, _get_unique_name, _register_group
|
|
|
|
from vllm_ascend.distributed.device_communicators.npu_communicator import NPUCommunicator
|
|
from vllm_ascend.utils import create_hccl_pg_options
|
|
|
|
|
|
class GroupCoordinatorPatch(GroupCoordinator):
|
|
def __init__(
|
|
self,
|
|
group_ranks: list[list[int]],
|
|
local_rank: int,
|
|
torch_distributed_backend: str | Backend,
|
|
use_device_communicator: bool, # whether to use device communicator
|
|
use_message_queue_broadcaster: bool = False,
|
|
group_name: str | None = None,
|
|
):
|
|
group_name = group_name or "anonymous"
|
|
self.unique_name = _get_unique_name(group_name)
|
|
_register_group(self)
|
|
|
|
self.rank = torch.distributed.get_rank()
|
|
self.local_rank = local_rank
|
|
|
|
self_device_group = None
|
|
self_cpu_group = None
|
|
hccl_pg_options = create_hccl_pg_options(group_name)
|
|
|
|
for ranks in group_ranks:
|
|
device_group = torch.distributed.new_group(
|
|
ranks, backend=torch_distributed_backend, pg_options=hccl_pg_options
|
|
)
|
|
|
|
# a group with `gloo` backend, to allow direct coordination between
|
|
# processes through the CPU.
|
|
cpu_group = torch.distributed.new_group(ranks, backend="gloo")
|
|
if self.rank in ranks:
|
|
self.ranks = ranks
|
|
self.world_size = len(ranks)
|
|
self.rank_in_group = ranks.index(self.rank)
|
|
self_device_group = device_group
|
|
self_cpu_group = cpu_group
|
|
|
|
assert self_cpu_group is not None
|
|
assert self_device_group is not None
|
|
|
|
self.cpu_group = self_cpu_group
|
|
self.device_group = self_device_group
|
|
self.device = torch.npu.current_device()
|
|
|
|
self.use_device_communicator = use_device_communicator
|
|
self.device_communicator = None
|
|
if use_device_communicator and self.world_size > 1:
|
|
self.device_communicator = NPUCommunicator(
|
|
cpu_group=self.cpu_group,
|
|
device=self.device,
|
|
device_group=self.device_group,
|
|
unique_name=self.unique_name,
|
|
)
|
|
|
|
from vllm.distributed.device_communicators.shm_broadcast import MessageQueue
|
|
|
|
self.mq_broadcaster: MessageQueue | None = None
|
|
if use_message_queue_broadcaster and self.world_size > 1:
|
|
self.mq_broadcaster = MessageQueue.create_from_process_group(self.cpu_group, 1 << 22, 6)
|
|
|
|
self.use_custom_op_call = False
|
|
self.use_cpu_custom_send_recv = False
|
|
|
|
def all_to_all(
|
|
self,
|
|
input_: torch.Tensor,
|
|
scatter_dim: int = 0,
|
|
gather_dim: int = -1,
|
|
scatter_sizes: list[int] | None = None,
|
|
gather_sizes: list[int] | None = None,
|
|
) -> torch.Tensor:
|
|
if self.world_size == 1:
|
|
return input_
|
|
assert -input_.dim() <= scatter_dim < input_.dim(), (
|
|
f"Invalid scatter dim ({scatter_dim}) for input tensor with shape {input_.size()}"
|
|
)
|
|
assert -input_.dim() <= gather_dim < input_.dim(), (
|
|
f"Invalid gather dim ({gather_dim}) for input tensor with shape {input_.size()}"
|
|
)
|
|
assert self.device_communicator is not None, "device_communicator should be initialized when world_size > 1"
|
|
return self.device_communicator.all_to_all(input_, scatter_dim, gather_dim, scatter_sizes, gather_sizes)
|
|
|
|
def all_reduce(self, input_):
|
|
if self.world_size == 1:
|
|
return input_
|
|
return torch.ops.vllm.all_reduce(input_, group_name=self.unique_name)
|
|
|
|
|
|
vllm.distributed.parallel_state.GroupCoordinator = GroupCoordinatorPatch
|