You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-21Lines changed: 52 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,38 +39,43 @@ pip install peft
39
39
Prepare a model for training with a PEFT method such as LoRA by wrapping the base model and PEFT configuration with `get_peft_model`. For the bigscience/mt0-large model, you're only training 0.19% of the parameters!
40
40
41
41
```python
42
-
from transformers import AutoModelForSeq2SeqLM
43
-
from peft import get_peft_config, get_peft_model, LoraConfig, TaskType
44
-
model_name_or_path ="bigscience/mt0-large"
45
-
tokenizer_name_or_path ="bigscience/mt0-large"
42
+
from transformers import AutoModelForCausalLM
43
+
from peft import LoraConfig, TaskType, get_peft_model
"Preheat the oven to 350 degrees and place the cookie dough in the center of the oven. In a large bowl, combine the flour, baking powder, baking soda, salt, and cinnamon. In a separate bowl, combine the egg yolks, sugar, and vanilla."
78
+
# prints something like: Preheat the oven to 350 degrees and place the cookie dough in a baking dish [...]
74
79
```
75
80
76
81
## Why you should use PEFT
@@ -124,6 +129,32 @@ The iterative diffusion process consumes a lot of memory which can make it diffi
124
129
> [!TIP]
125
130
> Take a look at the [examples/lora_dreambooth/train_dreambooth.py](examples/lora_dreambooth/train_dreambooth.py) training script to try training your own Stable Diffusion model with LoRA, and play around with the [smangrul/peft-lora-sd-dreambooth](https://huggingface.co/spaces/smangrul/peft-lora-sd-dreambooth) Space which is running on a T4 instance. Learn more about the PEFT integration in Diffusers in this [tutorial](https://huggingface.co/docs/peft/main/en/tutorial/peft_integrations#diffusers).
126
131
132
+
### Transformers
133
+
134
+
PEFT is directly integrated with [Transformers](https://huggingface.co/docs/transformers/main/en/peft). After loading a model, call `add_adapter` to add a new PEFT adapter to the model:
And to switch between different adapters, call `set_adapter`:
151
+
152
+
```python
153
+
model.set_adapter("lora_2")
154
+
```
155
+
156
+
The Transformers integration doesn't include all the functionalities offered in PEFT, such as methods for merging the adapter into the base model.
157
+
127
158
### Accelerate
128
159
129
160
[Accelerate](https://huggingface.co/docs/accelerate/index) is a library for distributed training and inference on various training setups and hardware (GPUs, TPUs, Apple Silicon, etc.). PEFT models work with Accelerate out of the box, making it really convenient to train really large models or use them for inference on consumer hardware with limited resources.
@@ -150,9 +181,9 @@ To use 🤗 PEFT in your publication, please cite it by using the following BibT
150
181
151
182
```bibtex
152
183
@Misc{peft,
153
-
title = {PEFT: State-of-the-art Parameter-Efficient Fine-Tuning methods},
184
+
title = {{PEFT}: State-of-the-art Parameter-Efficient Fine-Tuning methods},
154
185
author = {Sourab Mangrulkar and Sylvain Gugger and Lysandre Debut and Younes Belkada and Sayak Paul and Benjamin Bossan},
0 commit comments