Skip to content

Commit 711075f

Browse files
author
nemo
committed
Merge remote-tracking branch 'huggingface/main' into feat/lycoris-conv1x1-support
2 parents 3fca72a + 246fe4d commit 711075f

File tree

308 files changed

+33713
-7188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+33713
-7188
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,14 @@ body:
2323
2424
Please tag fewer than 3 people.
2525
26-
Library: @benjaminbossan @sayakpaul
26+
Library: @benjaminbossan @githubnemo
27+
28+
diffusers integration: @benjaminbossan @sayakpaul
2729
2830
Documentation: @stevhliu
2931
3032
placeholder: "@Username ..."
3133

32-
- type: checkboxes
33-
id: information-scripts-examples
34-
attributes:
35-
label: Information
36-
description: 'The problem arises when using:'
37-
options:
38-
- label: "The official example scripts"
39-
- label: "My own modified scripts"
40-
41-
- type: checkboxes
42-
id: information-tasks
43-
attributes:
44-
label: Tasks
45-
description: "The tasks I am working on are:"
46-
options:
47-
- label: "An officially supported task in the `examples` folder"
48-
- label: "My own task or dataset (give details below)"
49-
5034
- type: textarea
5135
id: reproduction
5236
validations:

.github/ISSUE_TEMPLATE/feature-request.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,11 @@ body:
1111
description: |
1212
A clear and concise description of the feature proposal. Please provide a link to the paper and code in case they exist.
1313
14-
- type: textarea
15-
id: motivation
16-
validations:
17-
required: true
18-
attributes:
19-
label: Motivation
20-
description: |
21-
Please outline the motivation for the proposal. Is your feature request related to a problem?
22-
2314
- type: textarea
2415
id: contribution
2516
validations:
2617
required: true
2718
attributes:
2819
label: Your contribution
2920
description: |
30-
Is there any way that you could help, e.g. by submitting a PR?
21+
Is there any way that you could help, e.g. by submitting a PR?
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Deploy "method_comparison" Gradio to Spaces
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- "method_comparison/**"
8+
workflow_dispatch:
9+
10+
permissions: {}
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # full history needed for subtree
20+
persist-credentials: false
21+
22+
- name: Authenticate via ~/.netrc
23+
env:
24+
HF_TOKEN: ${{ secrets.PEFT_INTERNAL_REPO_READ_WRITE }}
25+
run: |
26+
# netrc needs BOTH login and password entries
27+
printf "machine huggingface.co\nlogin hf\npassword ${HF_TOKEN}\n" >> ~/.netrc
28+
chmod 600 ~/.netrc
29+
30+
- name: Deploy method_comparison app to HF Spaces
31+
run: |
32+
cd method_comparison
33+
git init
34+
# Spaces expect requirements.txt
35+
mv requirements-app.txt requirements.txt
36+
git config user.name "github-actions[bot]"
37+
git config user.email "github-actions[bot]@users.noreply.github.com"
38+
git remote add gradio-app https://huggingface.co/spaces/peft-internal-testing/PEFT-method-comparison
39+
git add .
40+
git commit -m "🚀 Deploy method comparison app from GH action"
41+
git push -f gradio-app HEAD:main

.github/workflows/test-docker-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
needs: get_changed_files
3737
name: Build Docker images on modified files
3838
runs-on: ubuntu-latest
39-
if: ${{ needs.get_changed_files.outputs.matrix }} != ''
39+
if: ${{ needs.get_changed_files.outputs.matrix != '[]' }}
4040
strategy:
4141
fail-fast: false
4242
matrix:

.github/workflows/tests.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
tests:
4040
needs: check_code_quality
4141
strategy:
42-
# TODO: remove 'fail-fast' line once timeout issue from the Hub is solved
4342
fail-fast: false
4443
matrix:
4544
python-version: ["3.9", "3.10", "3.11", "3.12"]
@@ -87,8 +86,27 @@ jobs:
8786
run: |
8887
pip install --force-reinstall -U "numpy<2.0.0"
8988
- name: Test with pytest
89+
# MacOS tests are currently too flaky and will fail almost each time. Thus, continue (green checkmark) even if
90+
# they fail, but add a notice so that the failure is not completely silent
91+
continue-on-error: ${{ matrix.os == 'macos-13' }}
92+
shell: bash
9093
run: |
94+
set +e
9195
make test
96+
status=$?
97+
# Post a notice only if this is macOS AND tests failed
98+
if [ "$status" -ne 0 ] && [ "${{ matrix.os }}" = "macos-13" ]; then
99+
{
100+
echo "## ⚠️ macOS tests failed"
101+
echo ""
102+
echo "- OS: ${{ matrix.os }}"
103+
echo "- Python: ${{ matrix.python-version }}"
104+
echo ""
105+
echo "Check the logs from this step for details."
106+
} >> "$GITHUB_STEP_SUMMARY"
107+
fi
108+
# Return the real status. On macOS this won't fail the job because of continue-on-error.
109+
exit $status
92110
- name: Dump cache content and diff
93111
# This is just debug info so that we can monitor if the model cache diverges substantially
94112
# over time and what the diverging model is.

