Repository navigation
Mixed midtraining: opt-in crop balancing for the vision encoder - #923
Conversation
Add olmo_core.nn.vision.crop_balance. balanced_encode exchanges the crop counts, sends the crops so that every rank encodes an equal share (to within one crop), and returns the features to the ranks the crops came from, in order. The backward pass returns the feature gradients the same way. Features and summed encoder gradients match unbalanced encoding up to floating-point rounding. Nothing uses it yet; the multimodal model and train module wire it in next. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0159PTUsp2w3YTANVDZ4BUss
MultimodalOLMoDDPTrainModuleConfig.balance_vit_crops (and the mixed mid-training recipe's balance_vit_crops) shares each micro-batch's image crops evenly among all ranks for the vision encoder, through olmo_core.nn.vision.crop_balance. The OLMoDDP MoE language model keeps its ranks in step, so without it every micro-batch waits for the rank holding the most crops. Off by default. - MultimodalLM.set_crop_balance_group: balanced encoding in training forwards, in place of sync_vit_crops' padding and barrier; evaluation forwards are unchanged. - The train module creates the exchange's own process group and records vision/encoder crops per rank, with and without balancing. Features and summed gradients match unbalanced encoding up to floating-point rounding. On the v4 merged mid-training mixture at 16 GPUs, 200 steps on the same data: 35.7 s per step instead of 58.7 s, CE within 0.0002 per step after step 100, load-balancing loss equal. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0159PTUsp2w3YTANVDZ4BUss
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80600a199d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if balance_vit_crops and is_distributed(): | ||
| group = dist.new_group(group_desc="vit_crop_balance") | ||
| self.multimodal_model.set_crop_balance_group(group) |
There was a problem hiding this comment.
Reject crop balancing when vision dropout is enabled
When a trainable vision configuration sets attention_dropout or residual_dropout above zero, redistributing a crop makes it consume the destination rank's RNG stream, and the changed per-rank batch shapes also advance those streams differently. Consequently the returned features and summed gradients are not merely changed by floating-point rounding as the option promises, which can alter experiment trajectories; either reject this combination as trim_microbatch_image_padding already does or preserve rank-independent dropout randomness during the exchange.
Useful? React with 👍 / 👎.
Stacked on #916: two commits on top of its head (8f8ae5d), off by default.
Summary
Two commits, reviewable separately:
olmo_core.nn.vision.crop_balance:plan_crop_balance(counts, world_size)splits all ranks'crops, in rank order, into shares that differ by at most one crop;
balanced_encode(encode, crops, group)all-gathers the crop counts, sends the crops with oneall_to_all_singleso eachrank encodes its share, and sends the features back to the ranks the crops came from, in order.
The backward pass returns the feature gradients the same way. Features and encoder gradients
summed over ranks are those of unbalanced encoding up to floating-point rounding.
balance_vit_crops(off by default):MultimodalLM.set_crop_balance_group(group): in training forwards the vision encoder's crops areshared evenly among the ranks of
group, in place ofsync_vit_crops' padding and barrier.Evaluation forwards are unchanged.
pop_crop_balance_counts()hands the per-rank crop counts tothe train module.
MultimodalOLMoDDPTrainModuleConfig.balance_vit_crops: the train module creates the exchange'sown process group (so it never queues behind MultiGroupDDP's asynchronous gradient
all-reduces) and records
vision/encoder crops per rankandvision/encoder crops per rank unbalanced.MixedMidtrainingRecipeConfig.balance_vit_crops:--recipe.balance_vit_crops=true.MULTIMODAL_OVERRIDESlists the new train-module field (alignment leaves it off).Why
The crops of a packed mixed batch are very uneven across ranks: one rank's micro-batch can hold
hundreds of crops while another's is text only. The OLMoDDP MoE LM keeps its ranks in step (the
router all-reduces its load-balancing statistics in every routed layer), so every micro-batch
costs the busiest rank's encoder time. On the v4 mixture the busiest rank encodes 7-8x the
average.
Results
Beaker, ai2/holmes, the merged MT+LC mixed stage from the noperc-joint step3500 parent, 200 steps
on the same data with balancing off and on. Step times are medians over steps 11-200.
v4 mixture
Training dynamics, mean CE by window (off / on):
at 0.0016 (16 GPUs, step 40) and 0.0025 (32 GPUs, step 37), and stays at or below 0.0002 after
step 100 at both sizes.
run-to-run noise (steps 151-200: 0.161 / 0.152 at 16 GPUs, 0.180 / 0.159 at 32 GPUs).
(13.2-14.4 s against 12.0-13.1 s), either the exchange's fixed cost per micro-batch or the two
runs' different nodes; four steps cannot tell which. Skipping the exchange when the plan keeps
every crop on its own rank would remove the former.
its fresh nodes.
clipped to 1.0).
90/10 split, 16 GPUs
--recipe.visual_data=stage1_v3 --recipe.text_loss_share=0.9with the 21,000-step schedule ofthe v3 90/10 run, same parent, 200 steps, balancing off and on.
rank encodes only 1.8x the average (7x on v4), and the encoder's total work dominates the step.
load-balancing loss differs by at most 0.0002.
For scale, the text-only merged MT+LC stage on 16 GPUs, 200 steps:
Tests
crop_balance_test.py: the plan (even shares, routing out and back restores every rank's owncrops in order, ranks without crops),
balanced_encodeagainst each rank encoding its owncrops for a trainable and a frozen encoder on gloo (4 ranks) and NCCL (2 GPUs), and rejection
of a rank without crops.
multimodal_olmo_ddp_test.py: balanced and unbalancedencode_imagesgive the same featuresand summed vision and connector gradients (gloo, 3 ranks, one holding text only); balancing
applies only to training forwards.
multimodal_ddp_train_module_test.py: a full DDP train step (3 micro-batches,only_allreduce_last_microbatch, 2 GPUs) gives the unbalanced gradients for the vision encoder,connector and LM (relative error about 0.5% from bf16 rounding, versus about 80% with crops
returned in the wrong order), the same CE, and the expected crop metrics; the config round trip
keeps the field.
test_native_checkpoint_loads_into_multimodal_and_roundtrips,fails the same way on [Do not merge yet] Mixed midtraining on OLMo 3.5: the OLMo-core side of scaling-ladders#83 #916's head (it calls
_copy_model_params_to_main_params(names), whichtakes no arguments).
balanced_encodefails all six equivalence tests.How to test
pytest src/test/nn/vision/crop_balance_test.py pytest src/test/nn/vision/multimodal_olmo_ddp_test.py \ src/test/train/train_module/transformer/multimodal_ddp_train_module_test.py -k "balance"The NCCL and full-step tests need 2 GPUs. To rerun the A/B, launch the merged MT+LC mixed stage
twice from the same parent with
'--trainer.hard_stop={value: 200, unit: steps}' --trainer.callbacks.checkpointer.enabled=false, once with--recipe.balance_vit_crops=true.🤖 Generated with Claude Code
https://claude.ai/code/session_0159PTUsp2w3YTANVDZ4BUss