Skip to content

Apply black and isort to vision - #894

Merged
jason718 merged 1 commit into
visionfrom
jasonr/vision-format
Sep 29, 2026
Merged

jason718 merged 1 commit into
visionfrom
jasonr/vision-format

Conversation

@jason718

@jason718 jason718 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

make style-check failed on vision: CI runs it only for PRs into main, so black and isort drift had built up on the multimodal work. This PR applies the pinned versions (black>=23.1,<24.0, isort>=5.12,<5.14) with isort . then black .. It changes whitespace and import order only.

  • Formatting: black reformatted 22 files and isort re-sorted imports in 18, 32 files in all, mostly under data/multimodal/. Afterwards isort --check . and black --check . pass (643 files unchanged).
  • Imports: the modules with re-sorted imports (data/multimodal, its academic and mixtures subpackages, nn/attention, nn/vision/connector, the multimodal train module) and both touched scripts import cleanly, so the new __init__ import order creates no cycle.
  • Tests:
    • src/test/data/multimodal: 292 passed.
    • src/test/nn/attention, nn/lm_head_test.py and nn/vision on an A100: 393 passed, 3 failed. The same three test_lm_head_response_logits_only cases fail identically on vision without this PR.
  • Not changed: ruff reports 6 findings (unused os imports and E402 in three nn/vision tests, an unused local in molmo2_loader.py). They are identical before and after this PR, and left alone.

make style-check (black 23 / isort 5.12, the pinned versions) now passes
on vision: 22 files reformatted by black, imports re-sorted in 18.
Whitespace and import order only.
@jason718
jason718 merged commit bbeb528 into vision Sep 29, 2026
1 check passed
@jason718
jason718 deleted the jasonr/vision-format branch September 29, 2026 13:52
jason718 added a commit that referenced this pull request Oct 1, 2026
…llbacks and recipe from #869

Squash of two port commits (the first one's tree object was corrupted by an interrupted write).

Port the vision alignment data adapters and evaluators' data layer from #869

The multimodal data package gains RustinS's alignment sources: the document
(native EOS-prefixed) message layout next to the qwen3 one, the
PretrainingReplayDataset that replays a text checkpoint's own pretraining
windows, the perception-phase OCR/audited adapters, strict Arrow-split
validation with content fingerprints, grouped mixture quotas, and the
matching tests. Files that vision had also changed since the fork (#875,
#894) are merged by hand, keeping vision's behavior:

- pixmo_points: `_build_example` accepts both the branch-list convention used
  by vision's stage-1 sources (qwen3 layout, branch weights) and the callable
  convention of the alignment adapters (document layout, strict validation);
  CoSyn keeps the audited-build prefixes and gains split/fingerprint options.
- pixmo_cap: vision's bare style tag and prompt pools stay the default; the
  document layout, transcript validation and length conditioning (opt-in,
  `style_length_conditioning`) are added for the alignment adapters.
- sft_common / sequence_builder / message_sequence: union of both sides
  (epoch-seeded examples from vision, message formats and bounded datasets
  from the alignment recipe).

Two pieces of logic that #868/#869 had placed in shared code move here so the
shared files stay untouched: the per-occurrence metadata alignment for
weighted source mixtures that drop zero-allocation paths (now done by the
replay adapter), and a filesystem cache decorator whose directory comes from
`OLMO_CORE_DATA_VERIFICATION_CACHE_DIR` (`data/multimodal/fs_cache.py`).


Add the OLMoDDP vision alignment train module, callbacks, evaluators and recipe

Builds the three-stage alignment recipe (bridge, perception, joint) from #869
as a multimodal-only layer on the OLMoDDP hooks:

- MultimodalOLMoDDPTrainModule: supplies the weighted response-only loss
  divisor and the valid-token router divisor through
  `_batch_auxiliary_loss_kwargs`; freezes parameters by pattern, restricts
  embedding gradients to the image-token rows, checkpoints frozen parameters
  as `frozen_model.*`, and loads both those checkpoints and native text
  checkpoints (no `lm.` prefix, fresh vision/connector state kept) through
  the `_optimizer_state_dict_for_load` / `_after_load` adapters. Held-out
  multimodal batches return the summed weighted loss; text-only downstream
  batches keep the standard full-logits path.
- train/callbacks/multimodal.py: model initialization from a text checkpoint
  plus a SigLIP tower, the held-out response-loss evaluators, and subclasses
  for W&B run resume and rewritable same-step metric snapshots (with
  `RestoreMetricsCallback`), replacing the shared-callback edits of #868.
- eval/: decoded, academic and fast-text evaluation of alignment checkpoints
  (`scipy` is imported lazily by the pointing metrics).
- internal/vision_alignment*.py and the Vision-Align scripts: the recipe now
  builds `MultimodalOLMoDDPOptimizerConfig`, sets `PYTHONPATH` in its own
  launch env, restores a missing `launch` on config load, and writes
  completion markers through an overwrite-capable helper instead of a
  trainer-wide overwrite policy.

Not carried from #868/#869: the router token mask (padding takes part in
routing statistics), the rowwise-EP forward-only eval dispatch, and the
compiled-flex mask routing; the corresponding tests are dropped.
jason718 added a commit that referenced this pull request Oct 2, 2026
… 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)
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