Repository navigation
Export unsharded model weights into every permanent checkpoint (stage 1 and 2); keep the last 5 in stage 1 - #893
Conversation
UnshardedModelExportCallback writes model.safetensors (the full model state dict, no optimizer state) and olmo_core_config.json next to model_and_optim/ in each permanent checkpoint, so evals read one file instead of reassembling the weights from every rank's DCP shards (olmo-eval issue #379). It runs on rank 0 in a background bookkeeping thread, re-reading the checkpoint just saved, so it needs no collectives and also works with async checkpointing. Molmo2-Stage1.py enables it. load_unsharded_model_state() is the reader: unlike unshard_checkpoint() and load_keys(), it may run on one rank of a distributed job.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cca6904a1a
ℹ️ 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".
| return | ||
|
|
||
| log.info(f"Exporting unsharded model weights to '{path}'...") | ||
| state_dict = load_unsharded_model_state(join_path(path, "model_and_optim")) |
There was a problem hiding this comment.
Support direct-format checkpoints in the exporter
When this callback is attached to an OLMoDDPTrainModule, its checkpoint is produced by save_state_dict_direct() from the optimizer's flat state dict (<parameter>.main, moments, and model_buffer.*), not the nested {"model": ...} layout this helper loads. load_unsharded_model_state() therefore finds no model entry (or cannot produce model-state keys) and the background export fails, which causes the trainer to abort on the next completion check. Either reject direct-checkpoint train modules explicitly or reconstruct the .main parameter tensors with their original shapes before writing safetensors.
Useful? React with 👍 / 👎.
Each kept checkpoint holds both its DCP state and the unsharded export (about 68 GB). The v2 run scored within about a point across steps 24k-32k, which the last 5 of a 32k-step run cover.
Molmo2-Stage2.py now enables UnshardedModelExportCallback, so its permanent checkpoints also carry model.safetensors + olmo_core_config.json. Its retention is unchanged (the default, last 3).
… steps); drop TallyQA's COCO val2017 images (#887) Based on `vision` at 05885ef (after #875, #893, #894 and the v3.0.0 main sync). Stage 1 is going to be mixed into text midtraining, which has about 100B text tokens, so it needs more distinct multimodal data than PixMo-Cap's ~717k images, which a stage-1 run already sees about 4 times. This PR adds: 1. **An academic QA group** (`--academic_rate`): stage 2's large synthetic QA sets, copied into stage 1 (stage 2 keeps them). The training set of a benchmark stage 2 is evaluated on is never a source. 2. **A PixMo-Clocks group** (`--clock_rate`), so clock reading can be learned without stage 2. 3. **A `v3` recipe** for 50,000 steps: caption 0.33, pointing and counting 0.16, OCR 0.34, academic QA 0.14, clocks 0.03. The default recipe stays `v1` at 32,000 steps. 4. **TallyQA without COCO val2017 images.** This changes stage 2 too, which reads TallyQA's train split. It also makes the stage-1 prompt family tag every style, which the new sources depend on ([Prompt](#prompt)). ## Results The v3 run `molmo2-stage1-4b-v3-50k-20260930` ([beaker](https://beaker.org/ex/01M3R9285B5GT234XXQ644NSR8), 4×8 B300 on holmes, 50k steps, finished 2026-10-01) trained this PR's code at `163d1c1f9` (this PR plus #893). Every file this PR touches is identical to the launch commit, except the removal of the unused share caps, which leaves the mixture weights unchanged (max difference 6e-17). All rows are from olmo-eval #412 with the stage-1 prompts (`-o prompt_templates=none -o system_prompt_style=style_and_length_v2`). v3 and the released checkpoint were scored at #412's `5fc8fa21`. v1 and v2 were scored on 2026-09-27 at `f1f3b2b3`; the caption, pointing and counting task code is the same at both commits. | Metric | Released Molmo2-4B-Pretrain | v1 32k | v2 32k | **v3 50k** | |---|---|---|---|---| | Caption avg | **57.7** | 57.1 | 56.9 | 56.8 | | Caption recall | **44.3** | 43.1 | 43.1 | 43.6 | | Caption consistency | **71.1** | 71.0 | 70.8 | 69.9 | | PixMo-Points F1 | **81.5** | 78.4 | 79.4 | 78.2 | | SA-Co Gold subset F1 | 66.3 | 62.0 | **68.1** | 67.2 | | SA-Co Gold 4k F1 | 55.7 | 54.0 | **83.7** | **83.7** | | SA-Co Gold 4k absent-object accuracy | 48.0 | 46.1 | 84.3 | **84.7** | | PixMo-Count val | 88.5 | 89.6 | 90.4 | **91.3** | | PixMo-Count test | **88.0** | 87.8 | 87.6 | 85.2 | | olmOCR-Bench | 26.5 | 26.5 | 51.1 | **54.0** | | CC-OCR multi-scene, English (macro F1) | 19.6 | 6.1 | 78.4 | **79.2** | | OmniDocBench v1.6 English, text edit (lower is better) | 0.971 | 0.980 | 0.247 | **0.211** | | OmniDocBench v1.5 English, text edit (lower is better) | 0.970 | 0.979 | 0.236 | **0.212** | * **OCR improves.** Against v2: olmOCR-Bench +2.9, CC-OCR +0.8, and OmniDocBench text edit 0.036 lower on v1.6 and 0.024 lower on v1.5. With formula grading (CDM), v3's OmniDocBench overall is 66.7 on v1.6 and 70.3 on v1.5. The v1/v2 eval skipped CDM, so OmniDocBench is compared on text edit only. 9 of the 755 v1.6 pages failed to score for v3. * **Caption and pointing are flat to about 1 point lower.** Caption avg is 56.8 against v2's 56.9 (recall +0.5, consistency −0.9). PixMo-Points F1 is −1.2 and the SA-Co subset −0.9; SA-Co 4k is unchanged. v3 sees caption and pointing data about as often as v2 does (4.2 and 4.4 passes), at lower rates over more steps. * **Counting is mixed.** Val is +0.9 and test −2.4. All answers parse. * **Longer training would not help.** v3 at step 40,000 is within about 1 point of step 50,000 on every caption, pointing, olmOCR-Bench and CC-OCR metric (OmniDocBench was not run at 40k). v2's 24k, 28k and 32k checkpoints were also within about 1 point of each other. * **The released checkpoint** was trained on 0.6 caption and 0.3 pointing. It still leads on caption (+0.9 avg over v3) and PixMo-Points (+3.3), but its SA-Co 4k score is 28 points lower: it handles only 48% of absent-object queries correctly, against v3's 85%. It has no OCR training. Its scores reproduce mm_olmo's own eval of it: PixMo-Points 81.5 vs 81.6, SA-Co 4k 55.7 vs 55.5. Its caption prompt here is `long_caption:` rather than the `long_caption 65:` it was trained on; mm_olmo with that prompt gets avg 58.1 and recall 45.6. * **What these evals do not measure** is the academic QA group (9.1% of v3's loss). Its effect, if any, shows after stage 2 or midtraining. ## Which stage-2 sets go into stage 1 **Rule: the training set of a benchmark the stage-2 checkpoints are evaluated on stays stage-2 data.** The stage-2 image evals (mm_olmo `eval_molmo2.py` `IMAGE_TASKS` / `TEST_IMAGE_TASKS`) are VQAv2, TextVQA, ChartQA, DocVQA, InfographicVQA, AI2D, A-OKVQA, MMMU, RealWorldQA, MathVista, Point-Bench, CountBenchQA and PixMo-Count. `STAGE2_EVAL_TRAIN_SETS` lists the sets this rule keeps out, and both the dataset class and the training script refuse them: | Stays in stage 2 | Train images | Benchmark | |---|---|---| | `coco_2014_vqa_multi` | 82,783 | VQAv2 | | `doc_qa` | 39,463 | DocVQA | | `text_vqa` | 34,602 | TextVQA | | `chart_qa_weighted` | 28,299 | ChartQA | | `info_qa` | 23,946 | InfographicVQA | | `a_okvqa_mc` / `a_okvqa_da` | 17,056 | A-OKVQA | | `ai2_diagram_v2_mix_transparent` | 15,042 | AI2D | | `tally_qa` | 127,867 (after the filter below) | VQAv2, through shared val2014 images | The rest of stage 2's single-image academic data becomes the stage-1 group. The group's rate is split by sqrt(size), with stage 2's row caps (`image_only_v9` `root_size_factor`) on the three templated chart sets. Without the caps, those sets would take 44.0% of the group instead of 18.8%: | Source | Train images | Weighted as | Share of group | Share of v3 mixture | |---|---|---|---|---| | `cosyn_chart_exp` | 116,814 | 116,814 | 18.83% | 2.64% | | `cosyn_document` | 71,282 | 71,282 | 14.71% | 2.06% | | `cosyn_math_exp` | 66,714 | 66,714 | 14.23% | 1.99% | | `cosyn_table_exp` | 46,518 | 46,518 | 11.88% | 1.66% | | `cosyn_diagram_exp` | 34,963 | 34,963 | 10.30% | 1.44% | | `cosyn_music_exp` | 11,969 | 11,969 | 6.03% | 0.84% | | `cosyn_chemical_exp` | 8,942 | 8,942 | 5.21% | 0.73% | | `plot_qa` | 157,070 | 20,000 | 7.79% | 1.09% | | `dv_qa` | 200,000 | 10,000 | 5.51% | 0.77% | | `figure_qa` | 100,000 | 10,000 | 5.51% | 0.77% | * **PlotQA trains 20 of its questions per image per epoch**, drawn afresh each epoch (`STAGE1_DEFAULT_MAX_QUESTIONS`; an explicit `max_questions` still wins). Its images carry 131 questions on average, and most full examples exceed the 2,560-token stage-1 sequence. With 20 questions, none of 300 sampled images overflowed (max 2,437 tokens). * **Left out:** OKVQA, ST-VQA, ScienceQA and TabMWP (6k–25k images each, too small to matter), and every multi-image source. * **CoSyn is closest to the line.** Its chart, document and table categories were built to improve ChartQA, DocVQA and InfographicVQA. It is not their training split, so the rule allows it. It is the set to drop first if the rule should be read more strictly. * **Overlap with the OCR group:** 267,359 of CoSyn's 357,202 images are also in the OCR group's figure-caption sources, so for those the group adds QA on images v3 already describes. The images a v3 run sees only through this PR: 546,913 (CoSyn's other 89,843, DVQA, FigureQA, PlotQA), plus PixMo-Clocks. ## PixMo-Clocks: a group of its own 800,269 synthetic clock faces, all asking the same question. They teach one narrow skill, so the group gets its own rate (`--clock_rate`; 0.03 in v3) instead of a share of the QA group. Clocks may later leave stage 2, which would leave stage 1 as the only place the model learns to read them. v3 trains about 271k clock examples (0.34 passes). That is roughly 40–70% of what the released Molmo2-4B stage 2 trained, at 2.0% of v3's tokens and 0.08% of its loss. The user turn is `clocks: What time is being shown?` and the answer is the time (`The time shown is 3:02 PM`). The question stays in because, without stage 2, it would be the only clock question the model ever sees. Naming `pixmo_clocks` in `--academic_sources` is refused with a pointer to `--clock_rate`. ## The v3 recipe `--recipe=v3` adds the academic and clock groups to v2 and raises OCR. It runs 50,000 steps (`RECIPE_MAX_STEPS`; an explicit `--trainer.max_duration.value` still wins). The rates were chosen against the sources themselves: 80 sampled examples per source (all 27, built as the script builds them), packed by the script's 2D-knapsack packer (2,560 tokens, 27 crops). That gives 1.41 examples per sequence, so 50k steps are 9.0M examples. | | v2 (32k steps) | **v3 (50k steps)** | |---|---|---| | Rate: caption / pointing / OCR / academic / clocks | 0.50 / 0.25 / 0.25 / 0 / 0 | **0.33 / 0.16 / 0.34 / 0.14 / 0.03** | | Loss share: caption | 55.1% | 39.2% | | Loss share: pointing and counting | 18.5% | 12.8% | | Loss share: OCR | 26.5% | 38.9% | | Loss share: academic QA | | 9.1% | | Passes over PixMo-Cap (715k) | 4.0 | 4.2 | | Passes over the pointing sources (325k) | 4.4 | 4.4 | | Passes over the OCR sources (3.09M) | 0.46 | **0.99** | | Passes over the academic group (814k) | | 1.55 | | Synthetic share of examples / loss | 22.6% / 20.7% | 44.0% / 38.5% | * **OCR 0.34 gives one pass over the OCR group**: 3.07M OCR examples for its 3.09M rows. The pass is uneven within the group, which is still split by task and then sqrt(size). The figure captions get about 1 pass, olmOCR documents 2.1, the small olmOCR subsets, TextOCR and the receipts 7–10, and NVIDIA's 1.46M synthetic images 0.32. * **Most of the synthetic rise is OCR** (figure captions, NVIDIA, receipts). CoSyn is 95% of the academic group's loss because its answers carry explanations. DVQA, FigureQA, PlotQA and the clocks together are about 0.5% of the loss. * **For midtraining these are shares of the multimodal part.** If that part grows, every pass count grows with it. ## Prompt Stage-1 sources send a `"<style>:"` tag and no template. An academic source sends the tag followed by the bare question: | Source | User turn | Answer | |---|---|---| | `plot_qa` | `plot_qa: Is the sum of the use of imf credit in dod in 2003 and 2007 greater than ...?` | `Yes` | | `dv_qa` | `dv_qa: What percentage of people like the least preferred object in the whole chart?` | `10` | | `cosyn_chart_exp` | `cosyn_chart_exp: What's the average investment in Transportation between 2003 and 2022?` | `<explanation> Answer: <answer>` | | `pixmo_clocks` | `clocks: What time is being shown?` | `The time shown is 3:02 PM` | Two `SftFormatter` fixes for the stage-1 family (`prompt_templates="none"`, `system_prompt="style_and_length_v2"`), which had only been used with pointing data: * **Every style is tagged.** Before, only the pointing styles got `"<style>:"`. mm_olmo tags every style under this family; the length number it adds to non-pointing styles is dropped here, as #875 dropped it from the caption tag. That matches mm_olmo's molmo3 stage-1 family (`style_and_length_v3`). The pointing sources are unaffected. * **No chain-of-thought instruction under `"none"`**, as in mm_olmo (`data_formatter.py:1933-1934`); the `*_exp` tag is what asks for the explanation. The stage-2 family keeps the instruction. Multiple choice under `"none"` raises `NotImplementedError` (mm_olmo's `format_options` layout is not ported); no stage-1 source is multiple choice. ## TallyQA: drop its COCO val2017 images TallyQA's train split holds the 5,000-image COCO val2017 set, both under 2014 file names and through Visual Genome (`image_data.json` `coco_id`). Those images are dropped; the rest of val2014 is kept. | TallyQA train | Images | Questions | |---|---|---| | Total | 132,981 | 249,318 | | COCO val2017 images under val2014 names | 4,052 | | | Visual Genome images that are COCO val2017 images | 1,062 | | | **Dropped** | **5,114** | **9,578** | | **Kept** | **127,867** | **239,740** | The ids come from COCO's `annotations/captions_val2017.json`. The filter is in the registry's TallyQA loader (train split only), so `image_only_v9` gets it too: TallyQA's sqrt(size) weight in stage 2 falls by 1.9% relative to the other academic sources. A missing held-out file fails the build rather than skipping the check. ## Launch note: torchvision `pixmo_clocks` imports torchvision only when it formats a clock image, so v1/v2 runs don't need it. A run that trains clocks does. In the `akshitab/olmo-core-tch2100cu130-2026-07-03` image, the package install upgrades torch to 2.13.0 and leaves torchvision at 0.25.0, which fails to import ("operator torchvision::nms does not exist"). The v3 run added `torchvision==0.28.0` to `post_setup`. Stage 2 trains clocks too, so it needs the same pin on that image. ## Verification * `src/test/data/multimodal/`: **324 passed, 7 skipped** on CPU (torch 2.10, rebased branch). The skips are `h5py` / `pypdfium2`, not installed here. `stage1_academic_test.py` (38 tests) covers: * the v3 recipe and its 50k steps, and PlotQA's default cap; * the clock group: prompt, refusal as an academic source, rate validation; * the prompt family and per-epoch question sampling; * the TallyQA filter, on synthetic files and against weka (pins 127,867 kept images and 5,000 val2017 ids); * refusal of every stage-2 eval training set; * the group weights (CoSyn 81.2%, templated charts 18.8%). * Real data: every v3 source built with the Qwen3 tokenizer as the script builds it, and 80 examples encoded from each of the 27 for the recipe numbers. * black 23.12 and isort 5.13 pass. ruff 0.15.9 (the pinned version) passes. mypy adds no errors: the changed files have 5 errors, against 7 on `vision`. ## Usage ``` python src/scripts/train/Molmo2-Stage1.py launch RUN --recipe=v3 # 50k steps python src/scripts/train/Molmo2-Stage1.py launch RUN --recipe=v3 --clock_rate=0.02 python src/scripts/train/Molmo2-Stage1.py launch RUN --recipe=v3 \ --academic_sources=[cosyn_chart_exp,cosyn_document,cosyn_table_exp] ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Evaluating a checkpoint straight from its
model_and_optim/DCP directory reads 49 GB of model and Adam state, spread over 256 shards in training-rank layout, to get about 19 GB of weights. It is slow and degrades badly when many eval jobs load the same checkpoint at once (allenai/olmo-eval#379). This PR writes an unsharded copy of the weights into every permanent checkpoint at training time, so evals read one file.What it adds
UnshardedModelExportCallback(train/callbacks/unsharded_export.py). After each permanent checkpoint it writes two files into the step directory, next tomodel_and_optim/:model.safetensors: the full model state dict, keyed asmodel.state_dict(), with no optimizer state.olmo_core_config.json: a copy of the checkpoint'sconfig.json.olmo-eval's
olmo_core_vlmprovider already loads this pair (itsolmo_core_unshardedformat) in preference to the DCP state, so eval commands keep pointing atstepN/.config.json(with a warning).model.safetensorsis written to a temporary file and renamed, and the config is written last, so a directory with both files is always complete. URL save folders are uploaded.load_unsharded_model_state(dir)(distributed/checkpoint) is the reader. Unlikeunshard_checkpoint()andload_keys(), it may run on one rank of a distributed job: it reads withno_dist=Trueand issues no collectives.Molmo2-Stage2.pyenables the callback too. Its retention is unchanged: the default, last 3.Molmo2-Stage1.pyenables the callback and keeps the last 5 permanent checkpoints (max_checkpoints=5, wasNone). Each kept checkpoint holds both its DCP state (for resuming) and the unsharded export, so nothing is lost. Pruning deletes the whole step directory, export included. Each save first waits for pending background ops, so a checkpoint's export always finishes before the next save, and deletions are only scheduled after a save. The v2 run scored within about a point across steps 24k-32k, the last 5 of a 32k run.Numbers
Measured on
molmo2-stage1-4b-v2-20260926/step32000(4.46B parameters, fp32):load_unsharded_model_statereturns the same 814 tensors assrc/scripts/unshard.py --safetensors --no-optim, all bit-identical.model.safetensors, detected by the olmo-eval provider asolmo_core_unsharded, with the config identical toconfig.json.Tests
src/test/train/callbacks/unsharded_export_test.py(5 tests): the exported weights equalmodel.state_dict()and the config is copied with no temporary file left behind; ephemeral checkpoints and checkpoints without a config are skipped; saves are queued and submitted as background ops, including the final checkpoint frompost_train; a disabled callback does nothing.test_load_unsharded_model_state_in_distributed_job(src/test/distributed/checkpoint_test.py): a checkpoint tensor-parallel across 2 ranks is read back on rank 0 alone while the job is still distributed, and matches the full tensors.vision(including Apply black and isort to vision #894):src/test/train/callbacksplussrc/test/distributed/checkpoint_test.py: 76 passed. The new distributed test passes on gloo; the NCCL variant needs 2 GPUs.test_load_checkpoint_with_missing_keys(CUDA initialization error in a child process), fails the same way onvisionwithout this PR. The S3 tests were not run (no credentials here).make style-checkpasses on the whole repo.ExperimentConfigwith the callback registered.🤖 Generated with Claude Code