Skip to content

Commit 7573ea0

Browse files
authored
[Revert] Revert [feature] reduce cases that required DP padding (vllm-project#11772) (vllm-project#13022)
### What this PR does / why we need it? [Revert] Revert [feature] reduce cases that required DP padding (vllm-project#11772) ### Does this PR introduce _any_ user-facing change? ### How was this patch tested? - vLLM version: v0.25.1 - vLLM main: vllm-project/vllm@fe784ff Signed-off-by: zzzzwwjj <1183291235@qq.com>
1 parent a935d36 commit 7573ea0

8 files changed

Lines changed: 32 additions & 39 deletions

File tree

.gitleaks.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,3 @@ minEntropy = 3.0
8282
redact = true
8383
maxMatchLength = 2048
8484
scanGitHistory = false
85-
86-
[[allowlists]]
87-
paths = ["^tests/ut/spec_decode/a2/test_eagle_proposer.py"]
88-
rules = ["generic-api-key"]

tests/ut/ops/a2/test_token_dispatcher.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def setUp(self):
146146
self.hier_comm_patch = patch(
147147
"vllm_ascend.ops.fused_moe.token_dispatcher.is_hierarchical_communication_enabled", return_value=False
148148
)
149-
self.mock_hier_comm = self.hier_comm_patch.start()
149+
self.hier_comm_patch.start()
150+
self.skip_allreduce_patch = patch(
151+
"vllm_ascend.ops.fused_moe.token_dispatcher.should_skip_allreduce_across_dp_group", return_value=False
152+
)
153+
self.mock_skip_allreduce = self.skip_allreduce_patch.start()
150154

151155
kwargs = {"with_quant": False, "top_k": 8, "num_experts": 128}
152156
self.dispatcher = TokenDispatcherWithMC2(**kwargs)
@@ -161,24 +165,26 @@ def tearDown(self):
161165
self.ascend_config_patch.stop()
162166
self.ascend_config_utils_patch.stop()
163167
self.hier_comm_patch.stop()
168+
self.skip_allreduce_patch.stop()
164169

165170
def test_init(self):
166171
self.assertEqual(self.dispatcher.ep_rank_id, 0)
167172
self.assertEqual(self.dispatcher.ep_world_size, 8)
168173
self.assertTrue(self.dispatcher.enable_dispatch_v2)
169174
self.assertTrue(self.dispatcher.need_extra_args)
170-
self.assertEqual(self.dispatcher.global_bs, 1024)
175+
self.assertEqual(self.dispatcher.global_bs, 0)
171176

172177
def test_init_uses_mc2_capacity_for_non_uniform_global_bs(self):
173178
self.mock_get_config.return_value.parallel_config.tensor_parallel_size = 4
179+
self.mock_skip_allreduce.return_value = True
174180

175181
dispatcher = TokenDispatcherWithMC2(with_quant=False, top_k=8, num_experts=128)
176182

177183
self.assertEqual(dispatcher.global_bs, 256)
178184

179-
def test_get_dispatch_mc2_kwargs_without_hier_comm_omits_mc2_mask(self):
185+
def test_get_dispatch_mc2_kwargs_with_skip_allreduce_omits_mc2_mask(self):
180186
self.mock_get_config.return_value.parallel_config.tensor_parallel_size = 4
181-
self.mock_hier_comm.return_value = False
187+
self.mock_skip_allreduce.return_value = True
182188
dispatcher = TokenDispatcherWithMC2(with_quant=False, top_k=8, num_experts=128)
183189

184190
hidden_states = torch.randn(10, 128)
@@ -199,9 +205,7 @@ def test_get_dispatch_mc2_kwargs_without_hier_comm_omits_mc2_mask(self):
199205
self.assertEqual(kwargs["global_bs"], 256)
200206
self.assertNotIn("x_active_mask", kwargs)
201207

202-
def test_get_dispatch_mc2_kwargs_with_hier_comm_keeps_mc2_mask(self):
203-
self.mock_hier_comm.return_value = True
204-
dispatcher = TokenDispatcherWithMC2(with_quant=False, top_k=8, num_experts=128)
208+
def test_get_dispatch_mc2_kwargs_without_skip_allreduce_keeps_mc2_mask(self):
205209
hidden_states = torch.randn(10, 128)
206210
topk_ids = torch.randint(0, 8, (10, 1))
207211
topk_weights = torch.randn(10, 1)
@@ -215,7 +219,7 @@ def test_get_dispatch_mc2_kwargs_with_hier_comm_keeps_mc2_mask(self):
215219
mc2_mask=mc2_mask,
216220
)
217221

