Rename evoukiyoe_v1.py to evo_ukiyoe_v1.py
#1
by
yuki-imajuku
- opened
- README.md +25 -32
- evo_ukiyoe_v1.py +18 -8
- requirements.txt +0 -8
README.md
CHANGED
@@ -9,13 +9,21 @@ tags:
|
|
9 |
---
|
10 |
# 🐟 Evo-Ukiyoe-v1
|
11 |
|
12 |
-
🤗 [Models](https://huggingface.co/SakanaAI
|
13 |
|
14 |
|
15 |
-
**
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
Please refer to our [blog](https://sakana.ai/evo-ukiyoe/) for more details.
|
19 |
|
20 |
## Usage
|
21 |
|
@@ -29,28 +37,18 @@ Use the code below to get started with the model.
|
|
29 |
```
|
30 |
git clone https://huggingface.co/SakanaAI/Evo-Ukiyoe-v1
|
31 |
```
|
32 |
-
2. Install
|
33 |
-
```
|
34 |
-
sudo apt install git-lfs
|
35 |
-
git lfs install
|
36 |
-
```
|
37 |
-
3. Create conda env
|
38 |
-
```
|
39 |
-
conda create -n evo-ukiyoe python=3.11
|
40 |
-
conda activate evo-ukiyoe
|
41 |
-
```
|
42 |
-
4. Install packages
|
43 |
```
|
44 |
cd Evo-Ukiyoe-v1
|
45 |
pip install -r requirements.txt
|
46 |
```
|
47 |
-
|
48 |
```python
|
49 |
-
from
|
50 |
|
51 |
-
prompt = "
|
52 |
-
pipe =
|
53 |
-
images = pipe(prompt + "
|
54 |
images[0].save("image.png")
|
55 |
```
|
56 |
|
@@ -65,11 +63,11 @@ Use the code below to get started with the model.
|
|
65 |
- **Developed by:** [Sakana AI](https://sakana.ai/)
|
66 |
- **Model type:** Diffusion-based text-to-image generative model
|
67 |
- **Language(s):** Japanese
|
68 |
-
- **Blog:** https://sakana.ai/
|
69 |
|
70 |
|
71 |
## License
|
72 |
-
The Python script included in this repository
|
73 |
Please note that the license for the model/pipeline generated by this script is inherited from the source models.
|
74 |
|
75 |
## Uses
|
@@ -82,16 +80,11 @@ Users must fully understand the risks associated with the use of this model and
|
|
82 |
|
83 |
## Acknowledgement
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
- [Juggernaut-XL-v9](https://huggingface.co/RunDiffusion/Juggernaut-XL-v9)
|
88 |
-
- [SDXL-DPO](https://huggingface.co/mhdang/dpo-sdxl-text2image-v1)
|
89 |
-
- [JSDXL](https://huggingface.co/stabilityai/japanese-stable-diffusion-xl)
|
90 |
|
91 |
## Citation
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
author = {Clanuwat, Tarin and Shing, Makoto and Imajuku, Yuki and Kitamoto, Asanobu and Akama, Ryo}
|
97 |
-
}
|
|
|
9 |
---
|
10 |
# 🐟 Evo-Ukiyoe-v1
|
11 |
|
12 |
+
🤗 [Models](https://huggingface.co/SakanaAI) | 📝 [Blog](TODO) | 🐦 [Twitter](https://twitter.com/SakanaAILabs)
|
13 |
|
14 |
|
15 |
+
**EvoSDXL-JP-v1** is an experimental education-purpose Japanese SDXL Lightning.
|
16 |
+
This model was created using the Evolutionary Model Merge method.
|
17 |
+
Please refer to our [report](https://arxiv.org/abs/2403.13187) and [blog](https://sakana.ai/evosdxl-jp/) for more details.
|
18 |
+
This model was produced by merging the following models.
|
19 |
+
We are grateful to the developers of the source models.
|
20 |
+
|
21 |
+
- [SDXL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)
|
22 |
+
- [Juggernaut-XL-v9](https://huggingface.co/RunDiffusion/Juggernaut-XL-v9)
|
23 |
+
- [SDXL-DPO](https://huggingface.co/mhdang/dpo-sdxl-text2image-v1)
|
24 |
+
- [JSDXL](https://huggingface.co/stabilityai/japanese-stable-diffusion-xl)
|
25 |
+
- [SDXL-Lightning](https://huggingface.co/ByteDance/SDXL-Lightning)
|
26 |
|
|
|
27 |
|
28 |
## Usage
|
29 |
|
|
|
37 |
```
|
38 |
git clone https://huggingface.co/SakanaAI/Evo-Ukiyoe-v1
|
39 |
```
|
40 |
+
2. Install packages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
```
|
42 |
cd Evo-Ukiyoe-v1
|
43 |
pip install -r requirements.txt
|
44 |
```
|
45 |
+
3. Run
|
46 |
```python
|
47 |
+
from evoukiyoe_v1 import load_evoukiyoe
|
48 |
|
49 |
+
prompt = "魚が泳いでいる。"
|
50 |
+
pipe = load_evoukiyoe(device="cuda")
|
51 |
+
images = pipe(prompt + "輻の浮世絵。", guidance_scale=8.0, num_inference_steps=40).images
|
52 |
images[0].save("image.png")
|
53 |
```
|
54 |
|
|
|
63 |
- **Developed by:** [Sakana AI](https://sakana.ai/)
|
64 |
- **Model type:** Diffusion-based text-to-image generative model
|
65 |
- **Language(s):** Japanese
|
66 |
+
- **Blog:** https://sakana.ai/TODO
|
67 |
|
68 |
|
69 |
## License
|
70 |
+
The Python script included in this repository is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
|
71 |
Please note that the license for the model/pipeline generated by this script is inherited from the source models.
|
72 |
|
73 |
## Uses
|
|
|
80 |
|
81 |
## Acknowledgement
|
82 |
|
83 |
+
We would like to thank the developers of the source models for their contributions and for making their work available.
|
84 |
+
|
|
|
|
|
|
|
85 |
|
86 |
## Citation
|
87 |
|
88 |
+
```bibtex
|
89 |
+
TODO
|
90 |
+
```
|
|
|
|
evo_ukiyoe_v1.py
CHANGED
@@ -12,8 +12,7 @@ import torch
|
|
12 |
from tqdm import tqdm
|
13 |
from transformers import AutoTokenizer, CLIPTextModelWithProjection
|
14 |
|
15 |
-
|
16 |
-
# Base models
|
17 |
SDXL_REPO = "stabilityai/stable-diffusion-xl-base-1.0"
|
18 |
DPO_REPO = "mhdang/dpo-sdxl-text2image-v1"
|
19 |
JN_REPO = "RunDiffusion/Juggernaut-XL-v9"
|
@@ -117,7 +116,6 @@ def load_evo_ukiyoe(device="cuda") -> StableDiffusionXLPipeline:
|
|
117 |
)
|
118 |
jn_weights = split_conv_attn(load_from_pretrained(JN_REPO, device=device))
|
119 |
jsdxl_weights = split_conv_attn(load_from_pretrained(JSDXL_REPO, device=device))
|
120 |
-
|
121 |
# Merge base models
|
122 |
tensors = [sdxl_weights, dpo_weights, jn_weights, jsdxl_weights]
|
123 |
new_conv = merge_models(
|
@@ -138,14 +136,11 @@ def load_evo_ukiyoe(device="cuda") -> StableDiffusionXLPipeline:
|
|
138 |
0.2198623756106564,
|
139 |
],
|
140 |
)
|
141 |
-
|
142 |
-
# Delete no longer needed variables to free
|
143 |
del sdxl_weights, dpo_weights, jn_weights, jsdxl_weights
|
144 |
gc.collect()
|
145 |
if "cuda" in device:
|
146 |
torch.cuda.empty_cache()
|
147 |
|
148 |
-
# Instantiate UNet
|
149 |
unet_config = UNet2DConditionModel.load_config(SDXL_REPO, subfolder="unet")
|
150 |
unet = UNet2DConditionModel.from_config(unet_config).to(device=device)
|
151 |
unet.load_state_dict({**new_conv, **new_attn})
|
@@ -167,10 +162,25 @@ def load_evo_ukiyoe(device="cuda") -> StableDiffusionXLPipeline:
|
|
167 |
torch_dtype=torch.float16,
|
168 |
variant="fp16",
|
169 |
)
|
|
|
170 |
|
171 |
# Load Evo-Ukiyoe weights
|
172 |
pipe.load_lora_weights(UKIYOE_REPO)
|
173 |
pipe.fuse_lora(lora_scale=1.0)
|
174 |
-
|
175 |
-
pipe = pipe.to(device=torch.device(device), dtype=torch.float16)
|
176 |
return pipe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
from tqdm import tqdm
|
13 |
from transformers import AutoTokenizer, CLIPTextModelWithProjection
|
14 |
|
15 |
+
# Base models (fine-tuned from SDXL-1.0)
|
|
|
16 |
SDXL_REPO = "stabilityai/stable-diffusion-xl-base-1.0"
|
17 |
DPO_REPO = "mhdang/dpo-sdxl-text2image-v1"
|
18 |
JN_REPO = "RunDiffusion/Juggernaut-XL-v9"
|
|
|
116 |
)
|
117 |
jn_weights = split_conv_attn(load_from_pretrained(JN_REPO, device=device))
|
118 |
jsdxl_weights = split_conv_attn(load_from_pretrained(JSDXL_REPO, device=device))
|
|
|
119 |
# Merge base models
|
120 |
tensors = [sdxl_weights, dpo_weights, jn_weights, jsdxl_weights]
|
121 |
new_conv = merge_models(
|
|
|
136 |
0.2198623756106564,
|
137 |
],
|
138 |
)
|
|
|
|
|
139 |
del sdxl_weights, dpo_weights, jn_weights, jsdxl_weights
|
140 |
gc.collect()
|
141 |
if "cuda" in device:
|
142 |
torch.cuda.empty_cache()
|
143 |
|
|
|
144 |
unet_config = UNet2DConditionModel.load_config(SDXL_REPO, subfolder="unet")
|
145 |
unet = UNet2DConditionModel.from_config(unet_config).to(device=device)
|
146 |
unet.load_state_dict({**new_conv, **new_attn})
|
|
|
162 |
torch_dtype=torch.float16,
|
163 |
variant="fp16",
|
164 |
)
|
165 |
+
pipe = pipe.to(device, dtype=torch.float16)
|
166 |
|
167 |
# Load Evo-Ukiyoe weights
|
168 |
pipe.load_lora_weights(UKIYOE_REPO)
|
169 |
pipe.fuse_lora(lora_scale=1.0)
|
|
|
|
|
170 |
return pipe
|
171 |
+
|
172 |
+
|
173 |
+
if __name__ == "__main__":
|
174 |
+
pipe: StableDiffusionXLPipeline = load_evo_ukiyoe()
|
175 |
+
images = pipe(
|
176 |
+
prompt="鶴が庭に立っている。雪が降っている。最高品質の輻の浮世絵。",
|
177 |
+
negative_prompt="",
|
178 |
+
width=1024,
|
179 |
+
height=1024,
|
180 |
+
guidance_scale=8.0,
|
181 |
+
num_inference_steps=50,
|
182 |
+
generator=torch.Generator().manual_seed(0),
|
183 |
+
num_images_per_prompt=1,
|
184 |
+
output_type="pil",
|
185 |
+
).images
|
186 |
+
images[0].save("out.png")
|
requirements.txt
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
torch
|
2 |
-
torchvision
|
3 |
-
|
4 |
-
accelerate==0.32.0
|
5 |
-
diffusers==0.29.2
|
6 |
-
sentencepiece==0.2.0
|
7 |
-
transformers==4.42.3
|
8 |
-
peft==0.11.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|