[Feature] Support sequence parallel without the need for DP, 1.9%~5.0% E2E Throughput Improvement (#47070)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
Co-authored-by: Canlin Guo <canlinguosdu@gmail.com>
This commit is contained in:
Wentao Ye
2026-07-05 05:41:30 -07:00
committed by GitHub
co-authored by Canlin Guo
parent fa4321de3d
commit b6cc46ec3b
7 changed files with 33 additions and 22 deletions
+4 -8
View File
@@ -1305,15 +1305,11 @@ class DeepseekV2DecoderLayer(nn.Module):
residual *= 1.0 / self.routed_scaling_factor
if self.use_sequence_parallel_moe:
sp_remainder = (
hidden_states.shape[0] % get_tensor_model_parallel_world_size()
)
tp_world_size = get_tensor_model_parallel_world_size()
# small trick using minus, eg. -17 % 8 = 7
sp_pad = (-hidden_states.shape[0]) % tp_world_size
# pad if not divisible by world size
if sp_remainder:
sp_pad = get_tensor_model_parallel_world_size() - sp_remainder
hidden_states = torch.nn.functional.pad(
hidden_states, (0, 0, 0, sp_pad)
)
hidden_states = torch.nn.functional.pad(hidden_states, (0, 0, 0, sp_pad))
hidden_states = tensor_model_parallel_reduce_scatter(hidden_states, 0)
if not input_is_sequence_parallel:
residual = sequence_parallel_chunk(residual)
+4 -1
View File
@@ -192,7 +192,10 @@ class MLPBlock(torch.nn.Module):
quant_config = vllm_config.quant_config
parallel_config = vllm_config.parallel_config
self.is_sequence_parallel = parallel_config.use_sequence_parallel_moe
self.is_sequence_parallel = (
parallel_config.use_sequence_parallel_moe
and vllm_config.lora_config is None
)
self.layer_idx = layer_idx
self.num_experts = config.num_local_experts