Transformers documentation

Save and share 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

Save and share a model

Saving a model after quantizing it while loading lets you, and anyone you share it with, skip the quantization step next time. Calibration methods like GPTQ benefit the most because calibration can take minutes to hours.

Save the model

Call save_pretrained() on the quantized model to write the quantized weights and add the quantization_config to config.json.

from transformers import AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_4bit=True)
model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-0.6B",
    quantization_config=quantization_config,
    device_map="auto",
)
model.save_pretrained("Qwen3-0.6B-bnb-4bit")

Save the tokenizer to the same directory so the checkpoint is complete.

Push the model to the Hub

Call push_to_hub() to upload the quantized weights and config to a Hub repository. Log in with hf auth login first.

model.push_to_hub("Qwen3-0.6B-bnb-4bit")

Load the saved model

Load the saved checkpoint with from_pretrained() and no quantization config. Transformers reads the method from the quantization_config in config.json and loads the weights already quantized.

from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("your-username/Qwen3-0.6B-bnb-4bit", device_map="auto")

The method’s library must be installed wherever the checkpoint is loaded.

Methods that can’t save

Some methods can’t save their quantized weights, and save_pretrained() raises a ValueError for them.

MethodWhy
GGUFWeights load from a GGUF file. Save in GGUF format with llama.cpp tools instead.
NVFP4Saving isn’t supported. Quantize the model again when you load it.
QuantoSaving isn’t supported through Transformers.
QuarkSaving isn’t supported through Transformers.
AWQ with an ExLlama backendSaving isn’t supported with the ExLlama backends. Load the model with another backend to save it.

A quantized model with a PEFT adapter attached is an exception. save_pretrained() saves only the adapter weights, so it works with any method.

To save a model in full precision instead, dequantize it first. See Dequantize a model.

Update on GitHub