Repository navigation
Conversation
Summary: - add optimizer-step batch grouping and trainer consumption - add deterministic whole-microbatch planning for packed text - add replicated input coordination, metrics, and checkpointing - document the final design Test Plan: - 112 focused CPU tests passed - two-rank DCP and torch_checkpointing round trips passed - 10-step two-GPU balance run passed - pre-commit passed except unavailable pyrefly executable
Contributor
|
We discussed the design offline. But I have a few meta questions:
|
Contributor
Author
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An attempt to implement a load balancer at dataloader level.
Problem
The attention workload depends quadratically with respect to the individual document lengths within a sequence.
So, even if all DP ranks get the same length sequences, their total workload may differ, leading to imbalance and stragglers.
Constraint
Ideally, we should not change which samples are used for a single optimization step.
This limits how much you can balance.
Consider the example, DP = 4, and the input microbatches have the following workload
It is impossible to achieve load balance, rank 0 will be the straggler and the total time would be approximately 40.
Another problem is with respect to packing.
Suppose DP = 2 and
seq_len = 10.Rank 0 gets documents
a, bwith lengths6, 4.Rank 1 gets documents
c, dwith lengths9, 1.It may not be possible with rearrange the documents across the microbatches because there may be no other way to pack.
Lastly, we may not be able to balance within the whole DP group when DP degree becomes large.
Solution
We set a DP balance group size that we try to balance among the whole optimization step microbatches.
For example, if PP = 4, grad acc = 2, DP balance group size = 8, we shuffle the 4 * 8 * 2 many microbatches around.
Example with PP = 1 grad acc = 2, DP = 2
[8][4, 4][2, 2, 2, 2][1]documentsLet
G = grad acc steps, D = DP balance group size, P = PP degreeAlgorithm goes by:
G * D * Pmicrobatches from high to low workloadifrom 1 toGD * Pmany next microbatches to the DP ranks to minimize the total PP workSee also #3938 for RL side load balancing.
There are some choices to be made in the implementation.
G * D * Pmicrobatches from the dataloader.But one may also consider each DP rank reading
G * P, communicating metadata, make a balancing plan, and communicate the inputs.Implementation
To be extensible, I took inspiration from MoE routed experts, where there the
token_dispatcherdoesdispatchandcombinewhile theinner_expertsdoes the computation.Components and responsibilities
LoadBalancingDataLoaderInputCoordinatorTokenizedTextPackingAdapterpositions, padding masks, labels, or model kwargs. A different input format can supply another adapter.QuadraticAttentionCostWholeMicrobatchBalancerThe coordinator abstraction is needed because it owns both sides of routing:
which payloads are visible before planning and how planned assignments become
local payloads afterward. The loader cannot own those details without assuming
a particular input topology.
Data flow
collect()receives the itemization callback because the coordinator owns theinput reads, while the loader owns the adapter and cost model. This arrangement
also fits a future coordinator that first inspects local payloads, exchanges
only metadata, and later exchanges reassigned tensors.
Limitations
The prefetch does not include load balancing, so if it takes long, it may not be hidden in the computation.