Repository navigation
Add a script that checks an olmo-core config reproduces its HF logits - #1839
Conversation
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
| hf_model = transformers.AutoModelForCausalLM.from_pretrained( | ||
| args.model_name, dtype=torch.bfloat16, trust_remote_code=True | ||
| ).to(device) |
There was a problem hiding this comment.
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 👍 / 👎.
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]>
8a2c984 to
ced5a4d
Compare
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]>
Loads a model twice, once through
transformersand once by building an olmo-coreTransformerConfigand 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.
GPU_TESTS=bypass — one manually-run script under
scripts/, noopen_instruct/code.🤖 Generated with Claude Code