Skip to content

Mixed midtraining: opt-in crop balancing for the vision encoder - #923

Merged
jason718 merged 2 commits into
jasonr/olmo35-mixed-midtrainingfrom
rustins/crop-balance-training
Oct 16, 2026
Merged

jason718 merged 2 commits into
jasonr/olmo35-mixed-midtrainingfrom
rustins/crop-balance-training

Conversation

@RustinS

@RustinS RustinS commented Oct 15, 2026

Copy link
Copy Markdown

Stacked on #916: two commits on top of its head (8f8ae5d), off by default.

Summary

Two commits, reviewable separately:

  1. 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 one all_to_all_single so each
    rank 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.
  2. The wiring, behind balance_vit_crops (off by default):
    • MultimodalLM.set_crop_balance_group(group): in training forwards the vision encoder's crops are
      shared evenly among the ranks of group, in place of sync_vit_crops' padding and barrier.
      Evaluation forwards are unchanged. pop_crop_balance_counts() hands the per-rank crop counts to
      the train module.
    • MultimodalOLMoDDPTrainModuleConfig.balance_vit_crops: the train module creates the exchange's
      own process group (so it never queues behind MultiGroupDDP's asynchronous gradient
      all-reduces) and records vision/encoder crops per rank and
      vision/encoder crops per rank unbalanced.
    • MixedMidtrainingRecipeConfig.balance_vit_crops: --recipe.balance_vit_crops=true.
    • MULTIMODAL_OVERRIDES lists 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

GPUs s/step off s/step on Speedup Busiest rank's crops per step, off / on Rank-0 peak reserved, off / on
8 (one node, 8 steps) 92-102 66-67 1.47x
16 58.7 35.7 1.64x 5,190 / 728 173 / 162 GiB
32 32.1 19.3 1.66x 2,955 / 368 168 / 153 GiB

Training dynamics, mean CE by window (off / on):

Steps 16 GPUs 32 GPUs
1-10 1.6917 / 1.6917 1.6961 / 1.6962
11-50 1.5964 / 1.5968 1.5957 / 1.5947
51-100 1.5091 / 1.5091 1.5100 / 1.5100
101-150 1.4694 / 1.4693 1.4682 / 1.4683
151-200 1.4440 / 1.4439 1.4441 / 1.4441
  • CE differs by at most 0.0001 over steps 1-10. The per-step gap from bf16 rounding peaks early,
    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.
  • Load-balancing loss is equal to 4 decimals at every step; grad norm differences are within
    run-to-run noise (steps 151-200: 0.161 / 0.152 at 16 GPUs, 0.180 / 0.159 at 32 GPUs).
  • At 32 GPUs, steps 2-5 held no images on any rank. There balancing was 0.8-2.4 s slower
    (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.
  • Data wait is unchanged (median 0.05-0.07 s); the balanced 32-GPU run had one 5.4 s data wait on
    its fresh nodes.
  • The step-1 grad norm is about 4.6M in every run, with or without balancing (pre-existing,
    clipped to 1.0).

90/10 split, 16 GPUs

--recipe.visual_data=stage1_v3 --recipe.text_loss_share=0.9 with the 21,000-step schedule of
the v3 90/10 run, same parent, 200 steps, balancing off and on.

s/step, median steps 11-200 Busiest rank's crops per step Rank-0 peak reserved
Off 75.1 6,668 181 GiB
On 62.3 3,753 175 GiB
  • Balancing gains 1.21x here. Nearly every rank holds images in most micro-batches, so the busiest
    rank encodes only 1.8x the average (7x on v4), and the encoder's total work dominates the step.
  • CE differs by at most 0.0015 per step (step 35) and by at most 0.0001 after step 100; the
    load-balancing loss differs by at most 0.0002.
  • Data wait is not a factor (median 0.35 s off, 0.32 s on).

For scale, the text-only merged MT+LC stage on 16 GPUs, 200 steps:

16 GPUs, 200 steps s/step vs text-only
Text-only merged MT+LC 15.0 1.0x
v4, balancing on 35.7 2.4x
v4, balancing off 58.7 3.9x
90/10, balancing on 62.3 4.2x
90/10, balancing off 75.1 5.0x

Tests

  • crop_balance_test.py: the plan (even shares, routing out and back restores every rank's own
    crops in order, ranks without crops), balanced_encode against each rank encoding its own
    crops 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 unbalanced encode_images give the same features
    and 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.
  • Related suites: 297 passed. The one failure, 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), which
    takes no arguments).
  • Planting a crop-order bug in balanced_encode fails 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

RustinS and others added 2 commits October 14, 2026 20:12
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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T06:55:51.994593Z 80600a1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +936 to +938
if balance_vit_crops and is_distributed():
group = dist.new_group(group_desc="vit_crop_balance")
self.multimodal_model.set_crop_balance_group(group)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@jason718
jason718 merged commit 1a2064c into jasonr/olmo35-mixed-midtraining Oct 16, 2026
1 check passed
@jason718
jason718 deleted the rustins/crop-balance-training branch October 16, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants