Transformers documentation

Dequantize a model

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.2).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Dequantize a model

Dequantizing converts quantized weights back to a higher-precision dtype like bf16. Dequantize a model to fully fine-tune it, to run it on hardware the method’s kernels don’t support, or to convert it to another format. The result uses as much memory as an unquantized model, and it doesn’t recover the accuracy lost to rounding.

Transformers dequantizes in two ways, depending on the method.

MethodHow to dequantize
bitsandbytes, HIGGSCall dequantize() after loading.
compressed-tensors, Fine-grained FP8, GGUF, Metal, MXFP4Pass dequantize=True to the method’s config when loading.

Other methods raise a NotImplementedError from dequantize().

Dequantize after loading

Call dequantize() on a loaded model. It defaults to the dtype the model was loaded in. Pass dtype to choose another.

import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig

model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-0.6B",
    quantization_config=BitsAndBytesConfig(load_in_4bit=True),
    device_map="auto",
)
model = model.dequantize(dtype=torch.bfloat16)

dequantize() also removes the quantization_config, so save_pretrained() saves a regular full-precision checkpoint.

Dequantize while loading

Pass dequantize=True to the config of a method that supports it. The weights are dequantized as they load, so the quantized kernels are never used. The example below loads the MXFP4 weights of gpt-oss in bf16.

from transformers import AutoModelForCausalLM, Mxfp4Config

model = AutoModelForCausalLM.from_pretrained(
    "openai/gpt-oss-20b",
    quantization_config=Mxfp4Config(dequantize=True),
    device_map="auto",
)

Some methods dequantize automatically when their kernels can’t run. GGUF, for example, falls back to dequantizing when no kernel supports the file’s quantization types.

Update on GitHub