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

[Feature] Support OFT #1160

Merged
merged 30 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c7e201d
Support OFT
okotaku Nov 21, 2023
703bc43
add test
okotaku Nov 21, 2023
c0288cd
Update README
okotaku Nov 21, 2023
485ed40
fix code quality
okotaku Nov 22, 2023
497505e
fix test
okotaku Nov 22, 2023
0317485
Skip 1 test
okotaku Nov 22, 2023
c9b1118
fix eps rule and add more test
okotaku Nov 22, 2023
6536c32
feat: added examples to new OFT method
lukaskuhn-lku Nov 23, 2023
54623f5
fix: removed wrong arguments from model example
lukaskuhn-lku Nov 23, 2023
de09791
fix: changed name of inference file
lukaskuhn-lku Nov 23, 2023
8a37126
fix: changed prompt variable
lukaskuhn-lku Nov 23, 2023
38009b3
fix docs
okotaku Nov 23, 2023
1ef5c79
Merge pull request #1 from lukaskuhn-lku/oft
okotaku Nov 23, 2023
3daa236
fix: dreambooth inference revision based on feedback
Nov 24, 2023
bf07076
fix: review from BenjaminBossan
Nov 24, 2023
edf2fa6
Merge pull request #2 from lukaskuhn-lku/oft
okotaku Nov 25, 2023
da0073d
apply safe merge
okotaku Nov 25, 2023
dfd3600
del partially
okotaku Nov 25, 2023
6d247ad
refactor oft
okotaku Nov 27, 2023
3d0f6a6
refactor oft
okotaku Nov 27, 2023
58b5383
del unused line
okotaku Nov 28, 2023
a21a8a3
del unused line
okotaku Nov 28, 2023
6284f07
fix skip in windows
okotaku Nov 28, 2023
93b1282
skip test
okotaku Nov 28, 2023
0647abe
Add comments about bias added place
okotaku Nov 28, 2023
9a7738f
rename orig_weights to new_weights
okotaku Nov 28, 2023
a2c2143
use inverse instead of linalg.inv
okotaku Nov 28, 2023
b1a5ddf
Merge pull request #3 from okotaku/pr/okotaku/1160
okotaku Nov 28, 2023
e0161e9
delete alpha and scaling
okotaku Nov 28, 2023
377a4ef
Merge branch 'main' into oft
okotaku Nov 29, 2023
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Supported methods:
7. MultiTask Prompt Tuning: [Multitask Prompt Tuning Enables Parameter-Efficient Transfer Learning](https://arxiv.org/abs/2303.02861)
8. LoHa: [FedPara: Low-Rank Hadamard Product for Communication-Efficient Federated Learning](https://arxiv.org/abs/2108.06098)
9. LoKr: [KronA: Parameter Efficient Tuning with Kronecker Adapter](https://arxiv.org/abs/2212.10650) based on [Navigating Text-To-Image Customization:From LyCORIS Fine-Tuning to Model Evaluation](https://arxiv.org/abs/2309.14859) implementation
10. OFT: [Controlling Text-to-Image Diffusion by Orthogonal Finetuning](https://arxiv.org/abs/2306.07280)

## Getting started

Expand Down Expand Up @@ -274,9 +275,9 @@ An example is provided in `~examples/causal_language_modeling/peft_lora_clm_acce

### Text-to-Image Generation

| Model | LoRA | LoHa | LoKr | Prefix Tuning | P-Tuning | Prompt Tuning | IA3 |
| --------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| Stable Diffusion | ✅ | ✅ | ✅ | | | |
| Model | LoRA | LoHa | LoKr | OFT | Prefix Tuning | P-Tuning | Prompt Tuning | IA3 |
| --------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| Stable Diffusion | ✅ | ✅ | ✅ | ✅ | | | |


### Image Classification
Expand Down
89 changes: 89 additions & 0 deletions examples/oft_dreambooth/oft_dreambooth_inference.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The notebook assumes that the user ran the training script first to create an adapter, right? Let's mention that. Otherwise, we could maybe copy https://huggingface.co/takuoko/oft_test to our PEFT HF repo and link that one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned it now in PR#2. Don't know how to integrate the oft_test adapter into the PEFT HF repo so I would need some guidance to help with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay now as is, this way users who just open the notebook know what they should do first.

"cells": [
{
"cell_type": "markdown",
"id": "acd7b15e",
"metadata": {},
"source": [
"# Dreambooth with OFT\n",
"This Notebook assumes that you already ran the train_dreambooth.py script to create your own adapter."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "acab479f",
"metadata": {},
"outputs": [],
"source": [
"from diffusers import DiffusionPipeline\n",
"from diffusers.utils import check_min_version, get_logger\n",
"from peft import PeftModel\n",
"\n",
"# Will error if the minimal version of diffusers is not installed. Remove at your own risks.\n",
"check_min_version(\"0.10.0.dev0\")\n",
"\n",
"logger = get_logger(__name__)\n",
"\n",
"BASE_MODEL_NAME = \"stabilityai/stable-diffusion-2-1-base\"\n",
"ADAPTER_MODEL_PATH = \"INSERT MODEL PATH HERE\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pipe = DiffusionPipeline.from_pretrained(\n",
" BASE_MODEL_NAME,\n",
")\n",
"pipe.to('cuda')\n",
"pipe.unet = PeftModel.from_pretrained(pipe.unet, ADAPTER_MODEL_PATH + \"/unet\", adapter_name=\"default\")\n",
"pipe.text_encoder = PeftModel.from_pretrained(pipe.text_encoder, ADAPTER_MODEL_PATH + \"/text_encoder\", adapter_name=\"default\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prompt = \"A photo of a sks dog\"\n",
"image = pipe(\n",
" prompt,\n",
" num_inference_steps=50,\n",
" height=512,\n",
" width=512,\n",
").images[0]\n",
"image"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
},
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading