mnnvl_compat.py 1.18 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
from typing import Any

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import torch.distributed as dist
from flashinfer.comm.mnnvl import CommBackend as CommBackend

from vllm.utils.flashinfer import has_flashinfer_all2all

assert has_flashinfer_all2all(), "Flashinfer alltoallv module cannot be found"


class CustomCommunicator(CommBackend):
    def __init__(self, group):
        self._group = group

    def Get_rank(self) -> int:
        return self._group.rank()

    def Get_size(self) -> int:
        return self._group.size()

    def allgather(self, data: int):
        gathered = [None] * self.Get_size()
        dist.all_gather_object(gathered, data, group=self._group)
        return gathered

28
29
30
31
32
33
34
35
36
    # NOTE(rob): CommBackend is an abstract class, and bcast/barrier
    # are unimplemented on vLLM side. If we need to utilize these
    # methods in the future, can create a concrete implementation.
    def bcast(self, data: Any, root: int) -> Any:
        raise NotImplementedError

    def barrier(self) -> None:
        raise NotImplementedError

37
    def Split(self, color: int, key: int) -> "CustomCommunicator":
38
        return self