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

debug dop lora #530

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cc16065
reproduce bug
strint Jan 17, 2024
c187f9f
use all_dynamic
strint Jan 17, 2024
12ff0bd
align dynamic param with torch
strint Jan 18, 2024
d0d056d
add doc of oneflow_compile
strint Jan 18, 2024
b96c27e
format
strint Jan 18, 2024
110f104
Merge branch 'align_dynamic' into sdxl_dpo
strint Jan 18, 2024
886b12d
use new dynamic api
strint Jan 18, 2024
d78c84f
support text encoder
marigoold Jan 30, 2024
4e56a68
refine code
marigoold Jan 30, 2024
46a6a3f
compatible for prev diffusers version
marigoold Jan 30, 2024
ffdf6ed
Update __init__.py
marigoold Jan 30, 2024
9877fb1
refine
marigoold Jan 30, 2024
9aa6af4
Merge branch 'dev_wy_lora_support_textencoder' of github.com:Oneflow-…
marigoold Jan 30, 2024
e252c38
update readme
marigoold Jan 31, 2024
7ede9af
refine doc
marigoold Jan 31, 2024
ef1eb8c
remove unfuse in fuse func
marigoold Jan 31, 2024
cead728
Merge branch 'main' into dev_wy_lora_support_textencoder
marigoold Jan 31, 2024
54903ce
refine
marigoold Jan 31, 2024
55c65b9
rename
marigoold Jan 31, 2024
7892a5b
remove out dated lora.py
marigoold Jan 31, 2024
93388a4
update readme
marigoold Jan 31, 2024
cb05e3e
refine
marigoold Jan 31, 2024
a964b23
Update lora.py
marigoold Jan 31, 2024
46b54c2
fix bug
marigoold Jan 31, 2024
2cf586e
Merge branch 'dev_wy_lora_support_textencoder' of github.com:Oneflow-…
marigoold Jan 31, 2024
8743725
refine
marigoold Jan 31, 2024
cf0452f
Merge branch 'main' into dev_wy_lora_support_textencoder
marigoold Feb 1, 2024
628a608
dual modulelist setattr fix bug, compatible with DualModule input
marigoold Feb 1, 2024
c773ac4
remove utils/__init__.py
marigoold Feb 2, 2024
6009d1a
modify examples
marigoold Feb 2, 2024
4a43b0b
update doc, and var name
marigoold Feb 2, 2024
57e8ca1
Merge branch 'dev_wy_lora_support_textencoder' into fix_wy_dualmodule…
marigoold Feb 2, 2024
bf57ec6
compatible for PEFT
marigoold Feb 2, 2024
0e7b951
Merge branch 'main' into fix_wy_dualmodulelist_setattr
marigoold Feb 3, 2024
daed844
fix merge
strint Feb 4, 2024
e2c3991
Merge branch 'main' into fix_wy_dualmodulelist_setattr
strint Feb 4, 2024
71865a2
update to compile pipe
strint Feb 4, 2024
e3ad735
Merge branch 'fix_wy_dualmodulelist_setattr' of https://github.com/si…
strint Feb 4, 2024
79a0c2b
Merge branch 'main' into sdxl_dpo
strint Feb 5, 2024
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
44 changes: 44 additions & 0 deletions examples/text_to_image_sdxl_dpo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Need `pip install -U peft transformers`

from diffusers import DiffusionPipeline
from diffusers.utils import make_image_grid
import torch

pipe = DiffusionPipeline.from_pretrained(
"/share_nfs/hf_models/sd-turbo", # SD Turbo is a destilled version of Stable Diffusion 2.1
#"stabilityai/sd-turbo", # SD Turbo is a destilled version of Stable Diffusion 2.1
# "stabilityai/stable-diffusion-2-1", # for the original stable diffusion 2.1 model
torch_dtype=torch.float16, variant="fp16"
)
pipe.to("cuda")

from onediffx import compile_pipe

pipe = compile_pipe(pipe)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

use compile_pipe


pipe.load_lora_weights("radames/sd-21-DPO-LoRA", adapter_name="dpo-lora-sd21")
pipe.set_adapters(["dpo-lora-sd21"], adapter_weights=[1.0]) # you can play with adapter_weights to increase the effect of the LoRA model
seed = 123123
prompt = "portrait headshot professional of elon musk"
negative_prompt = "3d render, cartoon, drawing, art, low light"
generator = torch.Generator().manual_seed(seed)

def run_once(dynamic_guidance_scale):
for i in range(2):
images = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
width=512,
height=512,
num_inference_steps=2,
generator=generator,
guidance_scale=dynamic_guidance_scale,
num_images_per_prompt=4
).images
make_image_grid(images, 1, 4)

run_once(1.0)
# Adjust guidance_scale
# Will raise error
run_once(1.5)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no compile time cost now for new guidance_scale now


Loading