Skip to content

do not overwrite storage dtypes - #1716

Merged
jlarson4 merged 3 commits into
TransformerLensOrg:devfrom
MdSadiqMd:sadiq/do-not-overwrite-storage-dtypes
Aug 22, 2026
Merged

do not overwrite storage dtypes#1716
jlarson4 merged 3 commits into
TransformerLensOrg:devfrom
MdSadiqMd:sadiq/do-not-overwrite-storage-dtypes

Conversation

@MdSadiqMd

Copy link
Copy Markdown
Contributor

Description

When TransformerBridge.boot_transformers loads a quantized HuggingFace model, its post-load dtype normalization via cast_floating_params_to_dtype casts every floating-point parameter to the requested dtype. This includes floating-point parameters owned by the quantizer, such as FP8 scale tensors (e.g., float8_e8m0fnu).

On MXFP4 checkpoints like deepseek-ai/DeepSeek-V4-Flash-0731, loading with dtype=torch.bfloat16 changes the expert scales from torch.float8_e8m0fnu to torch.bfloat16. The packed int8 expert weights are left unchanged, so the weight/scale pair no longer describes the same quantization format, causing forward pass failures.

Fix implemented at two levels:

  1. Call-site skip: Skip cast_floating_params_to_dtype entirely when the model has an active quantization_config
  2. Function guard: Skip one-byte floats (FP8 dtypes) in cast_floating_params_to_dtype as a defensive guard

Fixes #1713

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@MdSadiqMd MdSadiqMd changed the title Sadiq/do not overwrite storage dtypes do not overwrite storage dtypes Aug 21, 2026

@jlarson4 jlarson4 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.

Hey @MdSadiqMd, thanks for the fix! A couple notes on the test coverage

Comment thread transformer_lens/model_bridge/sources/transformers.py Outdated
Comment thread tests/integration/model_bridge/test_bridge_integration.py Outdated
Comment thread tests/unit/utilities/test_multi_gpu_unit.py
Comment thread tests/unit/utilities/test_multi_gpu_unit.py Outdated
@jlarson4

Copy link
Copy Markdown
Collaborator

@MdSadiqMd I missed this the first time around, could you please rebase this to dev?

@MdSadiqMd

Copy link
Copy Markdown
Contributor Author

sure

@MdSadiqMd
MdSadiqMd force-pushed the sadiq/do-not-overwrite-storage-dtypes branch from 0319690 to 9fc6507 Compare August 21, 2026 22:10
@MdSadiqMd
MdSadiqMd changed the base branch from main to dev August 21, 2026 22:11
@jlarson4

Copy link
Copy Markdown
Collaborator

Hi @MdSadiqMd, just pushed a CI update to your branch that should help stabilize Full Code Coverage, there was a flaw in dev that was causing failures. Everything looks good, once this run passes I'll merge, thanks for your patience!

@jlarson4
jlarson4 merged commit c03d510 into TransformerLensOrg:dev Aug 22, 2026
25 checks passed
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.

[Bug Report] boot_transformers casts quantizer-owned scale parameters and breaks MXFP4 checkpoints

2 participants