[PCP] Support prefill context parallelism with data parallelism (#57075)
Signed-off-by: QiuChunshuo <qiuchunshuo@huawei.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Signed-off-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com> Co-authored-by: QiuChunshuo <qiuchunshuo@huawei.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: Robert Shaw <114415538+robertgshaw2-redhat@users.noreply.github.com> Co-authored-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
QiuChunshuo
Claude Fable 5.1
Codex
Robert Shaw
Nick Hill
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
6697a7dd30
commit
e6dc16cebd
@@ -56,11 +56,17 @@ class AgRsAll2AllManager(All2AllManagerBase):
|
||||
|
||||
def __init__(self, cpu_group, tcp_store_group=None):
|
||||
super().__init__(cpu_group, tcp_store_group)
|
||||
self.use_ep = get_current_vllm_config().parallel_config.enable_expert_parallel
|
||||
|
||||
def _get_comm_group(self, is_sequence_parallel: bool) -> Any:
|
||||
if is_sequence_parallel:
|
||||
return get_ep_group()
|
||||
if self.dp_world_size > 1:
|
||||
if self.use_ep and get_pcp_group().world_size > 1:
|
||||
assert self.tp_group.world_size == 1, (
|
||||
"DP+PCP with TP>1 requires sequence-parallel MoE inputs"
|
||||
)
|
||||
return get_ep_group()
|
||||
return get_dp_group()
|
||||
return get_pcp_group()
|
||||
|
||||
@@ -72,6 +78,7 @@ class AgRsAll2AllManager(All2AllManagerBase):
|
||||
assert dp_metadata is not None
|
||||
sizes = dp_metadata.get_chunk_sizes_across_dp_rank()
|
||||
assert sizes is not None
|
||||
assert len(sizes) == comm_group.world_size
|
||||
return sizes
|
||||
|
||||
def dispatch_router_logits(
|
||||
|
||||
@@ -6,6 +6,7 @@ from vllm.distributed.device_communicators.pynccl import defer_comm_warmup_on_ro
|
||||
from vllm.distributed.parallel_state import (
|
||||
_init_stateless_group,
|
||||
_node_count,
|
||||
get_pcp_group,
|
||||
get_pp_group,
|
||||
get_tp_group,
|
||||
get_world_group,
|
||||
@@ -72,12 +73,13 @@ def create_standby_groups(
|
||||
_STANDBY_WORLD_NODE_COUNT = _node_count(_STANDBY_WORLD.tcp_store_group)
|
||||
|
||||
tp_size = get_tp_group().world_size
|
||||
pcp_size = get_pcp_group().world_size
|
||||
pp_size = get_pp_group().world_size
|
||||
|
||||
all_ranks = torch.arange(new_world_size_across_dp).reshape(
|
||||
-1, new_dp_size, pp_size, tp_size
|
||||
-1, new_dp_size, pp_size, pcp_size, tp_size
|
||||
)
|
||||
standby_dp_ranks = all_ranks.transpose(1, 3).reshape(-1, new_dp_size).unbind(0)
|
||||
standby_dp_ranks = all_ranks.transpose(1, 4).reshape(-1, new_dp_size).unbind(0)
|
||||
standby_dp_ranks = [x.tolist() for x in standby_dp_ranks]
|
||||
|
||||
# Deferred to commit so the warm-up runs while the engine is paused.
|
||||
@@ -87,7 +89,9 @@ def create_standby_groups(
|
||||
)
|
||||
|
||||
standby_ep_ranks = (
|
||||
all_ranks.transpose(1, 2).reshape(-1, new_dp_size * tp_size).unbind(0)
|
||||
all_ranks.transpose(1, 2)
|
||||
.reshape(-1, new_dp_size * pcp_size * tp_size)
|
||||
.unbind(0)
|
||||
)
|
||||
standby_ep_ranks = [x.tolist() for x in standby_ep_ranks]
|
||||
_STANDBY_EP = _init_stateless_group(
|
||||
|
||||
+14
-3
@@ -58,8 +58,17 @@ class BatchDescriptor:
|
||||
|
||||
|
||||
def _compute_sp_num_tokens(
|
||||
num_tokens_across_dp_cpu: torch.Tensor, sequence_parallel_size: int
|
||||
num_tokens_across_dp_cpu: torch.Tensor,
|
||||
sequence_parallel_size: int,
|
||||
pcp_size: int = 1,
|
||||
use_ep: bool = True,
|
||||
) -> list[int]:
|
||||
if pcp_size > 1:
|
||||
num_tokens_across_dp_cpu = (
|
||||
num_tokens_across_dp_cpu.repeat_interleave(pcp_size)
|
||||
if use_ep
|
||||
else num_tokens_across_dp_cpu * pcp_size
|
||||
)
|
||||
sp_tokens = (
|
||||
num_tokens_across_dp_cpu + sequence_parallel_size - 1
|
||||
) // sequence_parallel_size
|
||||
@@ -98,12 +107,14 @@ class DPMetadata:
|
||||
return DPMetadata(num_tokens_across_dp_cpu)
|
||||
|
||||
@contextmanager
|
||||
def sp_local_sizes(self, sequence_parallel_size: int):
|
||||
def sp_local_sizes(
|
||||
self, sequence_parallel_size: int, pcp_size: int = 1, use_ep: bool = False
|
||||
):
|
||||
"""Context manager for setting self.local_sizes. Same as self.chunked_sizes
|
||||
but without any chunking.
|
||||
"""
|
||||
self.local_sizes = _compute_sp_num_tokens(
|
||||
self.num_tokens_across_dp_cpu, sequence_parallel_size
|
||||
self.num_tokens_across_dp_cpu, sequence_parallel_size, pcp_size, use_ep
|
||||
)
|
||||
try:
|
||||
yield self.local_sizes
|
||||
|
||||
@@ -657,7 +657,11 @@ class MoERunner(MoERunnerInterface):
|
||||
"""
|
||||
ctx = get_forward_context()
|
||||
return (
|
||||
ctx.dp_metadata.sp_local_sizes(self.moe_config.sp_size)
|
||||
ctx.dp_metadata.sp_local_sizes(
|
||||
self.moe_config.sp_size,
|
||||
pcp_size=self.moe_config.pcp_size,
|
||||
use_ep=self.moe_config.use_ep,
|
||||
)
|
||||
if ctx.dp_metadata
|
||||
else nullcontext()
|
||||
)
|
||||
|
||||
@@ -329,12 +329,6 @@ class CudaPlatformBase(Platform):
|
||||
parallel_config = vllm_config.parallel_config
|
||||
model_config = vllm_config.model_config
|
||||
|
||||
if (
|
||||
parallel_config.prefill_context_parallel_size > 1
|
||||
and parallel_config.data_parallel_size > 1
|
||||
):
|
||||
raise ValueError("PCP does not support data parallelism on CUDA yet.")
|
||||
|
||||
if parallel_config.worker_cls == "auto":
|
||||
parallel_config.worker_cls = "vllm.v1.worker.gpu_worker.Worker"
|
||||
|
||||
|
||||
@@ -934,12 +934,6 @@ class RocmPlatform(Platform):
|
||||
compilation_config = vllm_config.compilation_config
|
||||
parallel_config = vllm_config.parallel_config
|
||||
|
||||
if (
|
||||
parallel_config.prefill_context_parallel_size > 1
|
||||
and parallel_config.data_parallel_size > 1
|
||||
):
|
||||
raise ValueError("PCP does not support data parallelism on ROCm yet.")
|
||||
|
||||
if (
|
||||
compilation_config.cudagraph_mode.has_full_cudagraphs()
|
||||
and parallel_config.prefill_context_parallel_size > 1
|
||||
|
||||
@@ -828,7 +828,7 @@ def split_decodes_and_prefills(
|
||||
(query_lens == query_lens[0]) | (query_lens == 0)
|
||||
):
|
||||
return num_reqs, 0, num_tokens, 0 # all decodes
|
||||
is_prefill = query_lens != query_lens[0]
|
||||
is_prefill = (query_lens != query_lens[0]) & (query_lens != 0)
|
||||
else:
|
||||
is_prefill = query_lens > decode_threshold
|
||||
|
||||
|
||||
@@ -18,8 +18,15 @@ def _gather_prefill_cache_inputs(
|
||||
assert all(tensor.shape[0] == local_num_tokens for tensor in tensors)
|
||||
assert 0 <= num_decode_tokens <= local_num_tokens
|
||||
|
||||
if num_decode_tokens == local_num_tokens:
|
||||
return tensors, slot_mapping[:num_decode_tokens]
|
||||
# Replicated draft decodes use unexpanded slot mappings, even with DP padding.
|
||||
if (
|
||||
num_decode_tokens == local_num_tokens
|
||||
or slot_mapping.shape[0] <= local_num_tokens
|
||||
):
|
||||
return (
|
||||
tuple(tensor[:num_decode_tokens] for tensor in tensors),
|
||||
slot_mapping[:num_decode_tokens],
|
||||
)
|
||||
|
||||
pcp_group = get_pcp_group()
|
||||
gathered_prefills = tuple(
|
||||
|
||||
@@ -754,6 +754,7 @@ class PCPManager:
|
||||
def prepare_draft_prefill(
|
||||
self, input_batch: InputBatch, input_ids: torch.Tensor
|
||||
) -> None:
|
||||
self.draft_prefill_batch = None
|
||||
if input_batch is not self._global_batch or self._local_batch is None:
|
||||
return
|
||||
local_batch = self._local_batch
|
||||
|
||||
@@ -364,7 +364,7 @@ class DraftModelSpeculator(BaseSpeculator):
|
||||
kv_cache_config=self.kv_cache_config,
|
||||
causal=causal,
|
||||
seq_lens_cpu_upper_bound=draft_seq_lens_cpu_upper_bound,
|
||||
is_prefilling=self.draft_is_prefilling[:num_reqs],
|
||||
is_prefilling=self.draft_is_prefilling[:num_reqs_padded],
|
||||
)
|
||||
return attn_metadata
|
||||
|
||||
|
||||
@@ -406,13 +406,14 @@ class Worker(WorkerBase):
|
||||
if dp_local_rank is None:
|
||||
dp_local_rank = self.parallel_config.data_parallel_index
|
||||
|
||||
tp_pp_world_size = (
|
||||
tp_pcp_pp_world_size = (
|
||||
self.parallel_config.pipeline_parallel_size
|
||||
* self.parallel_config.prefill_context_parallel_size
|
||||
* self.parallel_config.tensor_parallel_size
|
||||
)
|
||||
|
||||
# DP_LOCAL_RANK * TP_PP_WORLD_SIZE + TP_LOCAL_RANK
|
||||
self.local_rank += dp_local_rank * tp_pp_world_size
|
||||
# DP_LOCAL_RANK * TP_PCP_PP_WORLD_SIZE + TP_LOCAL_RANK
|
||||
self.local_rank += dp_local_rank * tp_pcp_pp_world_size
|
||||
|
||||
# Publish the logical-to-physical mapping for topology queries
|
||||
# such as NIC affinity and P2P checks.
|
||||
|
||||
Reference in New Issue
Block a user