-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Deepseek v4 support dp attention is not TP size #24952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
ad78d18
bc4135a
a9b5b05
3944eda
45c6521
d4da6dc
4813ac5
eb1d8df
5ec497c
fe29439
b5f890b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,9 @@ | |
| from sglang.srt.layers.deepseek_v4_rope import apply_rotary_emb_triton | ||
| from sglang.srt.layers.dp_attention import ( | ||
| _DpGatheredBufferWrapper, | ||
| attn_tp_all_reduce, | ||
| attn_tp_all_gather, | ||
| dp_gather_partial, | ||
| dp_gather_replicate, | ||
| dp_scatter, | ||
| get_attention_cp_rank, | ||
| get_attention_cp_size, | ||
|
|
@@ -299,7 +300,7 @@ def __init__( | |
| self.hidden_size, | ||
| bias=False, | ||
| quant_config=quant_config, | ||
| reduce_results=attn_tp_size > 1, | ||
| reduce_results=attn_tp_size == get_tensor_model_parallel_world_size() and attn_tp_size > 1, | ||
| prefix=add_prefix("wo_b", prefix), | ||
| tp_rank=attn_tp_rank, | ||
| tp_size=attn_tp_size, | ||
|
|
@@ -513,9 +514,6 @@ def forward( | |
| forward_batch: ForwardBatch, | ||
| ) -> torch.Tensor: | ||
| if not get_attn_tp_context().input_scattered and x.shape[0] == 0: | ||
| assert ( | ||
| not self.wo_b.reduce_results | ||
| ), "short-circuiting allreduce will lead to hangs" | ||
| return x | ||
|
Comment on lines
821
to
822
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the assertion that checks While the logic for |
||
|
|
||
| attn_backend = forward_batch.attn_backend | ||
|
|
@@ -590,6 +588,8 @@ def forward( | |
| o = torch.einsum("tgd,grd->tgr", o, wo_a) | ||
|
|
||
| o, _ = self.wo_b(o.flatten(1)) | ||
| if self.tp_size > 1 and self.tp_size < get_tensor_model_parallel_world_size(): | ||
| o = attn_tp_all_reduce(o) | ||
|
|
||
| return o | ||
|
|
||
|
|
@@ -820,7 +820,10 @@ def forward( | |
| input_ids_global = input_ids | ||
| elif _use_tp_moe_gather: | ||
| hidden_states, local_hidden_states = get_global_dp_buffer(), hidden_states | ||
| dp_gather_partial(hidden_states, local_hidden_states, forward_batch) | ||
| # hidden_states here follow TP_ATTN_FULL semantics: they are replicated | ||
| # within an attention-TP group. Use replicate gather to avoid summing the | ||
| # same activations across attention-TP ranks before entering MLP/MoE. | ||
| dp_gather_replicate(hidden_states, local_hidden_states, forward_batch) | ||
| _a2a_scatter_chunks: Optional[List[torch.Tensor]] = None | ||
| if _use_tp_attn_a2a_scatter: | ||
| s, r = get_attention_tp_size(), get_attention_tp_rank() | ||
|
|
@@ -939,7 +942,9 @@ def forward( | |
| dtype=input_ids.dtype, | ||
| device=input_ids.device, | ||
| ) | ||
| dp_gather_partial(input_ids_global, input_ids[:, None], forward_batch) | ||
| # Token ids are replicated within an attention-TP group. Use replicate | ||
| # gather here to avoid summing duplicated ids when attention_tp_size > 1. | ||
| dp_gather_replicate(input_ids_global, input_ids[:, None], forward_batch) | ||
| input_ids_global = input_ids_global.squeeze(-1) | ||
| else: | ||
| input_ids_global = input_ids | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
and attn_tp_size > 1is redundant here.get_tensor_model_parallel_world_size()is 1,attn_tp_sizeis also 1, makingattn_tp_size > 1false. The whole expression is false.get_tensor_model_parallel_world_size()is greater than 1, andattn_tp_size == get_tensor_model_parallel_world_size(), thenattn_tp_size > 1is implicitly true.The
RowParallelLinearlayer already checks iftp_size > 1before performing an all-reduce, so settingreduce_results=Truewhentp_size=1has no effect. Simplifying this condition improves clarity.