Skip to content

Molmo2-Stage1: train the ViT as a third optimizer group (mm_olmo ft_vit parity) - #820

Merged
jason718 merged 1 commit into
allenai:visionfrom
jason718:jasonr/stage1-train-vit
Aug 12, 2026
Merged

jason718 merged 1 commit into
allenai:visionfrom
jason718:jasonr/stage1-train-vit

Conversation

@jason718

Copy link
Copy Markdown
Contributor

mm_olmo's captioner sets ft_connector / ft_vit / ft_llm all true and gives the ViT its
own optimizer group, so it trains three component groups. This script froze the encoder
with freeze_params=["vision.*"] and trained two.

TRAIN_VIT (default True) unfreezes the encoder and adds the vision group. It overrides
only the learning rate, inheriting betas=(0.9, 0.95), eps=1e-6 and weight_decay=0.0
from the top-level AdamWConfig — exactly what mm_olmo configures for the ViT
(vit_betas=[0.9,0.95], vit_eps=1e-6, vit_weight_decay=0.0), so there are no redundant
overrides.

Group LR Warmup betas / eps / wd
connector.* 2e-4 200 (0.9, 0.95) / 1e-6 / 0.0
vision.* 6e-6 2000 (0.9, 0.95) / 1e-6 / 0.0
LM (default) 2e-5 2000 (0.9, 0.95) / 1e-6 / 0.0

All three cosine-decay to alpha_f=0.1.

This matters more since #818. Stage 1 now starts from base checkpoints, so the encoder is
base SigLIP2 rather than a trained Molmo2 ViT — freezing it was leaving the vision tower at
its pretraining state for the entire run.

--train_vit=false restores the frozen two-group setup, including putting the encoder back in
eval mode: the train module keys that off freeze_params, so the empty list is what keeps
it in train mode.

Ported from de031c61f on jasonr/molmo2-infra-compare, minus that branch's unrelated
SEQUENCE_LENGTH change, and promoted from a module constant to a CLI-overridable field.
train_vit is resolved from the raw overrides before Config.merge runs — like
model_size / init_from — because it shapes freeze_params, the optimizer groups and the
per-group scheduler, all built pre-merge. The merged config is then re-checked against the
resolved value so a stray override cannot slip through.

Verified on CPU

Three real optimizer param groups bind (not just config fields) on a tiny model:
connector 11 params @ 2e-4, vision 51 params @ 6e-6, LM 47 params @ 2e-5 — each with
betas (0.9, 0.95), eps 1e-6, wd 0.0.

Per-group LR curves dispatch correctly through PerGroupScheduler:

  step |   connector      vision          LM
     1 |   1.000e-06   3.000e-09   1.000e-08
   200 |   2.000e-04   6.000e-07   2.000e-06   <- connector peaks
  2000 |   1.986e-04   6.000e-06   2.000e-05   <- ViT + LM peak
 32000 |   2.000e-05   6.000e-07   2.000e-06   <- all at 0.1x

The FSDP lockstep invariant still holds with a trainable ViT. Every rank must produce
vision gradients every step or the collectives desync, and the mixture hands some ranks
all-text microbatches. Tested directly: on an all-text batch (the collator's dummy zero crop,
all--1 pooled) all 51 vision params still receive finite gradients via the existing
h + 0.0 * image_features.sum() tie. That tie was added for the connector; it covers the ViT
too, since the gradient path runs vision → connector → image_features.

--train_vit=false yields two groups and freeze_params=["vision.*"].

242 passed / 17 skipped across src/test/nn/vision and src/test/data/multimodal;
isort/black/ruff/mypy clean. No test was added for the script's own config — no training
script in this repo has one — so the above is local-run verification.

Cost to budget for

4B 8B
Trainable params 4.079B → 4.462B (+9.4%) 8.280B → 8.662B (+4.6%)
Extra AdamW state (2 × fp32) +2.85 GiB +2.85 GiB
Extra gradients +1.42 GiB +1.42 GiB

Plus ViT backward activations for the 382.5M-param encoder.
vision_activation_checkpointing already defaults to True in the train module and now
actually earns its keep. Given the 4B peaked near 44 GiB with a frozen ViT, the 8B with a
trainable one is where --train_module.response_logits_only=true and an LM ac_config stop
being optional — both still open follow-ups from the mm_olmo comparison.

…it parity)

mm_olmo's captioner sets ft_connector/ft_vit/ft_llm all true and gives the ViT its
own optimizer group (vit_learning_rate=6e-6, vit_weight_decay=0.0,
vit_betas=[0.9, 0.95], vit_eps=1e-6, cosine warmup 2000 / alpha_f=0.1), so it
trains three component groups. This script froze the encoder with
freeze_params=["vision.*"] and trained two.

`TRAIN_VIT` (default True) unfreezes the encoder and adds the vision group. The
group overrides only the learning rate, inheriting betas (0.9, 0.95), eps 1e-6 and
weight decay 0.0 from the top-level AdamWConfig — which is exactly what mm_olmo
configures for the ViT. `--train_vit=false` restores the frozen two-group setup,
including putting the encoder back in eval mode (the train module keys that off
`freeze_params`, so an empty list keeps it in train mode).

Ported from de031c6 on jasonr/molmo2-infra-compare, minus that branch's
unrelated SEQUENCE_LENGTH change, and promoted from a module constant to a
CLI-overridable field. `train_vit` is resolved from the raw overrides before
`Config.merge` runs, like model_size/init_from, because it shapes freeze_params,
the optimizer groups and the per-group scheduler — all built pre-merge; the merged
config is then re-checked against the resolved value.

This matters more now that stage 1 starts from base weights (#818): the encoder is
base SigLIP2 rather than a trained Molmo2 ViT, so freezing it was leaving the
vision tower at its pretraining state for the whole run.

Verified on CPU:
- Three real optimizer param groups bind on a tiny model: connector 11 params
  lr 2e-4, vision 51 params lr 6e-6, LM 47 params lr 2e-5 — all with
  betas (0.9, 0.95), eps 1e-6, wd 0.0.
- Per-group LR curves dispatch correctly through PerGroupScheduler: connector
  peaks 2e-4 at step 200, ViT 6e-6 at 2000, LM 2e-5 at 2000, each cosine-decaying
  to 0.1x by step 32000.
- The FSDP lockstep invariant still holds with a trainable ViT: on an all-text
  microbatch (collator's dummy zero crop, all-(-1) pooled) every one of the 51
  vision params still receives a finite gradient via the
  `h + 0.0 * image_features.sum()` tie, so the vision all-gather and
  reduce-scatter fire on every rank each step.
- `--train_vit=false` yields two groups and freeze_params=["vision.*"].
- 242 passed / 17 skipped across src/test/nn/vision and src/test/data/multimodal;
  isort/black/ruff/mypy clean.

Cost: trainable params 4.079B -> 4.462B for the 4B (+9.4%; 8.280B -> 8.662B, +4.6%
for the 8B), plus ~2.85 GiB of fp32 AdamW state and ~1.42 GiB of gradients for the
382.5M-param encoder, and ViT backward activations. `vision_activation_checkpointing`
already defaults to True in the train module, which now actually earns its keep.
@jason718
jason718 merged commit 7cb7c4c into allenai:vision Aug 12, 2026
1 check passed
@jason718
jason718 deleted the jasonr/stage1-train-vit branch August 12, 2026 18:37
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.

1 participant