-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[perf, data] feat: DP workload balance #3605
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?
Conversation
root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
Code Review
This pull request introduces workload balancing for Data Parallelism to mitigate the impact of stragglers with longer sequences. The core change is the _balance_data_proto
function, which reorders data within a batch using the Karmarkar-Karp algorithm to equalize workload across DP ranks before splitting. My review has identified a critical bug that breaks data splitting when auto-padding is enabled, and a high-severity issue related to a hardcoded value that limits the feature's general applicability. Addressing these points will improve the correctness and maintainability of the implementation.
# approximate workload of transformer block | ||
workloads = seqlens**2 + seqlens * 33024 |
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 workload calculation uses a hardcoded magic number 33024
. According to the PR description, this is specific to a 7B model's MLP layer. This limits the general applicability of this workload balancing feature to other model architectures.
The function signature includes an unused model_config
parameter, which should be used to pass model-specific configuration, such as the MLP size, to make the workload calculation more flexible and accurate for different models.
Consider refactoring this to use the model_config
parameter. For example:
# approximate workload of transformer block
mlp_factor = model_config.get("mlp_workload_factor", 33024) if model_config else 33024
workloads = seqlens**2 + seqlens * mlp_factor
… batching, adjust micro batch order to reduce PP bubble
5e9feec
to
7432a21
Compare
880688e
to
090a58b
Compare
What does this PR do?
Mitigate workload imbalance in DP.
As shown in the figure below, all ranks must synchronize after mini batch in DP. Stragglers with longer sequences delay all workers.
Checklist Before Starting
[{modules}] {type}: {description}
(This will be checked by the CI){modules}
includefsdp
,megatron
,sglang
,vllm
,rollout
,trainer
,ci
,training_utils
,recipe
,hardware
,deployment
,ray
,worker
,single_controller
,misc
,perf
,model
,algo
,env
,tool
,ckpt
,doc
,data
,
like[megatron, fsdp, doc]
{type}
is infeat
,fix
,refactor
,chore
,test
[BREAKING]
to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batching
Test
The line with the suffix

Balance
in the figure below can get better MFU in Qwen2.5-Math-7 GRPO.API and Usage Example
split Data to n workload balanced chunks
Design & Code Changes
As shown in the figure, the leftmost side shows the unsplit data with a global batch size of 16.
When DP = 2, existing methods directly split the batch into two ranks sequentially. You can see that in this case, rank 0 receives more tokens than rank 1.
The rightmost side shows our design. We model the workload generated by each data entry and use the Karmarkar-Karp algorithm to split the batch into two equal parts, ensuring that the total workload of each part is as close as possible.
The workload can be calculated using the FLOPS formula in verl. Here, we roughly estimate and hardcode the FLOPs by
seqlens**2 + seqlens * 24576
(Attention+MLP of 7B model).Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always
ci-request
channel in theverl
Slack workspace. (If not accessible, please try the Feishu group (飞书群).)