.github/zizmor.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ rules:
1313
- build_docker_images.yml:103:9
1414
- build_docker_images.yml:136:9
1515
- build_docker_images.yml:169:9
16+
unpinned-images:
17+
ignore:
18+
# We want to test these images with the latest version and we're not using them
19+
# to deploy anything so we deem it safe to use those, even if they are unpinned.
20+
- nightly-bnb.yml:30:7
21+
- nightly-bnb.yml:155:7
22+
- nightly.yml:27:7
23+
- nightly.yml:77:7
24+
- torch_compile_tests.yml:32:7

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.9.2
3+
rev: v0.12.8
44
hooks:
55
- id: ruff
66
args:

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ tests_core_multi_gpu:
3131
tests_core_single_gpu:
3232
python -m pytest -m single_gpu_tests tests/test_common_gpu.py $(if $(IS_GITHUB_CI),--report-log "core_single_gpu.log",)
3333

34+
# exclude gemma tests, as generation fails with torch.compile, these failures
35+
# trigger side effects that make other tests fail with 'RuntimeError: Offset
36+
# increment outside graph capture encountered unexpectedly.'
37+
# TODO re-enable gemma once/if it is fixed
3438
tests_common_gpu:
35-
python -m pytest tests/test_decoder_models.py $(if $(IS_GITHUB_CI),--report-log "common_decoder.log",)
39+
python -m pytest tests/test_decoder_models.py -k "not gemma" $(if $(IS_GITHUB_CI),--report-log "common_decoder.log",)
3640
python -m pytest tests/test_encoder_decoder_models.py $(if $(IS_GITHUB_CI),--report-log "common_encoder_decoder.log",)
3741
python -m pytest tests/test_gptqmodel.py $(if $(IS_GITHUB_CI),--report-log "gptqmodel_gpu.log",)
3842

README.md

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,43 @@ pip install peft
3939
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!
4040

4141
```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
4644

45+
device = torch.accelerator.current_accelerator().type if hasattr(torch, "accelerator") else "cuda"
46+
model_id = "Qwen/Qwen2.5-3B-Instruct"
47+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map=device)
4748
peft_config = LoraConfig(
48-
task_type=TaskType.SEQ_2_SEQ_LM, inference_mode=False, r=8, lora_alpha=32, lora_dropout=0.1
49+
r=16,
50+
lora_alpha=32,
51+
task_type=TaskType.CAUSAL_LM,
52+
# target_modules=["q_proj", "v_proj", ...] # optionally indicate target modules
4953
)
50-
51-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path)
5254
model = get_peft_model(model, peft_config)
5355
model.print_trainable_parameters()
54-
"trainable params: 2359296 || all params: 1231940608 || trainable%: 0.19151053100118282"
56+
# prints: trainable params: 3,686,400 || all params: 3,089,625,088 || trainable%: 0.1193
57+
58+
# now perform training on your dataset, e.g. using transformers Trainer, then save the model
59+
model.save_pretrained("qwen2.5-3b-lora")
5560
```
5661

5762
To load a PEFT model for inference:
5863

59-
```py
60-
from peft import AutoPeftModelForCausalLM
61-
from transformers import AutoTokenizer
62-
import torch
64+
```python
65+
from transformers import AutoModelForCausalLM, AutoTokenizer
66+
from peft import PeftModel
6367

64-
model = AutoPeftModelForCausalLM.from_pretrained("ybelkada/opt-350m-lora").to("cuda")
65-
tokenizer = AutoTokenizer.from_pretrained("facebook/opt-350m")
68+
device = torch.accelerator.current_accelerator().type if hasattr(torch, "accelerator") else "cuda"
69+
model_id = "Qwen/Qwen2.5-3B-Instruct"
70+
tokenizer = AutoTokenizer.from_pretrained(model_id)
71+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map=device)
72+
model = PeftModel.from_pretrained(model, "qwen2.5-3b-lora")
6673

67-
model.eval()
6874
inputs = tokenizer("Preheat the oven to 350 degrees and place the cookie dough", return_tensors="pt")
75+
outputs = model.generate(**inputs.to(device), max_new_tokens=50)
76+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
6977

70-
outputs = model.generate(input_ids=inputs["input_ids"].to("cuda"), max_new_tokens=50)
71-
print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
72-
73-
"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 [...]
7479
```
7580

7681
## Why you should use PEFT
@@ -124,6 +129,32 @@ The iterative diffusion process consumes a lot of memory which can make it diffi
124129
> [!TIP]
125130
> 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).
126131
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:
135+
136+
```python
137+
from peft import LoraConfig
138+
model = ... # transformers model
139+
peft_config = LoraConfig(...)
140+
model.add_adapter(lora_config, adapter_name="lora_1")
141+
```
142+
143+
To load a trained PEFT adapter, call `load_adapter`:
144+
145+
```python
146+
model = ... # transformers model
147+
model.load_adapter(<path-to-adapter>, adapter_name="lora_1")
148+
```
149+
150+
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+
127158
### Accelerate
128159

129160
[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
150181

151182
```bibtex
152183
@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},
154185
author = {Sourab Mangrulkar and Sylvain Gugger and Lysandre Debut and Younes Belkada and Sayak Paul and Benjamin Bossan},
155186
howpublished = {\url{https://github.com/huggingface/peft}},
156187
year = {2022}
157188
}
158-
```
189+
```

docs/source/_toctree.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@
126126
title: Trainable Tokens
127127
- local: package_reference/randlora
128128
title: RandLora
129+
- local: package_reference/shira
130+
title: SHiRA
131+
- local: package_reference/c3a
132+
title: C3A
133+
- local: package_reference/miss
134+
title: MiSS
135+
- local: package_reference/road
136+
title: RoAd
129137

130138
title: Adapters
131139
- sections:

0 commit comments

Comments
 (0)