Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More convenient way to initialize LoftQ #1543

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/source/developer_guides/lora.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ lora_config = LoraConfig(..., init_lora_weights="loftq", loftq_config=loftq_conf
peft_model = get_peft_model(base_model, lora_config)
```

An easier way to apply LoftQ initialization is to use the convenience function `replace_lora_weights_loftq` from PEFT. This takes the quantized PEFT model as input and replaces the LoRA weights in-place with their LoftQ-initialized counterparts.
BenjaminBossan marked this conversation as resolved.
Show resolved Hide resolved

```python
from peft import replace_lora_weights_loftq
BenjaminBossan marked this conversation as resolved.
Show resolved Hide resolved

bnb_config = BitsAndBytesConfig(load_in_4bit, ...)
base_model = AutoModelForCausalLM.from_pretrained(..., quantization_config=bnb_config)
# note: don't pass init_lora_weights="loftq" or loftq_config!
lora_config = LoraConfig(task_type="CAUSAL_LM")
peft_model = get_peft_model(base_model, lora_config)
replace_lora_weights_loft(peft_model)
```

`replace_lora_weights_loftq` also allows to pass the argument `callback` to give you more fine-grained control on which layers should be modified or not. To see a more elaborate example of this, check out [this notebook](https://github.com/huggingface/peft/blob/main/examples/loftq_finetuning/LoftQ_weight_replacement.ipynb).
BenjaminBossan marked this conversation as resolved.
Show resolved Hide resolved

At the moment, using this convenience function has the following restrictions:

- The model file must be stored as a `safetensors` file.
- Only bitsandbytes 4bit quantization is supported.
BenjaminBossan marked this conversation as resolved.
Show resolved Hide resolved

<Tip>

Learn more about how PEFT works with quantization in the [Quantization](quantization) guide.
Expand Down
Loading
Loading