← All notes

Quantization in Transformers: load-time vs pre-quantized

Answer: Quantization stores weights (and sometimes activations) in fewer bits so the model needs less memory; in Transformers you either pass a quantization config to from_pretrained or load a checkpoint that is already quantized.

Memory rule of thumb

Models usually load in bf16 at 2 bytes per parameter. An 8B model needs about 16GB in bf16. At 8 bits it needs about 8GB; at 4 bits, about 4–5GB. Each drop in bits costs some accuracy.

Two paths

bitsandbytes

bitsandbytes offers LLM.int8() for 8-bit inference and QLoRA, a 4-bit technique that stays trainable through small LoRA weights. Quantizing in 8-bit halves the memory usage.

Artifacts

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Hugging Face docs (huggingface/transformers, huggingface/huggingface_hub, huggingface/diffusers on GitHub), Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Hugging Face docs, Quantization overview, Apache-2.0 (huggingface docs repos); Hugging Face docs, Bitsandbytes, Apache-2.0 (huggingface docs repos).

Cite this

Permanent ID: iil:note:8szmwr6d

iinventedlight. 2026. "Quantization in Transformers: load-time vs pre-quantized." iinventedlight Library, iil:note:8szmwr6d, version of 2026-11-09. https://iinventedlight.com/library/notes/hf-transformers-quantization-overview/. License: CC-BY-4.0.

@misc{iil_note_8szmwr6d,
  author = {{iinventedlight}},
  title = {{Quantization in Transformers: load-time vs pre-quantized}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-09},
  url = {https://iinventedlight.com/library/notes/hf-transformers-quantization-overview/},
  note = {Permanent ID iil:note:8szmwr6d. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/hf-transformers-quantization-overview.md.