Rename evoukiyoe_v1.py to evo_ukiyoe_v1.py

#1
Files changed (3) hide show
  1. README.md +25 -32
  2. evo_ukiyoe_v1.py +18 -8
  3. requirements.txt +0 -8
README.md CHANGED
@@ -9,13 +9,21 @@ tags:
9
  ---
10
  # 🐟 Evo-Ukiyoe-v1
11
 
12
- 🤗 [Models](https://huggingface.co/SakanaAI/Evo-Ukiyoe-v1/) | 📝 [Blog](https://sakana.ai/evo-ukiyoe/) | 🐦 [Twitter](https://twitter.com/SakanaAILabs)
13
 
14
 
15
- **Evo-Ukiyoe-v1** is an experimental education-purpose Japanese woodblock print Ukiyoe style image generation model. The model was train based on Sakana AI's [Evo-SDXL-JP](https://huggingface.co/SakanaAI/EvoSDXL-JP-v1).
16
- All the dataset used to train Evo-Ukiyoe comes from Ukiyoe images belonged to [Ritsumeikan University, Art Research Center](https://www.arc.ritsumei.ac.jp/).
 
 
 
 
 
 
 
 
 
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 git-lfs if you don't have it yet.
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
- 5. Run
48
  ```python
49
- from evo_ukiyoe_v1 import load_evo_ukiyoe
50
 
51
- prompt = "着物を着ている猫が庭でお茶を飲んでいる。"
52
- pipe = load_evo_ukiyoe(device="cuda")
53
- images = pipe(prompt + "輻の浮世絵。超詳細。", negative_prompt='', guidance_scale=8.0, num_inference_steps=40).images
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/evo-ukiyoe/
69
 
70
 
71
  ## License
72
- The Python script included in this repository and Lora weight are licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
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
- Evo-Ukiyoe was trained based on Evo-SDXL-JP. We would like to thank the developers of Evo-SDXL-JP source models for their contributions and for making their work available.
86
- - [SDXL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)
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
- @misc{Evo-Ukiyoe,
94
- url = {[https://huggingface.co/SakanaAI/Evo-Nishikie-v1](https://huggingface.co/SakanaAI/Evo-Nishikie-v1)},
95
- title = {Evo-Ukiyoe},
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