Skip to content

Restore QuantState nested_offset in its original dtype - #2147

Open
klin2024 wants to merge 1 commit into
bitsandbytes-foundation:mainfrom
klin2024:dev/klin/quantstate-nested-offset-dtype
Open

klin2024 wants to merge 1 commit into
bitsandbytes-foundation:mainfrom
klin2024:dev/klin/quantstate-nested-offset-dtype

Conversation

@klin2024

@klin2024 klin2024 commented Nov 18, 2026 •

Copy link
Copy Markdown

QuantState.from_dict rebuilds nested_offset with torch.tensor(float(...)), which follows the global default dtype. Loaders that call Params4bit.from_prequantized under torch.set_default_dtype(torch.bfloat16) get a rounded offset (0.048583984375 instead of 0.04863208532333374 in one case), which shifts every dequantized absmax of a compress_statistics=True weight. On a 32B NF4 text encoder this gave about 0.6% relative output drift versus the model before serialization.

Fix: build the offset with the stored nested_dtype, the dtype it was computed in.

The new test round-trips as_dict / from_dict under fp16 and bf16 default dtypes and checks that the offset and the dequantized weight are bit-exact. On CPU and CUDA (H100) it fails before the fix (8/8) and passes after.

@klin2024
klin2024 force-pushed the dev/klin/quantstate-nested-offset-dtype branch from 4664b7d to 7415026 Compare November 18, 2026 16:08
QuantState.from_dict rebuilt nested_offset with torch.tensor(float), which
follows the global default dtype. Loaders that build models under
torch.set_default_dtype(torch.bfloat16) (or float16) therefore got a rounded
offset, and every dequantized absmax of a compress_statistics=True weight
shifted by the rounding error. Build it with nested_dtype instead.

Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>
@klin2024
klin2024 force-pushed the dev/klin/quantstate-nested-offset-dtype branch from 7415026 to a91783e Compare November 18, 2026 16:15
@klin2024 klin2024 changed the title Restore QuantState nested_offset in its original dtype, not the default dtype Restore QuantState nested_offset in its original dtype Nov 18, 2026
@klin2024
klin2024 marked this pull request as ready for review November 18, 2026 16:35

This branch has not been deployed

No deployments
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.

1 participant