Skip to content

Add a script that checks an olmo-core config reproduces its HF logits - #1839

Merged
farhatkevin merged 3 commits into
mainfrom
pr/check-olmo-core-matches-hf
Sep 3, 2026
Merged

farhatkevin merged 3 commits into
mainfrom
pr/check-olmo-core-matches-hf

Conversation

@abhishekraok

@abhishekraok abhishekraok commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Loads a model twice, once through transformers and once by building an olmo-core TransformerConfig and converting the HF weights into it, then runs both on the same input and compares logits. Per-block divergence is reported too, so a mismatch names the first block that drifts.

Key-and-shape checks cannot see a right-shaped tensor behind the wrong name. On the hybrid conversion three of them passed clean on code carrying a 38% logit error.

python scripts/train/debug/check_olmo_core_matches_hf.py \
    --model-name allenai/Olmo-Hybrid-7B --config-name olmo3_hybrid_7B

GPU_TESTS=bypass — one manually-run script under scripts/, no open_instruct/ code.

🤖 Generated with Claude Code

@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: 8a2c984003

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

args = parser.parse_args()

device = torch.device("cuda")
ids = torch.tensor([[100257, 3923, 374, 279, 6864, 315, 9822, 30, 578, 6864]], device=device)

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 Generate input IDs within the model vocabulary

For supported checkpoints whose vocabulary has at most 100257 entries, such as Llama-family models with a 32K vocabulary, the hard-coded token 100257 is out of range and the first HF forward fails in the embedding lookup. Since the loader otherwise supports non-OLMo checkpoints through its Llama-style conversion path, derive the test sequence from the checkpoint's tokenizer or constrain the IDs using hf_config.vocab_size.

Useful? React with 👍 / 👎.

Comment on lines +46 to +48
hf_model = transformers.AutoModelForCausalLM.from_pretrained(
args.model_name, dtype=torch.bfloat16, trust_remote_code=True
).to(device)

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 Use the selected attention backend for both models

When --attn-implementation differs from the backend automatically selected by Transformers—including the default core flash_2 versus an HF model using SDPA—the two forwards exercise different kernels. Their normal numerical differences can then exceed the tolerance or change a near-tied argmax, causing this conversion checker to report a false mismatch; pass the corresponding HF attention implementation when loading the reference model.

Useful? React with 👍 / 👎.

Base automatically changed from pr/olmo-hybrid-sft to main August 20, 2026 20:39
Key and shape checks pass on conversions that are numerically wrong: they
cannot see a right-shaped tensor behind the wrong name, and a state-dict
round trip cannot either. This runs both models on the same input and
compares logits, reporting per-block divergence so a mismatch points at
the layer that caused it.

It found one real bug while landing Olmo-Hybrid support (#1822): HF
hardcodes eps=1e-5 on the gated DeltaNet output norm instead of reading
rms_norm_eps, which three structural checks passed straight through at a
38% logit error.

Needs a GPU, so it stays a manual tool rather than a test.

Co-Authored-By: Claude Fable 5 <[email protected]>
@abhishekraok
abhishekraok force-pushed the pr/check-olmo-core-matches-hf branch from 8a2c984 to ced5a4d Compare August 20, 2026 20:40
The hard-coded ids started at 100257, which is outside any vocabulary smaller
than that -- a 32k-vocab Llama would have died in the embedding lookup, on a
path the loader otherwise supports. Encoding with the checkpoint's own
tokenizer keeps the ids in range whatever the model.

Loading HF under its default backend while building olmo-core with flash also
compared two different kernels, whose ordinary numerical difference can flip a
near-tied argmax and read as a conversion error. Map the backend across, and
fall back to HF's own choice with a warning when an architecture does not
implement it.

Both raised by Codex on #1839.

Co-Authored-By: Claude Fable 5 <[email protected]>
The previous fallback only moved HF: when it rejected the requested backend we
reloaded it under its own default while olmo-core still built with flash,
recreating the mismatched-kernel comparison the mapping existed to prevent.
The backend is now a variable both sides read, so a fallback moves them
together, and re-raises rather than retrying when the fallback is what already
failed.

Backends without an HF counterpart (flash_4, te) are rejected by argparse
instead of silently comparing different kernels.

Raised by @farhatkevin on #1839.

Co-Authored-By: Claude Fable 5 <[email protected]>

@farhatkevin farhatkevin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good

@farhatkevin
farhatkevin added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit ebd0c8e Sep 3, 2026
7 checks passed
@farhatkevin
farhatkevin deleted the pr/check-olmo-core-matches-hf branch September 3, 2026 21:44
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