Mixed-precision: per-policy param/buffer dtype cast (preserve fp32 buffers)#8066
Open
sfc-gh-truwase wants to merge 4 commits into
Open
Mixed-precision: per-policy param/buffer dtype cast (preserve fp32 buffers)#8066sfc-gh-truwase wants to merge 4 commits into
sfc-gh-truwase wants to merge 4 commits into
Conversation
…ffers) Add data_types.param_dtype / buffer_dtype mirroring FSDP MixedPrecisionPolicy. Replace blanket module.half()/bfloat16() with a targeted cast so floating buffers (e.g. the rotary inv_freq) keep their loaded dtype unless buffer_dtype is explicitly set, matching HF/FSDP2 and avoiding RoPE precision drift. Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9aee8a9b8d
ℹ️ 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".
CPU unit tests cover dtype resolution and the targeted cast helper (params cast, fp32 buffers preserved unless buffer_dtype is set, zero-init param guard). A bf16 end-to-end test verifies the keys flow through DeepSpeedConfig and that the fp32 inv_freq buffer survives deepspeed.initialize. Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>
stas00
approved these changes
Jun 15, 2026
A data_types.param_dtype that disagrees with the fp16/bf16 enabled flag would cast params to a dtype the optimizer/master-weight/reduction paths (which derive the model dtype from those flags) do not expect. Validate config-only in _do_sanity_check so the run fails before any module cast or optimizer setup. Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com> Co-authored-by: Cursor <cursoragent@cursor.com>
stas00
reviewed
Jun 15, 2026
stas00
left a comment
Collaborator
There was a problem hiding this comment.
probably should add these to the config md in the docs, no?
Co-authored-by: Stas Bekman <stas00@users.noreply.github.com>
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
data_types.param_dtypeanddata_types.buffer_dtype(both defaultNone), mirroring FSDPMixedPrecisionPolicy.module.half()/module.bfloat16()in_configure_distributed_modelwith a targeted cast: parameters go toparam_dtype; floating buffers keep their loaded dtype unlessbuffer_dtypeis explicitly set.Motivation
The blanket cast downcasts every floating buffer, including the rotary
inv_freqbuffer that HF/FSDP2 keep in fp32. On long contexts the bf16inv_freqloses precision, RoPE angles drift, and logits/grads diverge from the FSDP2 reference. Preserving fp32 buffers by default fixes this;buffer_dtypeis the escape hatch to reproduce the legacy behavior.Behavior
param_dtypeunset -> derived from the fp16/bf16 enabled flag (legacy param behavior).buffer_dtypeunset -> buffers keep their loaded dtype (e.g. fp32inv_freq).buffer_dtypeset -> buffers force-cast (legacy blanket-cast parity).Test plan
param_dtype=bf16,buffer_dtypeunset -> params bf16,inv_freqstays fp32.buffer_dtype=bf16-> buffers downcast (legacy parity).Made with Cursor