Text-to-Image
Diffusers
Safetensors
English
StableDiffusionXLPipeline
Inference Endpoints
KBlueLeaf commited on
Commit
6776258
1 Parent(s): 2d91860

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +188 -0
README.md CHANGED
@@ -2,4 +2,192 @@
2
  license: other
3
  license_name: fair-ai-public-license-1.0-sd
4
  license_link: https://freedevproject.org/faipl-1.0-sd/
 
 
 
 
 
 
5
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: other
3
  license_name: fair-ai-public-license-1.0-sd
4
  license_link: https://freedevproject.org/faipl-1.0-sd/
5
+ datasets:
6
+ - KBlueLeaf/danbooru2023-webp-4Mpixel
7
+ - KBlueLeaf/danbooru2023-sqlite
8
+ language:
9
+ - en
10
+ library_name: diffusers
11
  ---
12
+
13
+ # Kohaku XL Δelta
14
+
15
+ ***The best "SDXL anime base model that has been trained by an 'individual'."***
16
+
17
+ join us: https://discord.gg/tPBsKDyRR5
18
+
19
+ ![banner](https://i.imgur.com/t5mkDsS.jpeg)
20
+
21
+ ## Introduction
22
+
23
+ Kohaku XL Delta, the fourth major iteration in the Kohaku XL series, features a 3.6 million images dataset, LyCORIS fine-tuning[1], trained on comsumer-level hardware, and is fully open-sourced.
24
+
25
+ ## Usage
26
+
27
+ Here's a simple format to make using this model a breeze:
28
+
29
+ ```
30
+ <1girl/1boy/1other/...>, <character>, <series>, <artists>, <special tags>, <general tags>
31
+ ```
32
+
33
+ Special tags(quality, rating, and date) actually fall under general tags. But it's a good idea to group all these tags before the general tags.
34
+
35
+ **While Kohaku XL Delta has mastered few artists' styles with high fidelity. However, users are strongly encouraged to blend multiple artist tags to explore new styles, rather than attempting to replicate the style of any specific artist.**
36
+
37
+ #### Tags
38
+
39
+ All the danbooru tags with at least 1000 popularity should work.
40
+ All the danbooru tags with at least 100 popularity can possibly work with high emphasis.
41
+
42
+ Remember to remove all the underscore in tags. (Underscores in short tags are not be removed, which are very likely part of emoji tags.)
43
+
44
+ ### Special Tags
45
+
46
+ - **Quality tag**s: masterpiece, best quality, great quality, good quality, normal quality, low quality, worst quality
47
+ - **Rating tags**: safe, sensitive, nsfw, explicit
48
+ - **Date tags**: newest, recent, mid, early, old
49
+
50
+ **Quality Tags**
51
+ Quality tags are assigned based on the percentile rankings of the favorite count (fav_count) within each rating category to avoid bias on nsfw content (Animagine XL v3 have met this problem), organized from high to low as follows: 95th, 85th, 75th, 50th, 25th, and 10th percentiles. This creates seven distinct quality levels separated by six thresholds.
52
+
53
+ **Rating tags**
54
+
55
+ * **General**: safe
56
+ * **Sensitive**: sensitive
57
+ * **Questionable**: nsfw
58
+ * **Explicit**: nsfw, explicit
59
+
60
+ Note: During training, content tagged as "explicit" is also considered under "nsfw" to ensure a comprehensive understanding.
61
+
62
+ **Date tags**
63
+ Date tags are based on the upload dates of the images, as the metadata does not include the actual creation dates.
64
+ The periods are categorized as follows:
65
+
66
+ * 2005~2010: old
67
+ * 2011~2014: early
68
+ * 2015~2017: mid
69
+ * 2018~2020: recent
70
+ * 2021~2024: newest
71
+
72
+ ### Emphasis
73
+
74
+ Given the short training period, some tags might not have been learned well. Through experimentation, increasing the "emphasis weight" to between 1.5 and 2.5 can still yield descent results, especially for character or artist tags.
75
+ For sd-webui users, please use version>=1.8.0 and switch the emphasis mode to "No norm" to prevent potential NaN issues.
76
+
77
+ ### Resolution
78
+
79
+ This model is trained for resolutions from ARB 1024x1024 with minimum resolution 256 and maximum resolution 4096. This means you can use the standard SDXL resolution. However, opting for a slightly higher resolution than 1024x1024 is recommended. Applying a hires-fix is also suggested for better results.
80
+
81
+ For more information, please check out the metadata of the sample images provided.
82
+
83
+ ## How This Model Came to Be
84
+
85
+ ### Dataset
86
+
87
+ The dataset for training this model was sourced from [HakuBooru](https://github.com/KohakuBlueleaf/HakuBooru), comprising 3.6 million images selected from the [danbooru2023](https://huggingface.co/datasets/KBlueLeaf/danbooru2023-webp-4Mpixel) dataset.[2][3]
88
+
89
+ A selection process was employed to choose 1 million posts from IDs 0 to 2,999,999, another million from IDs 3,000,000 to 4,999,999, and all posts after ID 5,000,000, totaling 4.1 million posts. After filtering out deleted posts, gold account posts and those without images (which could be GIFs or MP4s), the final dataset comprised 3.6 million images.
90
+
91
+ The selection was essentially random, but a fixed seed was utilized to ensure reproducibility.
92
+
93
+ **Further Process**
94
+
95
+ * **Shuffle tags**: The order of general tags was shuffled in each step.
96
+ * **Tag dropout**: Randomly, 10% of general tags were dropped in each step.
97
+
98
+ ### Training
99
+
100
+ The training of Kohaku XL Delta was facilitated by the [LyCORIS](https://github.com/KohakuBlueleaf/LyCORIS) project and the trainer from [kohya-ss/sd-scripts](https://github.com/kohya-ss/sd-scripts). [1][4]
101
+
102
+ **Base Model Refinement**
103
+ Our investigation indicated that training the "token_embedding" and "position_embedding" within CLIP, or the "positional_embedding" in openCLIP, may not be beneficial for fine-tuning on a small to medium scale, particularly with smaller batch sizes.[5][6]
104
+
105
+ Consequently, we reverted to the original token and position embeddings from TE1 and TE2 models. Following this, we combined the restored gamma rev2 and beta7 models through a weighted sum (weight=0.5), forming the foundational model for Kohaku XL Delta.
106
+
107
+ This foundational model, referred to as "delta-pre2" or "delta base," serves as a preliminary version without further training, positioning its capabilities between Kohaku XL gamma rev2 and Kohaku XL beta7.
108
+
109
+ **Algorithm: LoKr**[7]
110
+ The model was trained using the LoKr algorithm with full matrix triggered and a factor of 2~8 for different modules. The aim was to demonstrate the applicability of LoRA/LyCORIS in training base models.
111
+
112
+ The original LoKr file size is under 800MB, and the TE was not frozen. The original LoKr file also be provided as "delta-lokr" version.
113
+
114
+ For detailed settings, refer to the LyCORIS config file.
115
+
116
+ **Other Training Details**
117
+
118
+ - **Hardware**: Dual RTX 3090s
119
+ - **Num Train Images**: 3,665,398
120
+ - **Batch Size**: 4
121
+ - **Grad Accumulation Step**: 16
122
+ - **Equivalent Batch Size**: 128
123
+ - **Total Epoch**: 1
124
+ - **Total Steps**: 28638
125
+ - **Optimizer**: Lion8bit
126
+ - **Learning Rate**: 4e-5 for UNet / 1e-5 for TE
127
+ - **LR Scheduler**: Constant
128
+ - **Warmup Steps**: 100
129
+ - **Weight Decay**: 0.1
130
+ - **Betas**: 0.9, 0.95
131
+ - **Min SNR Gamma**: 5
132
+ - **Resolution**: 1024x1024
133
+ - **Min Bucket Resolution**: 256
134
+ - **Max Bucket Resolution**: 4096
135
+ - **Mixed Precision**: FP16
136
+
137
+ **Warning**: Versions 0.36.0~0.41.0 of bitsandbytes have significant [bugs](https://github.com/TimDettmers/bitsandbytes/issues/659) in the 8bit optimizer that could compromise training, so updating is essential.[8]
138
+
139
+ **Training Cost**
140
+ Utilizing DDP with two RTX 3090s, completing 1 epoch across the 3.6 million image dataset took approximately 17 to 18 days. Each step for an equivalent batch size of 128 took about 51 to 51.5 seconds to complete.
141
+
142
+ ### What's Next
143
+
144
+ Delta is likely the last big update for Kohaku XL, but that doesn't mean I'm done tinkering with it. And I won't ensure this is actually the last one.
145
+
146
+ I'm thinking about running it through a few more epochs or maybe beefing up the dataset to 5 million images soon. Plus, I'm considering trying out DoKr with a bit of a bigger setup for some experimental tweaks.
147
+
148
+ (Funny thing, Delta started off as an experiment too, but turned out so well it became a main release!)
149
+
150
+ ## Special Thanks
151
+
152
+ AngelBottomless & Nyanko7: danbooru2023 dataset[3]
153
+ Kohya-ss: Trainer[4]
154
+ ChatGPT/GPT4: Refine this model card
155
+
156
+ ---
157
+
158
+ ***AI art should be looked like AI, not like humans.***
159
+
160
+ ---
161
+
162
+ ## Reference & Resource
163
+
164
+ ### Reference
165
+
166
+ [1] **Shih-Ying Yeh**, Yu-Guan Hsieh, Zhidong Gao, Bernard B W Yang, Giyeong Oh, & Yanmin Gong (2024). Navigating Text-To-Image Customization: From LyCORIS Fine-Tuning to Model Evaluation. In The Twelfth International Conference on Learning Representations.
167
+
168
+ [2] HakuBooru - text-image dataset maker for booru style image platform. https://github.com/KohakuBlueleaf/HakuBooru
169
+
170
+ [3] Danbooru2023: A Large-Scale Crowdsourced and Tagged Anime Illustration Dataset.
171
+ https://huggingface.co/datasets/nyanko7/danbooru2023
172
+
173
+ [4] kohya-ss/sd-scripts.
174
+ https://github.com/kohya-ss/sd-scripts
175
+
176
+ [5] Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
177
+ https://github.com/huggingface/transformers/blob/b647acdb53d251cec126b79e505bac11821d7c93/src/transformers/models/clip/modeling_clip.py#L204-L205
178
+
179
+ [6] OpenCLIP - An open source implementation of CLIP.
180
+ https://github.com/mlfoundations/open_clip/blob/73fa7f03a33da53653f61841eb6d69aef161e521/src/open_clip/transformer.py#L598-L604
181
+
182
+ [7] LyCORIS - Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion.
183
+ https://github.com/KohakuBlueleaf/LyCORIS/blob/main/docs/Algo-Details.md#lokr
184
+
185
+ [8] TimDettmers/bitsandbytes - issue 659/152/227/262 - Wrong indented lines cause bugs for a long time.
186
+ https://github.com/TimDettmers/bitsandbytes/issues/659
187
+
188
+ ### Resource
189
+
190
+ * Kohaku XL beta. https://civitai.com/models/162577/kohaku-xl-beta
191
+ * Kohaku XL gamma. https://civitai.com/models/270291/kohaku-xl-gamma
192
+
193
+ ## Appendix