Skip to content

Fix GPT-OSS final norm reconstruction in FakeBaseModel - #2897

Merged
h-guo18 merged 1 commit into
NVIDIA:mainfrom
sragrawal:sandeepa/gptoss-final-norm-reuse
Oct 23, 2026
Merged

h-guo18 merged 1 commit into
NVIDIA:mainfrom
sragrawal:sandeepa/gptoss-final-norm-reuse

Conversation

@sragrawal

@sragrawal sragrawal commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix.

GPT-OSS draft training cannot reconstruct teacher logits from hidden states
captured before the final normalization because FakeBaseModel has no GPT-OSS
final-norm mapping.

Register GPT-OSS and reuse Transformers' GptOssRMSNorm. Follow its loading
dtype policy: BF16 and FP32 keep the requested precision; FP16 loading keeps
the norm weights in FP32. Later explicit model dtype conversions retain normal
PyTorch behavior.

Usage

No new flag or dependency. Existing GPT-OSS FakeBaseModel loading selects
the normalization automatically.

Testing

pytest tests/unit/torch/speculative/plugins/test_modeling_final_norm.py \
  -q --durations=10
  • 19 focused CPU tests passed with PyTorch 2.13
    and Transformers 5.18. Changed-file pre-commit passed, including mypy and Bandit.
  • Tests compare with a real tiny GptOssForCausalLM loaded from local
    safetensors: BF16/FP32 checkpoint weights crossed with FP32/BF16/FP16 loading.
    They check exact norm weights, logits, input/scale gradients and save/reload
    parity.
  • Before-fix controls produced seven GPT-OSS failures. An always-FP32 norm
    control fails the two BF16 cases.
  • The existing GPT-OSS selector expectation changes from unsupported to the
    registered norm. Other model assertions remain intact.

Before your PR is "Ready for review"

  • Is this change backward compatible?: Yes; existing model mappings and norm classes are unchanged.
  • If you copied code or added a new dependency, did you follow CONTRIBUTING.md?: No copied implementation or new dependency; reuses Transformers.
  • Did you write any new necessary tests?: Yes; one parametrized integration test in the existing test module.
  • Did you update Changelog?: Yes.
  • Did you get Claude approval on this PR?: Earlier local review passed; no new Claude review for this rebase.

Additional Information

AI-assisted implementation and testing using Codex. No changes to training
algorithms, loss masking, launchers or serving code.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed GPT-OSS draft training with pre-normalization teacher hidden states.
    • Improved GPT-OSS reconstructed logit generation with support for the model’s final normalization layer. Normalization now handles FP16 model weights and works across supported data types, including during model loading and checkpoint restoration. This helps maintain consistent outputs and gradients when using GPT-OSS with speculative decoding.

@sragrawal
sragrawal requested review from a team as code owners October 20, 2026 17:52
@sragrawal
sragrawal requested a review from ChenhanYu October 20, 2026 17:52
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/Model-Optimizer/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 557b2115-7f7b-4dbe-9a6c-ff236f4089c4
📥 Commits

Reviewing files that changed from the base of the PR and between ab57299 and 922e0bf.

📒 Files selected for processing: 1
  • CHANGELOG.rst
🚧 Files skipped from review as they are similar to previous changes: 1
  • CHANGELOG.rst

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

📝 Walkthrough

GPT-OSS models now use a final-norm implementation for fake-base logit reconstruction. The implementation stores weights in FP32 when the requested dtype is FP16. Parametrized tests cover loading, outputs, gradients, serialization, and reload behavior.

Changes: GPT-OSS final-norm support

Layer / File(s) Summary
Implement and validate GPT-OSS final norm
modelopt/torch/speculative/plugins/modeling_final_norm.py, tests/unit/torch/speculative/plugins/test_modeling_final_norm.py, CHANGELOG.rst
The plugin registers a GPT-OSS final-norm implementation and maps GPT-OSS models to it. Tests cover dtype combinations, normalized outputs, logits, gradients, and save-and-reload behavior. The changelog adds a GPT-OSS draft-training bug-fix entry.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: h-guo18

Merge Risk: ⚪ Minimal · up to 922e0

The GPT-OSS final-norm fix appears ready to merge after normal checks; no actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing GPT-OSS final-norm reconstruction in FakeBaseModel.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed PASS. The pull request changes modelopt/torch/speculative/plugins/modeling_final_norm.py and its test only. The diff adds no torch.load(..., weights_only=False), pickle-enabled NumPy loading, hard…
Full details: Security Anti-Patterns

Explanation

PASS. The pull request changes modelopt/torch/speculative/plugins/modeling_final_norm.py and its test only. The diff adds no torch.load(..., weights_only=False), pickle-enabled NumPy loading, hardcoded trust_remote_code=True, external-input eval() or exec(), or # nosec. No pyproject.toml or requirements file changes add dependencies.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.94%. Comparing base (8c8ea45) to head (922e0bf).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2897      +/-   ##
==========================================
- Coverage   79.63%   78.94%   -0.70%     
==========================================
  Files         659      659              
  Lines       74141    74146       +5     
==========================================
- Hits        59045    58536     -509     
- Misses      15096    15610     +514     
Flag Coverage Δ
examples-diffusers 20.06% <60.00%> (+<0.01%) ⬆️
examples-gpt-oss 13.54% <60.00%> (+<0.01%) ⬆️
examples-hf_ptq 23.46% <60.00%> (+0.01%) ⬆️
examples-llm_distill 13.61% <60.00%> (-0.01%) ⬇️
examples-llm_eval 17.26% <60.00%> (-0.01%) ⬇️
examples-llm_qat 17.50% <60.00%> (-0.01%) ⬇️
examples-llm_sparsity 16.86% <60.00%> (-0.01%) ⬇️
examples-megatron_bridge 26.44% <60.00%> (-0.19%) ⬇️
examples-specdec_bench 13.32% <60.00%> (+<0.01%) ⬆️
examples-speculative_decoding 17.49% <60.00%> (-0.07%) ⬇️
examples-torch_onnx 21.39% <60.00%> (-0.03%) ⬇️
examples-torch_trt 15.26% <60.00%> (-0.01%) ⬇️
examples-vllm_serve 17.49% <60.00%> (-0.01%) ⬇️
gpu 58.93% <60.00%> (-1.20%) ⬇️
regression 15.12% <60.00%> (-0.01%) ⬇️
unit 60.75% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cjluo-nv cjluo-nv 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.

Bot review (gpt-6.1-sol) — DM the bot to share feedback.

LGTM: the fix reuses Transformers’ normalization and has strong parity coverage; the justified existing-test update needs human sign-off.

Needs action:

  • Confirm the updated GPT-OSS expectation in test_modeling_final_norm.py: registering the matching norm legitimately replaces the previous unsupported-model assertion.

No action needed:

  • Coverage checks checkpoint dtypes, loading precision, exact logits and gradients, and save/reload parity.
  • Tests were inspected but not executed during this review.

@sragrawal

Copy link
Copy Markdown
Contributor Author
  • Confirm the updated GPT-OSS expectation in test_modeling_final_norm.py: registering the matching norm legitimately replaces the previous unsupported-model assertion.

Confirmed. Adding GPT-OSS support requires replacing the old “unsupported” test expectation, and includes parity tests against Transformers.

@h-guo18 h-guo18 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thanks!

@h-guo18
h-guo18 merged commit 5760a04 into NVIDIA:main Oct 23, 2026
56 checks passed
@sragrawal
sragrawal deleted the sandeepa/gptoss-final-norm-reuse branch November 7, 2026 06:20
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.

3 participants