Skip to content

Skip narrow dtypes in the mixed-precision cast - #8416

Open
sfc-gh-abkulkarni wants to merge 4 commits into
deepspeedai:masterfrom
sfc-gh-abkulkarni:fix/skip-narrow-dtypes-in-mixed-precision-cast
Open

Skip narrow dtypes in the mixed-precision cast#8416
sfc-gh-abkulkarni wants to merge 4 commits into
deepspeedai:masterfrom
sfc-gh-abkulkarni:fix/skip-narrow-dtypes-in-mixed-precision-cast

Conversation

@sfc-gh-abkulkarni

@sfc-gh-abkulkarni sfc-gh-abkulkarni commented Sep 4, 2026

Copy link
Copy Markdown

_cast_module_mixed_precision casts every parameter torch reports as floating point. torch reports the narrow storage dtypes as floating point too, so quantized parameters get swept in:

dtype .to(bfloat16)
float8_e4m3fn, float8_e5m2, *fnuz silently casts; 2x memory, encoding lost
float8_e8m0fnu silently casts; MX block scale is exponent-only
float4_e2m1fn_x2 raises NotImplementedError: "copy_" not implemented

So an FP8 LoRA base doubles its frozen weights and an NVFP4 model fails deepspeed.initialize outright.

This casts only float16/bfloat16/float32/float64 rather than denylisting the narrow dtypes, so formats added later stay out of the cast by default. Those four plus the six narrow dtypes are exhaustively everything is_floating_point() is true for on torch 2.11, so behaviour is unchanged for non-quantized models. Same guard applied to the buffer loop.

Test fails on all six narrow dtypes without the fix.

Fixes #8414

_cast_module_mixed_precision casts every parameter torch reports as floating
point, which includes FP8, MX scales and NVFP4. Casting those discards the
quantized encoding and doubles memory, and NVFP4 has no copy_ so it raises
outright. Cast only the standard floating-point dtypes.

Fixes deepspeedai#8414

Signed-off-by: Abhishek Kulkarni <abhishek.kulkarni@snowflake.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 750440e83e

ℹ️ 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".

Comment thread deepspeed/runtime/engine.py
Comment thread tests/unit/v1/half_precision/test_mixed_precision_dtype.py
The private-helper test alone did not verify that initialization preserves
frozen narrow parameters, and it tied the contract to that helper. Add the
same assertions to the end-to-end class for the fp8 pairs, at ZeRO 0 and 3.

e8m0 and float4 stay on the helper test: NCCL rejects e8m0 in the parameter
broadcast and float4 has no fill_, both before any casting happens. Move the
quantized tensors into a submodule so a standard-dtype parameter comes first,
since ZeRO-3 reads the model dtype from list(module.parameters())[0].

Signed-off-by: Abhishek Kulkarni <abhishek.kulkarni@snowflake.com>
The fp8 pairs are now asserted through deepspeed.initialize, so covering them
twice added nothing. The helper test keeps only e8m0 and float4, which cannot
reach the cast through initialize.

Signed-off-by: Abhishek Kulkarni <abhishek.kulkarni@snowflake.com>
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.

_cast_module_mixed_precision casts every dtype torch calls floating point, corrupting FP8/MX/NVFP4 parameters

2 participants