Plumb model_cfg.fp32_output through Float16Module#52
Merged
Conversation
The fp32_output kwarg on Float16Module was never forwarded by either trainer (lm_trainer.py and packed_model.py), so its consumer in Float16Module.forward fell back to its default of True regardless of the model config. Setting model_cfg.fp32_output=False was silently a no-op, and the final logits always upcast to fp32. This patch: - Forwards getattr(model_config, "fp32_output", True) in both trainers. - Declares fp32_output: bool = True on MegatronPPModelConfig (sibling to fp32_residual_connection) so it is discoverable. Default behavior is preserved -- existing recipes are unaffected. Recipes that opt out (model_cfg.fp32_output = False) now correctly skip the fp32 logit upcast, which bounds transient memory on long-seq + large-vocab bf16 configs (e.g. vocab=248k, seq=128k saves ~14 GB). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Randomizez
approved these changes
May 5, 2026
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.
Summary
Float16Moduleaccepts anfp32_outputkwarg (defaultTrue) and honorsit in
forward, but neither trainer forwards it:lm_trainer.py:352andpacked_model.py:107instantiateFloat16Module(model_module, params_dtype)with two args only. The kwarg has been silently dead.
getattr(model_config, "fp32_output", True)from bothtrainers and declares
fp32_output: bool = TrueonMegatronPPModelConfig(sibling to
fp32_residual_connection) so the flag has a discoverable home.True); recipes that opt out now correctlyskip the fp32 logit upcast in
Float16Module.forward, bounding transientmemory on long-seq + large-vocab bf16 configs.
Repro
model_cfg.fp32_output = False.add ~14 GB transient activation, OOMing on borderline configs.
Verification
successfully with
model_cfg.fp32_output = False. The fp32 logit upcast iscorrectly skipped and the ~14 GB transient activation is reclaimed.
fp32_output=True) is unchanged:getattr(..., True)keepsprior behavior for all existing recipes.
No unit test added — the fix is config plumbing; the kwarg's runtime
behavior in
Float16Module.forwardis exercised by every existing fp16/bf16training run.
🤖 Generated with Claude Code