Skip to content

Many layers missing when converting GPTOSS Megatron checkpoint to HF format #2124

Closed

Description

@dhineshkumar-r

Describe the bug

Many layers are not found in generator model when converting gpt-oss checkpoint Megatron to HF format.

load_return: _IncompatibleKeys(missing_keys=['decoder.layers.0.self_attention.linear_proj._extra_state', 'decoder.layers.0.self_attention.linear_qkv._extra_state', 'decoder.layers.0.pre_mlp_layernorm._extra_state', 'decoder.layers.0.mlp.experts.linear_fc1._extra_state', 'decoder.layers.0.mlp.experts.linear_fc2._extra_state', 'decoder.layers.1.self_attention.linear_proj._extra_state', 

....

ayers.22.mlp.experts.linear_fc1._extra_state', 'decoder.layers.22.mlp.experts.linear_fc2._extra_state', 'decoder.layers.23.self_attention.linear_proj._extra_state', 'decoder.layers.23.self_attention.linear_qkv._extra_state', 'decoder.layers.23.pre_mlp_layernorm._extra_state', 'decoder.layers.23.mlp.experts.linear_fc1._extra_state', 'decoder.layers.23.mlp.experts.linear_fc2._extra_state', 'decoder.final_layernorm._extra_state'], unexpected_keys=[])
tokenizer_config.json: 4.20kB [00:00, 20.5MB/s]
tokenizer.json: 100%|█████████████████████████████████████████████████| 27.9M/27.9M [00:00<00:00, 28.0MB/s]
special_tokens_map.json: 100%|██████████████████████████████████████████| 98.0/98.0 [00:00<00:00, 1.09MB/s]
chat_template.jinja: 16.7kB [00:00, 61.2MB/s]
generation_config.json: 100%|█████████████████████████████████████████████| 177/177 [00:00<00:00, 1.87MB/s]
model.safetensors.index.json: 36.4kB [00:00, 92.2MB/s]                               | 0/5 [00:00<?, ?it/s]
model-00002-of-00002.safetensors: 100%|████████████████████████████████| 4.17G/4.17G [00:10<00:00, 398MB/s]
model-00000-of-00002.safetensors: 100%|████████████████████████████████| 4.79G/4.79G [00:14<00:00, 337MB/s]
model-00001-of-00002.safetensors: 100%|████████████████████████████████| 4.80G/4.80G [00:19<00:00, 245MB/s]
original/model.safetensors: 100%|██████████████████████████████████████| 13.8G/13.8G [00:22<00:00, 618MB/s]
Fetching 5 files: 100%|██████████████████████████████████████████████████████| 5/5 [00:22<00:00,  4.54s/it]
[rank0]: Traceback (most recent call last):
[rank0]:   File "/opt/nemo-rl/examples/converters/convert_megatron_to_hf.py", line 76, in <module> 774MB/s]
[rank0]:     main()tensors:  98%|████████████████████████████████████▏| 13.5G/13.8G [00:22<00:00, 1.51GB/s]
[rank0]:   File "/opt/nemo-rl/examples/converters/convert_megatron_to_hf.py", line 66, in main
[rank0]:     export_model_from_megatron(
[rank0]:   File "/opt/nemo-rl/nemo_rl/models/megatron/community_import.py", line 140, in
export_model_from_megatron
[rank0]:     bridge.save_hf_pretrained(megatron_model, output_path)
[rank0]:   File
"/opt/nemo-rl/3rdparty/Megatron-Bridge-workspace/Megatron-Bridge/src/megatron/bridge/models/conversion/auto
_bridge.py", line 494, in save_hf_pretrained
[rank0]:     self.save_hf_weights(
[rank0]:   File
"/opt/nemo-rl/3rdparty/Megatron-Bridge-workspace/Megatron-Bridge/src/megatron/bridge/models/conversion/auto
_bridge.py", line 573, in save_hf_weights
[rank0]:     self.hf_pretrained.state.source.save_generator(
[rank0]:   File
"/opt/nemo-rl/3rdparty/Megatron-Bridge-workspace/Megatron-Bridge/src/megatron/bridge/models/hf_pretrained/s
tate.py", line 749, in save_generator
[rank0]:     raise KeyError(
[rank0]: KeyError: "Tensor 'model.layers.0.mlp.experts.gate_up_proj' from generator not found in the
original model structure. To ignore, set strict=False."
Converting to HuggingFace ━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   4% 0:00:39 (137/3291) GPTOSSBridge

Steps/Code to reproduce bug

  1. Pull nvcr.io/nvidia/nemo-rl:v0.5.0.nemotron_3_super image
  2. root@ip:/opt/nemo-rl# uv run --extra mcore examples/converters/convert_megatron_to_hf.py --config=$CKPT_PATH/config.yaml --megatron-ckpt-path $CKPT_PATH/policy/weights/iter_0000000/ --hf-ckpt-path $CKPT_PATH/hf
  3. Ckpt path tree
step_40
├── config.yaml
├── policy
│   └── weights
│       ├── iter_0000000
│       │   ├── __0_0.distcp
│       │   ├── __0_1.distcp
│       │   ├── __10_0.distcp
│       │   ├── __10_1.distcp
│       │   ├── __11_0.distcp
│       │   ├── __11_1.distcp
│       │   ├── __12_0.distcp
│       │   ├── __12_1.distcp
│       │   ├── __13_0.distcp
│       │   ├── __13_1.distcp
│       │   ├── __14_0.distcp
│       │   ├── __14_1.distcp
│       │   ├── __15_0.distcp
│       │   ├── __15_1.distcp
│       │   ├── __1_0.distcp
│       │   ├── __1_1.distcp
│       │   ├── __2_0.distcp
│       │   ├── __2_1.distcp
│       │   ├── __3_0.distcp
│       │   ├── __3_1.distcp
│       │   ├── __4_0.distcp
│       │   ├── __4_1.distcp
│       │   ├── __5_0.distcp
│       │   ├── __5_1.distcp
│       │   ├── __6_0.distcp
│       │   ├── __6_1.distcp
│       │   ├── __7_0.distcp
│       │   ├── __7_1.distcp
│       │   ├── __8_0.distcp
│       │   ├── __8_1.distcp
│       │   ├── __9_0.distcp
│       │   ├── __9_1.distcp
│       │   ├── common.pt
│       │   ├── metadata.json
│       │   ├── modelopt_run_config.yaml
│       │   ├── run_config.yaml
│       │   └── train_state.pt
│       ├── latest_checkpointed_iteration.txt
│       └── latest_train_state.pt
|── train_dataloader.pt
|── training_info.json

Expected behavior

Successful conversion without any issue.

Additional context

Activity

  1. added
    bug
    on Mar 18, 2026
  2. dhineshkumar-r commented on Mar 18, 2026

    @dhineshkumar-r
    ContributorAuthor
    1. Can someone help me understand why this would occur?
    2. Does training configuration matter? If yes, how should I change the conversion script accordingly?
  3. added
    needs-follow-up
    on Mar 20, 2026
  4. yuki-97 commented on Mar 25, 2026

    @yuki-97
    Contributor

    hi @RayenTian @yaoyu-33 , could you help to take a look?

  5. removed
    needs-follow-up
    on Mar 25, 2026
  6. dhineshkumar-r commented on Mar 25, 2026

    @dhineshkumar-r
    ContributorAuthor

    I had asked the same question in Megatron-Bridge Ref. The recommendation was to use the config of unsloth/gpt-oss-20b-BF16 and that helped resolve the issue.

    I update the conversion script locally to unblock myself. I can raise a PR with that change, if you folks think that'd be helpful.

  7. added
    needs-follow-up
    on Mar 27, 2026
  8. yuki-97 commented on Mar 28, 2026

    @yuki-97
    Contributor

    hi @dhineshkumar-r , thanks for the investigation!

    instead of just changing to unsloth/gpt-oss-20b-BF16, I tend to think it's better to have a guide for gpt-oss like Megatron-Bridge, wdyt? @terrykong

  9. removed
    needs-follow-up
    on Mar 28, 2026
  10. dhineshkumar-r commented on Mar 29, 2026

    @dhineshkumar-r
    ContributorAuthor

    Hey @yuki-97,

    To clarify, my proposed change is to update checkpoint conversion script to take an optional argument hf_model_name as an override.

  11. yuki-97 commented on Mar 30, 2026

    @yuki-97
    Contributor

    Hey @yuki-97,

    To clarify, my proposed change is to update checkpoint conversion script to take an optional argument hf_model_name as an override.

    Hey @dhineshkumar-r , I see, that sounds great, appreciate for your help!

  12. dhineshkumar-r commented on Apr 3, 2026

    @dhineshkumar-r
    ContributorAuthor

    Hey @yuki-97
    Here is the PR. Please take a look when you get a chance.
    #2202

  13. added
    qa_rcca_done
    on May 5, 2026
  14. qiaochuz-nv commented on May 5, 2026

    @qiaochuz-nv
    Contributor

    QA RCCA Analysis

    RCCA Status: Done
    RCCA Category: missing_test_case
    Test Action: create_new_test

    Fix PR: #2202
    Root Cause: convert_megatron_to_hf.py always used policy.model_name as the HF model class/source, so GPT-OSS Megatron checkpoints could load with many missing layers unless the HF model name was explicitly overridden.
    Trigger Config: GPT-OSS Megatron checkpoint conversion to HF format + converter path examples/converters/convert_megatron_to_hf.py + missing --hf-model-name override.

    Coverage Assessment:

    Area Result
    Existing Test nemo_llm/test_suite/rl/testcases/algorithms/test_grpo_gptoss_20b_megatron.sh
    Coverage Status MISSING_TEST_CASE
    Gap Existing GPT-OSS test covers GRPO Megatron training only; it does not exercise Megatron→HF checkpoint conversion or the --hf-model-name converter option.
    Corrective Action Created regression test: nemo_llm/test_suite/rl/testcases/sanitycheck/test_rcca_convert_megatron_to_hf_hf_model_name.sh (0-GPU static AST guard for --hf-model-name propagation). Local direct validation passed; suite-run status pending.

    Conclusion: GPT-OSS training coverage exists, but converter coverage is absent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommunity-requestqa_rcca_done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions