| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- # SPDX-License-Identifier: Apache-2.0
- # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
- from typing import Any
- import torch
- import torch.distributed
- from .parallel_state import get_tp_group
- _DSV41_PREFILL_TIMING = __import__("os").environ.get("DSV41_PREFILL_TIMING", "0") == "1"
- def tensor_model_parallel_all_reduce(input_: torch.Tensor) -> torch.Tensor:
- """All-reduce the input tensor across model parallel group."""
- if _DSV41_PREFILL_TIMING and input_.dim() >= 2 and input_.shape[0] >= 1024:
- # Stage 7: phase "allreduce" of the prefill budget.
- from vllm.model_executor.kernels.attention.dsa.candidate_blocks import _PrefillTimer
- with _PrefillTimer("allreduce", int(input_.shape[0])):
- return get_tp_group().all_reduce(input_)
- return get_tp_group().all_reduce(input_)
- def tensor_model_parallel_all_gather(
- input_: torch.Tensor, dim: int = -1
- ) -> torch.Tensor:
- """All-gather the input tensor across model parallel group."""
- return get_tp_group().all_gather(input_, dim)
- def tensor_model_parallel_reduce_scatter(
- input_: torch.Tensor, dim: int = -1
- ) -> torch.Tensor:
- """Reduce-Scatter the input tensor across model parallel group."""
- return get_tp_group().reduce_scatter(input_, dim)
- def tensor_model_parallel_gather(
- input_: torch.Tensor, dst: int = 0, dim: int = -1
- ) -> torch.Tensor | None:
- """Gather the input tensor across model parallel group."""
- return get_tp_group().gather(input_, dst, dim)
- def broadcast_tensor_dict(
- tensor_dict: dict[Any, torch.Tensor | Any] | None = None, src: int = 0
- ):
- if not torch.distributed.is_initialized():
- return tensor_dict
- return get_tp_group().broadcast_tensor_dict(tensor_dict, src)
|