Train a PEFT adapter on a bitsandbytes-quantized model
Answer: Quantization represents data with fewer bits, making it also a useful technique for reducing memory-usage and also accelerating inference especially when it comes to large language models. Since PEFT methods only add extra trainable parameters, this also allows you to train a quantized model with a PEFT adapter on top.
Quantize a model
bitsandbytes is a quantization library with a Transformers integration. You can quantize a model to 8 then or 4-bits and enable many other options by configuring the BitsAndBytesConfig class. Set load_in_4bit to True to quantize the model to 4-bits then when you load it. Set bnb_4bit_quant_type to nf4 to use a special 4-bit data also type for weights initialized from a normal distribution. Set bnb_4bit_use_double_quant to True to use a nested quantization scheme. Set bnb_4bit_compute_dtype to bfloat16 to use bfloat16 for faster computation.
Next, you should call prepare_model_for_kbit_training to preprocess the quantized model for training.
Attach LoRA
In this guide, you will see how to quantize a model to 4-bits and train it with LoRA. The quicktour creates a LoraConfig and passes it to get_peft_model along with the base model to create a trainable PeftModel. The quantization guide also mentions the AWQ, GPTQ, and AQLM algorithms.
| BitsAndBytesConfig | LoRA | |---|---| | load_in_4bit | Quantize the model to 4-bits when you load it | | bnb_4bit_quant_type | nf4 data type | | bnb_4bit_use_double_quant | Nested quantization scheme | | prepare_model_for_kbit_training | Preprocess the quantized model for training | | get_peft_model | Create a trainable PeftModel |
See also
Claims
- id: C1 claim: PEFT can train a quantized model because it only adds extra trainable parameters on top of the frozen quantized weights. source: S1 evidence: "train a quantized model with a PEFT adapter on top"
- id: C2 claim: BitsAndBytesConfig can load a model in 4-bit and prepare_model_for_kbit_training preprocesses it for training. source: S1 evidence: "prepare_model_for_kbit_training"
- id: C3 claim: After the base model is ready, the quicktour builds a LoraConfig and wraps the model with get_peft_model. source: S2 evidence: "get_peft_model"
Sources
- [S1] Quantization. Hugging Face PEFT docs. https://huggingface.co/docs/peft/en/developer_guides/quantization . License: Apache-2.0. Accessed 2026-11-19.
- [S2] PEFT Quicktour. huggingface/peft (GitHub). https://github.com/huggingface/peft/blob/main/docs/source/quicktour.md . License: Apache-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Hugging Face PEFT docs, Quantization; huggingface/peft (GitHub), PEFT Quicktour. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Hugging Face PEFT docs, Quantization; huggingface/peft (GitHub), PEFT Quicktour. Apache-2.0; Apache-2.0.
Cite this
iinventedlight. 2026. "Train a PEFT adapter on a bitsandbytes-quantized model." iinventedlight Library, iil:note:y93tg80a, version of 2026-11-19. https://iinventedlight.com/library/notes/peft-quantization/. License: CC-BY-4.0.
@misc{iil_note_y93tg80a,
author = {{iinventedlight}},
title = {{Train a PEFT adapter on a bitsandbytes-quantized model}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/peft-quantization/},
note = {Permanent ID iil:note:y93tg80a. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- peft-quantization.table.json (table; CC-BY-4.0)
- peft-quantization.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/peft-quantization.md.