Update README.md
Browse files
README.md
CHANGED
@@ -4,7 +4,7 @@ pipeline_tag: text-to-image
|
|
4 |
inference: true
|
5 |
base_model: stabilityai/sd-turbo
|
6 |
---
|
7 |
-
# DPO LoRA Stable Diffusion
|
8 |
Model trained with LoRA implementation of Diffusion DPO Read more [here](https://github.com/huggingface/diffusers/tree/main/examples/research_projects/diffusion_dpo)
|
9 |
|
10 |
|
@@ -14,43 +14,52 @@ Base Model: https://huggingface.co/stabilityai/stable-diffusion-2-1
|
|
14 |
|
15 |
|
16 |
```python
|
17 |
-
|
18 |
-
from diffusers import DiffusionPipeline
|
19 |
-
from diffusers.utils import make_image_grid
|
20 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
)
|
27 |
-
pipe.
|
28 |
-
pipe.load_lora_weights("radames/stable-diffusion-2-1-DPO-LoRA", adapter_name="dpo-lora-sd21")
|
29 |
-
pipe.set_adapters(["dpo-lora-sd21"], adapter_weights=[1.0]) # you can play with adapter_weights to increase the effect of the LoRA model
|
30 |
-
seed = 123123
|
31 |
-
prompt = "portrait headshot professional of elon musk"
|
32 |
-
negative_prompt = "3d render, cartoon, drawing, art, low light"
|
33 |
generator = torch.Generator().manual_seed(seed)
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
make_image_grid(images, 1, 4)
|
45 |
```
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
Left Withoud DPO right with DPO LoRA
|
50 |
|
51 |
-
|
52 |
-
<img src=https://cdn-uploads.huggingface.co/production/uploads/6064e095abd8d3692e3e2ed6/Eg4LbyxCfhmsk2INzqODw.png style="max-width: 60rem;">
|
53 |
-
<img src=https://cdn-uploads.huggingface.co/production/uploads/6064e095abd8d3692e3e2ed6/GD7KumSCNweBWMJ1TArI-.png style="max-width: 60rem;">
|
54 |
-
<img src=https://cdn-uploads.huggingface.co/production/uploads/6064e095abd8d3692e3e2ed6/SO7QoA9lZJY9hI0U4fBLy.png style="max-width: 60rem;">
|
55 |
-
<img src=https://cdn-uploads.huggingface.co/production/uploads/6064e095abd8d3692e3e2ed6/ZWbQwIQ5OklEgF9RW581R.png style="max-width: 60rem;">
|
56 |
|
|
|
|
4 |
inference: true
|
5 |
base_model: stabilityai/sd-turbo
|
6 |
---
|
7 |
+
# DPO LoRA Stable Diffusion XL
|
8 |
Model trained with LoRA implementation of Diffusion DPO Read more [here](https://github.com/huggingface/diffusers/tree/main/examples/research_projects/diffusion_dpo)
|
9 |
|
10 |
|
|
|
14 |
|
15 |
|
16 |
```python
|
|
|
|
|
|
|
17 |
import torch
|
18 |
+
from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler
|
19 |
+
from diffusers.utils import make_image_grid
|
20 |
+
|
21 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
22 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
23 |
+
torch_dtype=torch.float16,
|
24 |
+
use_safetensors=True,
|
25 |
+
variant="fp16",
|
26 |
+
)
|
27 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
|
28 |
+
pipe.scheduler.config, use_karras_sigmas=True
|
29 |
+
)
|
30 |
+
pipe.to("cuda");
|
31 |
|
32 |
+
seed = 12341234123
|
33 |
+
prompt = "professional portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography"
|
34 |
+
negative_prompt = "3d render, cartoon, drawing, art, low light, blur, pixelated, low resolution, black and white"
|
35 |
+
num_inference_steps = 20
|
36 |
+
height = 1024
|
37 |
+
width = height
|
38 |
+
guidance_scale = 20
|
39 |
+
|
40 |
+
pipe.unload_lora_weights()
|
41 |
+
pipe.load_lora_weights(
|
42 |
+
"radames/diffusion-sdxl-dpo",
|
43 |
+
weight_name="checkpoint-5500/pytorch_lora_weights.safetensors",
|
44 |
+
# weight_name="pytorch_lora_weights.safetensors",
|
45 |
+
adapter_name="sdxl-dpo-lora",
|
46 |
)
|
47 |
+
pipe.set_adapters(["sdxl-dpo-lora"], adapter_weights=[1.0])
|
|
|
|
|
|
|
|
|
|
|
48 |
generator = torch.Generator().manual_seed(seed)
|
49 |
+
with_dpo = pipe(
|
50 |
+
prompt=prompt,
|
51 |
+
guidance_scale=guidance_scale,
|
52 |
+
negative_prompt=negative_prompt,
|
53 |
+
num_inference_steps=num_inference_steps,
|
54 |
+
width=width,
|
55 |
+
height=height,
|
56 |
+
generator=generator,
|
57 |
+
).images[0]
|
58 |
+
with_dpo
|
|
|
59 |
```
|
60 |
|
61 |
+
# Adaptor Weights effect
|
|
|
|
|
62 |
|
63 |
+
adapter_weights
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/6064e095abd8d3692e3e2ed6/Oto0TMZ4HTzThhyIv4FN0.jpeg)
|