Repository navigation
Add OLMo Core <-> MaxText checkpoint conversion - #920
Conversation
…Text Weights-only conversion in both directions as a pure re-layout, so round trips are bit-exact. Includes scripts to convert, to dump OLMo Core reference logits on GPU, and to check a converted checkpoint's logits in MaxText. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
… FLA's fused kernel Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
…nding Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Rebuild olmo_core.nn.maxtext around nn.conversion's StateConverter, like nn.hf. get_maxtext_config() picks the MaxText decoder from the OLMo Core config and validates it; convert.py holds the mappings as per-component StateMappingTemplate builders; convert_checkpoint.py converts whole checkpoints and checks the round trip layer by layer. Adds the dense olmo3 decoder alongside the hybrid KDA/MoE one, with scan layouts per decoder. The new mappings give bit-identical output to the old module on every fixture. Tests check converted trees against MaxText's own eval_shape init for both decoders, and dense logits match OLMo Core on CPU (rel 1e-6), scanned and unscanned. CLIs and parity scripts move to src/examples/maxtext/. Run-specific results and the one-off debug scripts are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM
Invert the OLMo Core -> MaxText mappings mechanically instead of hand-writing each one twice: one _invert() reverses the StateConverter pipeline, so the *_from_maxtext builders and (to, from) tuple plumbing go away. Reuse the checkpoint helpers OLMo Core already has: get_checkpoint_metadata, load_keys and save_state_dict replace hand-rolled DCP plumbing, write_json uses copy_file, and one read_json replaces five copies of the same block. Scanned/unscanned layouts use prefix parsing instead of regexes built from format strings. Make the scan cycle a config field and derive first_num_dense_layers from the layers instead of hard-coding 1. Share the MaxText pyconfig bootstrap between the parity helper and the test. Move the legacy config normalizer from olmo_core.nn.hf to olmo_core.nn.transformer.config so the MaxText converter doesn't reach into the HF converter for it. Drop unused parameters and trim the package's exports to its entry points. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The converter is now the same four modules as the Hugging Face one (config, convert, checkpoint, convert_checkpoint). The parity scripts and their summary/metrics module were a debugging workflow, not converter API; they can come back in their own PR. - Remove reference_logits.py, maxtext_logits.py and nn/maxtext/parity.py. - Move initialize_maxtext_config() into nn/maxtext/checkpoint.py; it's how a converted checkpoint is loaded, so it belongs with the I/O. - Inline the dense CPU logits check in maxtext_test.py: load through MaxText's load_parameters_path, assert every parameter equals the checkpoint's, and compare logits directly. - Trim the README's parity and gotchas sections. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2c9f06201
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5845099f67
ℹ️ 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".
AkshitaB
left a comment
There was a problem hiding this comment.
Found two configuration translation issues that can silently change model behavior while passing parameter round-trip validation. Confirmed both config collisions using the PR fixtures with the config parsing code isolated from unavailable dependencies. Full tests could not run locally because PyTorch is not installed.
Address review feedback on the converter's config validation. These settings change the forward pass without changing any parameter shape, so a weight round-trip can't catch them: - olmo3: reject rope.no_global_rope=True (MaxText applies RoPE on every layer) - olmoe3: validate the router weighting (softmax, normalize_expert_weights=1.0, restore_weight_scale=True, or the equivalent topk_softmax) and reject router biases, score-correction biases, expert-weight rescaling, grouping, and forced assignment - olmoe3: require embed_scale == sqrt(d_model), since the embedding norm's epsilon keeps a different scale from cancelling out - both: require the LM head norm and include it in the epsilon check - both: reject n_extra_vocab > 0 Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a867730deb
ℹ️ 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".
Second round of review feedback on the converter's config validation: - treat an omitted attention, feed-forward, or LM head bias as True, which is what the modules build with after as_config_dict() drops None fields - reject clip_qkv on both decoders - reject embed_scale=0.0 for olmo3 (was a truthiness check) - olmoe3: require the full-attention QK norm and include it in the shared epsilon check; reject attention projection biases - olmoe3: require the KDA output norm's epsilon to match the constant MaxText hardcodes for it - olmoe3: translate KDA allow_neg_eigval instead of relying on MaxText's default - olmoe3: reject latent_moe.up_proj_input_norm_enabled, which adds a parameter the mapping has no slot for Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a811cadfdc
ℹ️ 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".
| raise ValueError("MaxText's olmo3 decoder has no projection biases") | ||
| if mixer.get("clip_qkv") is not None: | ||
| raise ValueError("MaxText's olmo3 decoder doesn't clip Q/K/V (clip_qkv)") | ||
| if mixer.get("use_head_qk_norm") or mixer.get("gate") or mixer.get("scalable_softmax"): |
There was a problem hiding this comment.
Reject attention-sink configurations
When dense default attention uses attention_sinks=True (with the torch backend), OLMo Core saves blocks.<i>.attention.sinks, but the converter's attention shapes and mappings have no slot for that parameter. This validation accepts the config, so load_olmo_core_weights() later rejects the checkpoint as having an extra key; the hybrid full-attention branch has the same omission. Reject this setting or add its MaxText mapping.
Useful? React with 👍 / 👎.
| shared = block["shared_experts"] | ||
| if shared["num_experts"] != 1 or shared.get("bias"): |
There was a problem hiding this comment.
A hybrid block may validly provide shared_experts_router even with its one shared expert, but this validation ignores it. That module contributes blocks.<i>.shared_experts_router.weight (and possibly a bias), neither of which appears in olmo_core_shapes() or the mappings, causing checkpoint loading to reject the extra parameters. Require this router to be absent unless it is mapped.
Useful? React with 👍 / 👎.
| if shared["num_experts"] != 1 or shared.get("bias"): | ||
| raise ValueError(f"block {i}: expected a single bias-free shared expert") |
There was a problem hiding this comment.
Reject non-SwiGLU shared experts
When a hybrid config uses shared_experts.activation="relu2", it passes this check, but the source allocates a one-part w_up_gate while olmo_core_shapes() and _shared_expert_mappings() always assume the two-part SwiGLU layout. Such checkpoints therefore fail the input shape validation instead of converting. Require the shared expert activation to be SwiGLU.
Useful? React with 👍 / 👎.
A non-unit attention_residual_alpha or feed_forward_residual_alpha converted cleanly but ran a different model, since the MaxText overrides carry no residual scale. The hybrid block already refuses these at build time. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7db7115153
ℹ️ 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".
Replace the EMO pool tuple on MoESpec with an EMOSpec that also holds the EOS token, and emit olmo_segment_eos_token_id and olmoe3_segments_for_emo_only=True so MaxText's OLMo data pipeline splits documents on the same token and only the router sees the split. Resolve an unset eval_document_expert_pool to the midpoint, as EmoRouterConfig.eval_pool_size() does, instead of raising KeyError. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 575b6463a3
ℹ️ 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".
AkshitaB
left a comment
There was a problem hiding this comment.
The previous two findings (no_global_rope and MoE router weighting) are addressed. The RoPE rejection and all 12 router rejection cases passed isolated config checks. Found one additional default-resolution issue below. Full tests remain unverified because PyTorch and pytest are unavailable locally.
as_config_dict() drops unset fields, so the converter has to apply the same defaults the modules build with: - norms: eps defaults to 1e-5, and bias and elementwise_affine to True, so an omitted eps no longer raises KeyError, an omitted bias is rejected like an explicit one, and non-affine norms (which have no gain to convert) are rejected - KDA n_v_heads and head_dim, and attention n_kv_heads and head_dim, are resolved before the per-block comparison, so blocks that spell the same model differently compare equal and an omitted n_v_heads no longer raises Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61e3b45b2a
ℹ️ 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".
The overrides carry no dropout rate and MaxText defaults to none, so a model trained with block, masked, or attention dropout would continue training without it. Reject nonzero values for both decoders. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 124c9f5521
ℹ️ 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".
| f"qk_norm_per_head={self.attention.per_head_qk_norm}", | ||
| f"use_scalable_softmax={self.attention.scalable_softmax}", | ||
| f"first_num_dense_layers={self.n_dense_layers}", | ||
| f"base_mlp_dim={self.layers[0].hidden_size}", |
There was a problem hiding this comment.
Reject mixed dense-expert widths
When a hybrid layout has more than one leading dense layer and those layers use different shared-expert hidden_size values, this records each width per layer but emits only base_mlp_dim from layer 0. MaxText will initialize every leading dense MLP at that single width while the converter produces later-layer tensors at their source widths, so the converted checkpoint cannot load into the generated model. Require all leading dense shared experts to use the same width, or represent their widths in the target configuration.
Useful? React with 👍 / 👎.
| raise ValueError( | ||
| f"block {i}: MaxText's olmoe3 router picks the top-k experts by score, without expert " | ||
| "groups or forced assignment" | ||
| ) |
There was a problem hiding this comment.
A hybrid router with nonzero jitter_eps is accepted here, although OLMo Core applies random multiplicative noise to router inputs while training and neither MoESpec nor the emitted MaxText overrides carries that setting. Continuing training from such a converted checkpoint therefore changes expert selection and gradients despite a successful weight round-trip. Reject nonzero jitter or translate it to an equivalent MaxText setting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19822d8b88
ℹ️ 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".
| if ( | ||
| router.get("uniform_expert_assignment") | ||
| or router.get("random_expert_assignment") | ||
| or router.get("n_group") is not None | ||
| or router.get("topk_group") is not None | ||
| ): | ||
| raise ValueError( | ||
| f"block {i}: MaxText's olmoe3 router picks the top-k experts by score, without expert " | ||
| "groups or forced assignment" | ||
| ) |
There was a problem hiding this comment.
Preserve router auxiliary-loss settings
When a hybrid source config changes lb_loss_weight, lb_loss_granularity, z_loss_weight, orth_loss_weight, or global_load_balancing, this validator still accepts it, but MoESpec and the generated MaxText overrides carry none of those settings. Continuing training after conversion can therefore use a different auxiliary objective and produce different gradients; translate these fields where MaxText supports them or reject incompatible values.
Useful? React with 👍 / 👎.
| LayerSpec(sequence_mixer="attention", hidden_size=ff["hidden_size"]) | ||
| for _ in range(n_layers) | ||
| ), | ||
| cycle=_OLMO3_CYCLE, |
There was a problem hiding this comment.
Reject incomplete dense scan cycles before conversion
For a supported dense model whose n_layers is not divisible by four, this returns a configuration with cycle=4, but the default checkpoint path subsequently calls scan_params(), which unconditionally raises because the layer count is not a multiple of the cycle. Thus a global-attention three-layer model, for example, passes architecture validation and then fails the documented default conversion unless the caller discovers --unscanned; reject this layout up front or support a partial final scan cycle.
Useful? React with 👍 / 👎.
No code yet. The branch starts at #916's head (4fb33e9), which includes the main sync (#885, #910-#912, #920). #916's earlier ac87d76 trained the 64K mixed mid-training checkpoint this SFT starts from. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KshPetwmP4KzQGok1mmMXs
No code yet. The branch starts at #916's head (4fb33e9), which includes the main sync (#885, #910-#912, #920). #916's earlier ac87d76 trained the 64K mixed mid-training checkpoint this SFT starts from. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KshPetwmP4KzQGok1mmMXs
Adds
olmo_core.nn.maxtext, which converts model weights between OLMo Core checkpoints and MaxText checkpoints in both directions. It follows the structure of the Hugging Face converter inolmo_core.nn.hf.Weights only for now; optimizer state isn't converted.
Design
config.py:get_maxtext_config(model_config)plays the role ofget_hf_config.decoder_blockfrom the OLMo Core block config.model_name, the overrides that size the model, and the decoder's scan layout.convert.py: the weight mappings, written asStateMappingTemplates and run by the existingStateConverter.blocks.{i}.attention.*) but not MaxText names. The HF hybrid path splits by layer for the same reason.checkpoint.py: reads and writes OLMo Core DCP checkpoints, including OLMoDDP's flatmodule.*.mainentries, and MaxText Orbax checkpoints. It also converts between MaxText's scanned and unscanned layouts for each decoder.convert_checkpoint.py:convert_checkpoint_to_maxtext()andconvert_checkpoint_from_maxtext().parity.py: logit summaries and comparison metrics, plusmaxtext_logit_summary(), which runs a converted checkpoint in MaxText and checks that it loaded the checkpoint's weights.src/examples/maxtext/: the CLIsconvert_checkpoint_{to,from}_maxtext.py, the parity scriptsreference_logits.pyandmaxtext_logits.py, and a README.Supported MaxText decoders
decoder_blockolmo3reordered_normblocks: RoPE attention with global QK norm, SwiGLU, and an optional[w, w, w, -1]sliding windowolmoe3Testing
convert_test.py(CPU, no JAX):maxtext_test.py(runs when MaxText is installed; CPU JAX is enough):jax.eval_shapeinit, for both decoders, scanned and unscanned.All 53 tests pass. isort, black, ruff and mypy are clean on the new files.
Not done yet
olmo3, and pre-norm blocks.🤖 Generated with Claude Code
https://claude.ai/code/session_011gHFAjGWHZotPXfJeNM9vM