Repository navigation
Conversation
… TP ranks MegatronSDLoader.split_state_dict splits final_linear.weight (the vocab-parallel output layer in GPT-NeoX checkpoints) along dim 0, but merge_state_dict had no matching branch. That sent final_linear.weight to the fallback, which keeps only the first shard. Loading a TP=2 checkpoint on TP=1 therefore produced a [vocab/2, hidden] tensor where [vocab, hidden] was expected. Concatenate final_linear.weight along dim 0 when merging, the same way split_state_dict divides it. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MegatronSDLoader.split_state_dictsplits the vocab-parallelfinal_linear.weight(GPT-NeoX output layer) along dim 0 when a checkpoint is loaded on more TP ranks than it was saved with.merge_state_dicthas no matching branch, so when a checkpoint is loaded on fewer TP ranks the key falls through toelse: new_client_sd[key] = value_list[0]and only the first shard is kept.Example:
final_linear.weightof shape[32, 8]split to TP=2 gives two[16, 8]shards (correct); merging them back to TP=1 returns[16, 8]instead of[32, 8], so the model'sload_state_dictfails with a size mismatch. The asymmetry dates back to #1899, which addedfinal_linearto the split side only.Fix
Add
final_linear.weightto the dim-0 concatenation branch ofmerge_state_dict, mirroring the split side.Tests
New
tests/unit/checkpoint/test_state_dict_factory.py: builds a Megatron-style checkpoint, splits it to TP=2 withSDLoaderFactory, merges the shards back to TP=1, and asserts every key equals the original tensor.main: fails withAssertionError: final_linear.weightRan on macOS (Apple Silicon) CPU only, no accelerator, torch 2.15.0, Python 3.13. pre-commit passes on the changed files.
Scope / validation
mp_rank_*checkpoints. The PipelineModule per-layer path is not changed (there,sanity_check(ckpt_list[0])already rejects a layer file that only holdsfinal_linear, a separate issue).quantize=True) loading. The quantize path is unaffected, since the quantizer only applies tomlp.dense_h_to_4h.weightin this branch.Duplicate check
Searched open PRs and issues for
final_linear,state_dict_factory,MegatronSDLoader,merge_state_dict: no existing work. No open PR touchesstate_dict_factory.py.AI assistance was used to prepare this change; I reviewed the diff and ran the tests above.