Skip to content

Commit c05804d

Browse files
committed
feat: use device group for dp metadata
Signed-off-by: Jade Zheng <zheng.shoujian@outlook.com>
1 parent 516e14a commit c05804d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

vllm_ascend/worker/model_runner_v1.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import numpy.typing as npt
3030
import torch
3131
import torch._dynamo.cache_size
32-
import torch.distributed as dist
3332
import torch.nn as nn
3433
from tqdm import tqdm # type: ignore
3534
from vllm.attention import AttentionType, get_attn_backend
@@ -596,18 +595,15 @@ def _update_states(self, scheduler_output: "SchedulerOutput") -> None:
596595
def _get_forward_metadata_across_dp(
597596
self, num_tokens: int, with_prefill: bool,
598597
enable_dbo: bool) -> tuple[torch.Tensor, bool, bool]:
599-
600-
# Compose: all_reduce metadata (num_tokens of each rank, with_prefill, enable_dbo)
601-
num_tokens_across_dp = torch.zeros(self.dp_size + 2,
602-
dtype=torch.int32,
603-
device="cpu")
604-
num_tokens_across_dp[self.dp_rank] = num_tokens
605-
num_tokens_across_dp[-2] = int(with_prefill)
606-
num_tokens_across_dp[-1] = int(not enable_dbo)
607-
dist.all_reduce(num_tokens_across_dp, group=get_dp_group().cpu_group)
608-
with_prefill = bool(num_tokens_across_dp[-2])
609-
enable_dbo = not bool(num_tokens_across_dp[-1])
610-
num_tokens_across_dp = num_tokens_across_dp[:-2]
598+
local_forward_metadata = torch.tensor(
599+
[[num_tokens, with_prefill, enable_dbo]],
600+
device="npu",
601+
dtype=torch.int32)
602+
global_forward_metadata = get_dp_group().all_gather(
603+
local_forward_metadata, dim=0)
604+
num_tokens_across_dp = global_forward_metadata[:, 0].cpu()
605+
with_prefill = bool(global_forward_metadata[:, 1].any())
606+
enable_dbo = bool(global_forward_metadata[:, 2].any())
611607
return num_tokens_across_dp, with_prefill, enable_dbo
612608

613609
def _get_forward_metadata_across_dp_and_pad(

0 commit comments

Comments
 (0)