218-
kwargs = dispatcher.get_dispatch_mc2_kwargs(token_dispatch_input)
222+
kwargs = self.dispatcher.get_dispatch_mc2_kwargs(token_dispatch_input)
219223

220224
self.assertEqual(kwargs["global_bs"], 0)
221225
self.assertIs(kwargs["x_active_mask"], mc2_mask)

tests/ut/spec_decode/a2/test_eagle_proposer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ def check_mock(self):
16141614
assert hasattr(RunnerCls, "_sync_metadata_across_dp")
16151615
sig = inspect.signature(RunnerCls._sync_metadata_across_dp)
16161616
sig_name = self.get_param_names(sig)
1617-
assert sig_name == ['self', 'num_tokens', 'is_draft_model', 'cudagraph_mode']
1617+
assert sig_name == ['self', 'num_tokens', 'is_draft_model', 'cudagraph_mode', 'allow_dp_padding']
16181618

16191619
assert hasattr(RunnerCls, "_pad_query_start_loc_for_fia")
16201620
sig = inspect.signature(RunnerCls._pad_query_start_loc_for_fia)

vllm_ascend/ascend_config.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,6 @@ def __init__(self, finegrained_tp_config: dict, vllm_config):
494494
if any(size > 0 for size in module_tp_sizes) and enabled_configs:
495495
logger.info("finegrained_tp_config enabled: %s", ", ".join(enabled_configs))
496496

497-
def get_max_finegrained_tp_size(self) -> int:
498-
max_finegrained_tp_size = 1
499-
max_finegrained_tp_size = max(max_finegrained_tp_size, self.oproj_tensor_parallel_size)
500-
max_finegrained_tp_size = max(max_finegrained_tp_size, self.lmhead_tensor_parallel_size)
501-
max_finegrained_tp_size = max(max_finegrained_tp_size, self.embedding_tensor_parallel_size)
502-
max_finegrained_tp_size = max(max_finegrained_tp_size, self.mlp_tensor_parallel_size)
503-
max_finegrained_tp_size = max(max_finegrained_tp_size, self.olora_tensor_parallel_size)
504-
return max_finegrained_tp_size
505-
506497

