mirror of
https://github.com/deepseek-ai/DeepEP.git
synced 2026-11-05 00:47:32 +00:00
[GH-ISSUE #241] Maybe a Method to Reduce Memory Consumption in Low-Latency Mode #186
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepEP#186
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @yulangz on GitHub (Jun 21, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepEP/issues/241
In low-latency mode, since it's impossible to predict the expert selected for each token beforehand, buffer allocation must be based on the worst-case scenario – assuming all tokens will be sent to a given expert. In reality, a significant portion of the pre-allocated buffer remains unused. I have some ideas that might reduce video memory consumption in low-latency mode:
During the dispatch phase, reserve a
dispatch_recv_data_buffer_bytessize ofredund_ratio * num_topk * num_local_experts * num_max_dispatch_tokens_per_rank * num_bytes_per_dispatch_msg, instead ofnum_experts * num_max_dispatch_tokens_per_rank * num_bytes_per_dispatch_msg. Here,redund_ratiois an empirical value representing the potential extra selections an expert might receive under relatively imbalanced system loads. Assumingredund_ratio=2, num_topk=8, num_experts=256, num_local_experts=1, this would reduce memory usage by a factor of 16.In the actual dispatch phase, to ensure sufficient memory space, the following approach can be adopted:
recv_token_numandfinish_rank_num. The token capacity of recv_bufferlen_{buffer}isnum_max_dispatch_tokens_per_rank * num_topk * redund_ratio.num_{e_i}to be sent to each experte_i.num_{e_i}to the target expert'srecv_token_numfield, and get the return valueslot_{end}.slot_{end} < len_{buffer}, it indicates sufficient space in the target expert's recv_buffer. Copy the tokens to the locationrecvBuffer[slot_{end} - num_{e_i} : slot_{end}].slot_{end} - len_{buffer}, meaning these tokens cannot be sent to the target expert. We need to:num_{block} = min(num_{e_i}, slot_{end} - len_{buffer}), which is the number of tokens that cannot be sent to the target expert.num_{block}tokens and mark them as failed sends.recvBuffer[slot_{end} - num_{e_i} : len_{buffer}].finish_rank_numby 1. In theLOW_LATENCY_DISPATCH_RECVphase, wait forfinish_rank_num == num_ranksto indicate reception completion.Pseudocode:
How to handle discarded tokens? I envision two approaches:
In systems with relatively balanced expert loads, token discarding should occur infrequently, minimizing its overall performance impact.
By reducing
dispatch_recv_data_buffer_bytes, the sizes ofcombine_send_buffer_bytesand packed_recv_x (https://github.com/deepseek-ai/DeepEP/blob/7b0c25f864cc7a2d95d7e3c3c2b7c13b22116063/csrc/deep_ep.cpp#L1089C33-L1089C38) can also be reduced.Assuming num_max_dispatch_tokens_per_rank=128, hidden=7168, num_experts=256, num_ranks=1, redund_ratio=2, this method could reduce the buffer size for
LowLatencyLayoutfrom 1.75GB down to 112MB.By the way, although this method reduces memory consumption, it introduces system complexity. Furthermore, the original 1.75GB also seems like an acceptable size.
I look forward to discussing this with you!
@LyricZhao commented on GitHub (Jun 27, 2025):
I think it is a great idea! For real online services, the buffer size of low-latency kernels is not a problem. But for normal kernels, using a communication queue will lead to performance cost, using an estimated buffer size is a great idea👍🏻
We plan to do a full refactor later in this year, we must have such ideas to be adopted.
@yulangz commented on GitHub (Jul 4, 2025):
Thank you for your appreciation! I am looking forward to seeing refactoring in the future!