Skip to content

OLMo 3.5 alignment: v3 Stage-1 data, stage design and eval export (multimodal-only, Molmo2 unchanged) - #918

Merged
jason718 merged 5 commits into
visionfrom
jasonr/olmo35-alignment-v3-and-stages
Oct 6, 2026
Merged

jason718 merged 5 commits into
visionfrom
jasonr/olmo35-alignment-v3-and-stages

Conversation

@jason718

@jason718 jason718 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Moves four multimodal-only pieces that the OLMo 3.5 alignment runs already use from run branches into vision, so the mixed-midtraining PR (#916) only carries midtraining and #885:

  1. OLMo 3.5 adapters for the Molmo2 Stage-1 sources (academic QA, OCR caption tars, olmOCR, PixMo-Points v2, synthetic OCR, text-rich captions, sft_common): the LM's own token ids, the document layout used with KDA language models, one sampled annotation per example, per-call epochs. All opt-in; Molmo2's defaults are unchanged.
  2. --recipe.data=stage1_v3 for alignment's perception and joint, with calibrated per-source mean loss weights (the v3 loss shares: caption 39.2 / pointing 12.6 / OCR 39.3 / academic 8.8 / clocks 0.08%).
  3. Stage design: recipe.steps (one knob for the training length and every schedule horizon), perception and joint started from the text LM, and bridge's connector schedule for a freshly initialized connector. Used by the stage ablations and the current 14T run.
  4. src/scripts/export_multimodal_olmoddp.py: exports a multimodal OLMoDDP checkpoint for the stage-1 eval (verified against the train module's own loader).

Nothing on vision changes

  • Molmo2 Stage-1 v1, v2 and v3, and Stage 2: loader batches identical. The first 4 global batches of each, built exactly as Molmo2-Stage1.py (--recipe=v1|v2|v3) and Molmo2-Stage2.py build them, on ranks 0 and 3 of 8: every tensor's dtype, shape and SHA-256 match between vision (4d1c8f4) and this branch (8 of 8 comparisons IDENTICAL).
  • Alignment defaults unchanged: resolved bridge, perception and joint configs are identical to vision except two new recipe fields at their defaults (data='alignment', steps=None).
  • Tests: 1,129 passed across src/test/internal, nn/vision, data/multimodal, train/train_module, optim; the one failure (nn/vision/parity_test.py::test_clip_parity) fails identically on vision.
  • GPU: these commits trained the 8T v3 alignment (perception 2,000 + joint 1,500 steps), the five-way stage ablation, and the running 14T alignment.

🤖 Generated with Claude Code

…all epochs

Lets the Molmo2-Stage1 v3 sources serve a document-mode LM (OLMo 3.5's KDA model). Defaults are
unchanged: Molmo2-Stage1 --recipe=v3 loader batches (ranks 0 and 1) and 312 per-source examples
at epochs 0/1 are byte-identical before and after.

- OlmOcrMix, OcrCaptionTars, NvidiaSynthOcr, SyntheticReceipts, TextRichCaption, Stage1Academic,
  PixMoPointsV2 and PixMoCountV2 configs gain token_ids (default Qwen ids) and message_format
  ("qwen3" default / "document"), threaded into encode_sft_example and truncation
  (truncate_for_format protects every image token in the document layout).
- annotation_sampling ("all" default / "one") on TextRichCaption (one level), Stage1Academic (one
  question) and PixMoPoints/CountV2 (one branch, via _build_example's callable convention),
  chosen with pixmo_points.select_annotation(seed, index, epoch, count).
- EpochSeededExamples.get(index, epoch): the continuous-stream loader's per-source epoch seeds the
  row without touching the shared epoch (thread-safe), with deterministic bad-row skipping. The
  __getitem__ path (Molmo2-Stage1) is unchanged.
- Stage1Academic and PixMoPoints/CountV2 accept max_sequence_length (unset by default).
Perception and joint can train on the Molmo2-Stage1 v3 mixture (caption / pointing v2 / OCR /
academic QA / clocks, 28 sources with v3's prompt tags) instead of the alignment sources. Bridge
stays caption-only and refuses the switch; phases, trainable parts, LRs, text-side settings,
8,192-token packing and the joint text replay split with 16/112 quotas are unchanged. The default
(recipe.data=alignment) builds byte-identical bridge and perception batches.

- build_stage1_v3_sources: v3's source configs, serialized as documents, loss_token_weighting
  "none", truncated at the sequence length; PixMo-Cap split into pixmo_caption (long_caption:)
  and pixmo_transcript (transcript:) over the prepared caption selection, so validation stays
  image-disjoint. Document-mode LMs get one annotation per example (annotation_sampling="one").
- Loss targets match v3's per-source loss shares: target_i = r_i * m_i(v3), with r_i the v3
  run's example rates and m_i(v3) the mean loss weight per example on the v3 Stage-1 path (Qwen,
  all annotations, caption message_weight 1.25; pixmo_cap split by branch). Group split: caption
  39.2 / pointing 12.6 / OCR 39.3 / academic 8.8 / clocks 0.08. Means for sampling come from
  estimate_mean_loss_weights (128 samples, seed 0) on the dolma2 / document / one-annotation
  path at 8,192. Joint scales the visual targets into its 0.65 share.
- The has_calibrated_artifacts gate is skipped for stage1_v3 (tokenizer, revision and sequence
  checks stay); missing means for stage1_v3 are a configuration error.
- Validation keeps the alignment sources and adds v3_long_caption / v3_transcript.
- Launch post_setup adds pip install -U 'datasets>=4,<6' pypdfium2 h5py for stage1_v3 only.
…tage ablations)

recipe.steps sets trainer.max_duration and every component's LR horizon
(bridge's connector decay scales with it; warmups and alpha_f unchanged).
Perception and joint with no parent_checkpoint start from
pretraining_checkpoint exactly like bridge (initialize_multimodal, fresh
connector and image rows, LB off while the LM is frozen) under their own
phase policy. Joint accepts a bridge or perception parent.
Default resolved configs are unchanged.
… connector schedule

A perception or joint stage started from the text LM has a freshly initialized connector and
image-token rows. Train them with bridge's connector peak (2e-4), warmup (100) and decay length
(250); the 10% floor equals the later phases' own connector LR, so the ablation variants
(no bridge, no stages) are not handicapped by a connector LR tuned for a warm connector.
Multimodal OLMoDDP checkpoints keep no model.* keys (trainable parameters live only as
flattened FP32 optimizer main params, frozen ones as frozen_model.<name>), so neither
unshard.py nor olmo-eval's olmo_core_vlm provider can read them. The script writes the
model state dict as model.safetensors plus olmo_core_config.json, bf16 by default (the
dtype the train module runs the model in); --verify checks every tensor bit for bit
against the train module's own eval-only loader.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 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-06T02:50:10.649947Z a89c237 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.

@jason718
jason718 merged commit 6b109c6 into vision Oct 6, 2026
1 check passed
@jason718
jason718 deleted the jasonr/olmo35-alignment-v3-and-stages branch October 6, 2026 02:46

@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: a89c237552

ℹ️ 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".

train_module.expand_shared_qk_norm_on_load = False
dcp_dir = str(step_dir / "model_and_optim")
reader = RemoteFileSystemReader(dcp_dir)
train_module._load_model_state_dict_direct(reader.read_metadata(), dcp_dir, reader, None)

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 Load persistent buffers before verifying the export

When --verify is used on a checkpoint with persistent model buffers (for example, an MoE router's updated score_bias), this parameter-only loader leaves those buffers at their fresh initialization while export_state_dict() has correctly included their model_buffer.* checkpoint values. The subsequent comparison therefore reports a mismatch and makes verification fail for such checkpoints; load _persistent_model_buffer_state_dict() entries as the regular train-module load path does before comparing.

Useful? React with 👍 / 👎.

jason718 added a commit that referenced this pull request Nov 10, 2026
…1.py (#913)

## Summary

PR 4 of 7 for moving the Molmo2 stage-1 reproduction from the long-lived
`vision` branch onto `main`. #910 (model), #911 (train module) and #912
(data core) are merged; this PR adds the **stage-1 recipe** that makes
them runnable end to end: the datasets, the mixtures, and
`Molmo2-Stage1.py`.

About 6.7k source lines and 4.8k test lines. It also restores one fix
needed for the recipe to train correctly: activation-checkpoint RNG
replay (see "Why the RNG fix is here"). Almost all of it is new files;
the only existing files touched are listed under "Read closely" below.

## Review map

Reading every file closely is not necessary. Here is where attention
pays off.

### Read closely (about 1.9k lines)
| File | Lines | What to check |
|---|---|---|
| `scripts/train/Molmo2-Stage1.py` | 1537 | The recipe itself: the `v1`
/ `v2` / `v3` mixture rates, step counts, optimizer groups and learning
rates, the `--init_from` paths, and the launch settings. This is where a
wrong constant changes the training run silently. |
| `train/callbacks/unsharded_export.py` | 128 | Writes
`model.safetensors` and a config copy into each permanent checkpoint
from a background op on rank 0; skips ephemeral checkpoints. Moved here
from #911 because the stage-1 script is its only user. |
| `distributed/checkpoint/__init__.py` | +30 |
`load_unsharded_model_state()`: the only change to a shared distributed
module. Additive. |
| `nn/transformer/model.py` (+`ac_rng_test.py`) | +24 / -4 | Activation
checkpointing now preserves the RNG state when dropout is active
(`masked_dropout`, `ResidualStream` dropout, `nn.Dropout`), so the
recomputed forward replays the original dropout masks. Required by this
recipe; see below. |
| `data/multimodal/__init__.py`, `sequence_builder.py` | +92 / +4 |
Exports, and a type annotation on `build_branched_sequence` that already
accepted multi-turn branches. No behaviour change. |

### Skim for the shared pattern (about 4.9k lines of dataset code)
These are adapters. Each one defines a config dataclass and a map-style
dataset, formats its rows into the stage-1 prompt family, builds the
sequence with the #912 builders, and truncates with `truncate_example`.
Seven of them (`academic_dataset`, `gui_syn`, `ocr_caption_tars`,
`olmocr`, `pixmo_points_v2`, `synthetic_ocr`, `text_rich_caption`) use
the `EpochSeededExamples` mixin from #912 for epoch-aware sampling; the
others do not sample per epoch. If one is right, the rest are
variations.

| Group | Files |
|---|---|
| Pointing and counting | `pixmo_points.py` (433), `pixmo_points_v2.py`
(579), `gui_syn.py` (243), `detect_counting_question.py` (82) |
| OCR | `olmocr.py` (328), `ocr_caption_tars.py` (366),
`synthetic_ocr.py` (384), `text_rich_caption.py` (200),
`mixtures/ocr.py` (245) |
| Academic QA | `academic/registry.py` (611), `academic_dataset.py`
(179), `academic/formatters.py` (102), `mixtures/stage1_academic.py`
(149) |
| Other sources | `pixmo_clocks.py` (145), `pixmo_cap_qa.py` (104),
`pixmo_ama.py` (96), `tulu.py` (173), `finevision.py` (249),
`mmfinereason.py` (218) |

### Tests (about 4.8k lines)
They mirror the modules above (one test file per dataset group), plus
`molmo2_training_logits_parity_test.py` (GPU, needs the HF checkpoint)
and the callback and distributed-checkpoint tests. A test that needs
Weka data skips when the data is absent.

### Invariants the design relies on (worth a spot check)
These are stated in the script's docstring and should hold across every
file:
- Every default source is a **train split only**; the training set of a
benchmark the stage-2 checkpoints are evaluated on is never a stage-1
source.
- OCR and academic sources use a **style tag as the whole user turn**,
with no question text.
- Data lives on Weka, so datasets read paths from `paths.py` (#912) and
nothing here needs S3 or GCS secrets.
- Mixture rates per recipe are as in the script's docstring: `v1`
caption 0.6 / pointing and counting 0.3 / text 0.1; `v2` caption 0.5 /
pointing 0.25 / OCR 0.25; `v3` caption 0.33 / pointing 0.16 / OCR 0.34 /
academic 0.14 / clocks 0.03.

## Series

| # | PR | Status |
|---|---|---|
| 1/7 | #910 Model: HF Molmo2 loader, flex attention, split-vocab
embedding | merged |
| 2/7 | #911 Train module, `PerGroupScheduler`, weighted CE | merged |
| 3/7 | #912 Data core | merged |
| 4/7 | #913 Stage-1 recipe **(this PR)** | review |
| 5/7 | #934 Data infrastructure, stage-2 recipe, Qwen3-0.6B / 1.7B
sizes | draft, stacked on this PR |
| 6/7 | #936 OLMo 3.5 alignment training: OLMoDDP hooks and train
module, optimizer, callbacks, alignment pipeline | draft |
| 7/7 | #937 In-repo evaluation suites and remaining tools | draft |
| 8 | #938 Stable mixed mid-training (from #916) | draft |
| 9 | #939 Still-changing mixed mid-training (from #916) | draft |

PRs 5 to 7 bring the rest of `vision` onto `main`, so that `main` can do
everything `vision` can. Separate: activation-checkpoint RNG replay for
`ResidualStream.masked_dropout` is already in this PR; #906 (open) will
need a rebase on it.

## Why this is a separate PR

- It is the bulk of the series, but the review is mostly
pattern-checking, and it is the only part that depends on external data
locations and recipe choices.
- It can be iterated (new datasets, recipe tweaks) without touching any
core API from #910 to #912.
- It is what makes stage 1 runnable, so it is where the end-to-end
evidence belongs.

## Does this change anything on `main` / the text side?

No intended text-side change. The shared files it touches are the
additive checkpoint helper, the callbacks `__init__` export, a type
annotation, and the activation-checkpointing change in
`nn/transformer/model.py`. That last one changes behaviour only for
models that use dropout together with activation checkpointing (their
recompute now replays the dropout masks, which it previously did not);
with `dropout=0`, the default, text models are unaffected. For the
series as a whole, text-side outputs (weights, logits, loss and
gradients) were compared bit for bit against `main` on CPU and match,
and the existing test suites show no regressions. Text GPU and
distributed paths (FSDP2, TP, CP) cannot run on the CPU box I used, so
CI's GPU jobs are the check there.

## Why the RNG fix is here

Stage 1 trains with full activation checkpointing and 10% response-token
residual dropout. Without replaying the RNG, the recompute draws
different dropout masks than the original forward, so gradients are
taken against a different sample than the loss. This was held out of
#910 because #906 (open) rewrites the same lines; the end-to-end parity
run below showed it cannot be left out of the recipe: without it the run
trains much worse than `vision` (final loss 1.83 vs 1.19). The change
here is `vision`'s own fix (#828) unchanged, with its test. #906 fixes
the general case differently and will need a rebase on top of this.

## Not included (stays on `vision`)

Stage 2 (`Molmo2-Stage2.py`, `image_only_v9`, multi-image datasets,
`compare_sft_example.py`), the stage-1 data infrastructure upgrades, and
the OLMo 3.5 alignment work; see the plan above.

## Testing

**CPU:** `src/test/data`, the callback and distributed-checkpoint tests:
462 passed, 0 failed (before the last test-only fix below). ruff, black,
isort and `mypy src/` (the CI config) are clean. `Molmo2-Stage1.py
dry_run` resolves for the default, `--recipe=v2` and `--recipe=v3` (32k
and 50k steps). One test (`test_st_qa_train_validation_split`) read a
Weka path with no skip, which failed on the CI runner; it now skips when
the data is absent.

**GPU smoke (Beaker, 8x GPU, FSDP2):** an earlier 30-step run of the
stack: CE loss 3.23 → 2.57, checkpoint and unsharded export written.

**End-to-end parity on Beaker** (`ai2/molmofication`, Holmes, allocated,
`--recipe=v3`, 1 node x 8 GPUs, 2000 steps, same seed and arguments; W&B
disabled because `BeakerCallback.pre_train` calls `wandb.Run.get_url()`,
which the image's `wandb` lacks, existing code unrelated to this
series). V is the control: `vision` at the commit this series was cut
from.

| Run | Code | Result |
|---|---|---|
| [V](https://beaker.org/ex/01M5N24PSKG4EYXQNXQ7KK45XC) | `vision` @
`f639a28` (control) | CE 3.16 -> 1.20 |
| [P](https://beaker.org/ex/01M5N222MQ1JSY1TBDWY3YZBEY) | this PR
**without** the RNG fix | trains worse than V, gap grows: +0.05 (steps
1-50), +0.41 (201-500), +0.60 (1501-2000); final-100-step CE 1.83 vs
1.20 |
| [P2](https://beaker.org/ex/01M5NWNH21XHNA9WFKPJRARQHS) | this PR
**with** the RNG fix | tracks V |

Windowed mean CE, with the fix (P2) against the control (V):

| steps | P2 | V | P2 - V |
|---|---|---|---|
| 1-50 | 2.619 | 2.619 | +0.000 |
| 51-200 | 2.114 | 2.096 | +0.018 |
| 201-500 | 1.638 | 1.640 | -0.002 |
| 501-1000 | 1.326 | 1.315 | +0.011 |
| 1001-1500 | 1.248 | 1.238 | +0.011 |
| 1501-2000 | 1.199 | 1.201 | -0.002 |

Last 100 steps: P2 1.192, V 1.197. The offset has no trend (-0.002 per
1000 steps; without the fix, +0.195 per 1000 steps). Two identical-code
runs (P and R1) differ by about 0.015 per logged point, so window means
agree within about that. Per-point differences between P2 and V are
larger (stdev 0.057) because the data draws differ on purpose: the
review fixes made PixMo-Cap sampling epoch-aware.

Caveats: one run per arm. The gradient norm is spiky; P2 had two
transient spikes (step 300: 30, step 455: 37.6) that V did not, with
normal loss at those steps and clipping at 1.0 (the unfixed run spiked
as high as 165). I cannot tell noise from a small residual difference
from single runs.

**Checkpoint and resume:** run
[R1](https://beaker.org/ex/01M5N222PV51TWTJ7YR9KXWWNP) (1000 steps)
wrote a checkpoint;
[R2](https://beaker.org/ex/01M5NS0S9NSNFQGJBQVDGF2ENE) resumed it from
step 1000 to 2000 (first logged step 1005). Over steps 1001-2000 its
loss differs from the uninterrupted run P by +0.003 on average (stdev
0.013), inside the same-code noise. The unsharded `model.safetensors`
export was written. This pair ran on the code before the RNG fix; resume
does not depend on it, but I have not rerun it on the final code.

**Second parity check: Qwen3-0.6B on 2 nodes (16 GPUs), against a
finished `vision` run.** This covers paths the 4B runs above did not:
`response_logits_only=true`, no activation checkpointing, and 16-GPU
FSDP. Reference: `molmo2-stage1-0p6b-v3-50k-20261023` (`vision` HEAD),
whose per-step training loss is readable from its W&B files. Test:
[`mm-e2e-0p6b-main-2k`](https://beaker.org/ex/01M5QC1TVNGX0R8CXF8VZ725C5),
this branch plus `vision`'s #933 (the 0.6B size) cherry-picked, with the
reference's launch arguments, image and environment, stopped at step
2000 by `hard_stop` while keeping its 50k-step LR schedule. Windowed
mean CE:

| steps | run | reference | diff |
|---|---|---|---|
| 1-50 | 4.580 | 4.595 | -0.015 |
| 51-200 | 2.722 | 2.729 | -0.007 |
| 201-500 | 2.383 | 2.380 | +0.002 |
| 501-1000 | 1.738 | 1.737 | +0.002 |
| 1001-2000 | 1.519 | 1.520 | -0.002 |

Last 100 steps: 1.443 vs 1.458; trend of the difference -0.006 per 1000
steps; loss finite throughout. Per-point differences between the two
runs have stdev 0.093, which matches what two independent runs of the
same curve should give (the reference's own per-step noise is about
0.064, so about 0.09 for a difference). Caveat: the reference ran
`vision` HEAD, which includes data-code changes made after this series'
cut point (#902, #903, #918), so this is a sanity check of overall
health, not an apples-to-apples control; the rigorous rerun comes once
those changes land on `main`.

**Offline check, no GPU:** one training step of a tiny multimodal model
on `vision`@cut and on this branch (dropout off) produces bit-identical
loss, gradients and updated weights, so the model and train-module path
is unchanged apart from the RNG fix.

**GPU logit parity vs HF Molmo2 (4B and 8B pass; O-7B skipped):** see
#910.

**Not covered:** long-horizon loss parity against the released
Molmo2-4B-Pretrain recipe (these are 2000-step checks); GPU text-side
paths beyond CI; a resume rerun on the final code.
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