507498
class AscendCompilationConfig:
508499
"""

vllm_ascend/ascend_forward_context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ def set_ascend_forward_context(
134134
from vllm_ascend.ops.fused_moe.moe_comm_method import get_moe_comm_method
135135

136136
max_num_tokens = int(num_tokens_across_dp.max().item()) if num_tokens_across_dp is not None else num_tokens
137-
moe_comm_type = select_moe_comm_method(max_num_tokens, vllm_config)
137+
moe_comm_type = select_moe_comm_method(
138+
max_num_tokens,
139+
vllm_config,
140+
)
138141

139142
forward_context.moe_comm_type = moe_comm_type
140143
forward_context.moe_comm_method = get_moe_comm_method(moe_comm_type)
@@ -353,6 +356,7 @@ def select_moe_comm_method(num_tokens: int, vllm_config: VllmConfig) -> MoECommT
353356
Args:
354357
num_tokens (int): The number of tokens in the current batch.
355358
vllm_config (VllmConfig): Runtime configuration for the model.
359+
is_draft_model (bool): Whether the model runs in MTP mode.
356360
357361
Raises:
358362
ValueError: If the soc version is unsupported.

vllm_ascend/ops/fused_moe/token_dispatcher.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
AscendDeviceType,
5252
get_ascend_device_type,
5353
is_hierarchical_communication_enabled,
54+
should_skip_allreduce_across_dp_group,
5455
)
5556

5657
EXPERT_TOKEN_NUMS_TYPE_CUMSUM = 0
@@ -139,11 +140,11 @@ def __init__(self, **kwargs):
139140
self.max_num_tokens_per_rank = num_tokens_per_tp_rank
140141
_max_global_bs = num_tokens_per_tp_rank * self.ep_world_size
141142

142-
# When hierarchical communication case, tokens are uniform across ranks:
143+
# When allreduce across DP is not skipped, tokens are uniform across ranks:
143144
# use global_bs=0 (uniform mode) and pass mc2_mask.
144-
# When it is not hierarchical communication case, we will not do padding across dp,
145-
# tokens may differ per rank: use the real global_bs and do NOT pass mc2_mask.
146-
self.global_bs = _max_global_bs if not is_hierarchical_communication_enabled() else 0
145+
# When allreduce is skipped, tokens may differ per rank:
146+
# use the real global_bs and do NOT pass mc2_mask.
147+
self.global_bs = _max_global_bs if should_skip_allreduce_across_dp_group(vllm_config) else 0
147148

148149
# NOTE: When enable_mc2_hierarchy_comm is true, we need pass in `comm_alg` to mc2 op.
149150
self.need_comm_alg = get_ascend_config().enable_mc2_hierarchy_comm

vllm_ascend/spec_decode/extract_hidden_states_proposer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def _determine_batch_execution_and_padding(
9797
num_tokens=num_tokens_padded,
9898
is_draft_model=True,
9999
cudagraph_mode=cudagraph_mode,
100+
allow_dp_padding=use_cudagraphs,
100101
)
101102

102103
if num_tokens_across_dp is not None:

vllm_ascend/worker/model_runner_v1.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,17 @@
151151
AscendDeviceType,
152152
calc_split_factor,
153153
check_gdn_layer,
154+
embedding_tp_enable,
154155
enable_sfa_dcp_replicated_indexer,
155156
enable_sp,
156157
enable_sp_by_pass,
157158
get_ascend_device_type,
158159
get_c_env,
159160
global_stream,
160161
is_hidden_state_cache_spec,
161-
is_hierarchical_communication_enabled,
162162
kv_cache_spec_uses_sparse_sfa_c8,
163163
lmhead_tp_enable,
164+
oproj_tp_enable,
164165
set_potential_max_tokens,
165166
should_skip_allreduce_across_dp_group,
166167
)
@@ -635,6 +636,7 @@ def _sync_metadata_across_dp(
635636
num_tokens: int,
636637
is_draft_model: bool = False,
637638
cudagraph_mode: CUDAGraphMode = CUDAGraphMode.NONE,
639+
allow_dp_padding: bool = False,
638640
) -> tuple[int, torch.Tensor | None, CUDAGraphMode]:
639641
# TODO: In vLLM, the only thing that needs to be synced is num_tokens, but in
640642
# our case, we still need to sync the other two flags as well. So we need to
@@ -660,17 +662,7 @@ def _sync_metadata_across_dp(
660662
synced_cudagraph_mode = CUDAGraphMode(_post_process_cudagraph_mode(packed_tensor))
661663

662664
# Create a tensor for num_tokens_after_padding
663-
comm_method = select_moe_comm_method(max_tokens_across_dp, self.vllm_config)
664-
is_mc2_with_hierarchical = (comm_method == MoECommType.MC2 and is_hierarchical_communication_enabled())
665-
is_finegrained_tp = self.ascend_config.finegrained_tp_config.get_max_finegrained_tp_size() > 1
666-
# There are three cases where padding between DPs is required:
667-
# 1. comm_method == ALLGATHER;
668-
# 2. comm_method == MC2 and is hierarchical communication, in this case,
669-
# the mc2 operator does not support dynamic batch size.
670-
# TODO(zzzzwwjj): It can be remove after op support this case.
671-
# 3. when finegrained_tp is open, we need to ensure num_tokens remains consistent within finegrained_tp_group.
672-
# TODO(zzzzwwjj): We can do dp padding in finegrained_tp_group, instead of world_group.
673-
if comm_method == MoECommType.ALLGATHER or is_mc2_with_hierarchical or is_finegrained_tp:
665+
if allow_dp_padding or is_draft_model:
674666
num_tokens_after_padding = torch.tensor(
675667
[max_tokens_across_dp] * self.dp_size, device="cpu", dtype=torch.int32
676668
)
@@ -2745,6 +2737,10 @@ def dispatch_cudagraph(num_tokens, disable_full=False, valid_modes=None):
27452737
_, num_tokens_across_dp, synced_cudagraph_mode = self._sync_metadata_across_dp(
27462738
num_tokens=num_tokens_padded,
27472739
cudagraph_mode=cudagraph_mode,
2740+
allow_dp_padding=((cudagraph_mode != CUDAGraphMode.NONE)
2741+
or enable_sp(self.vllm_config)
2742+
or oproj_tp_enable()
2743+
or embedding_tp_enable()),
27482744
)
27492745

27502746
# Extract DP padding if there is any

0 commit comments

Comments
 (0)