Kohaku XL Δelta
The best "SDXL anime base model that has been trained by an 'individual'."
join us: https://discord.gg/tPBsKDyRR5
|
|
Introduction
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.
Usage
the "base" version is "before train" one!!!!
Here's a simple format to make using this model a breeze:
<1girl/1boy/1other/...>, <character>, <series>, <artists>, <special tags>, <general tags>
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.
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.
Tags
All the danbooru tags with at least 1000 popularity should work. All the danbooru tags with at least 100 popularity can possibly work with high emphasis.
Remember to remove all the underscore in tags. (Underscores in short tags are not be removed, which are very likely part of emoji tags.)
Special Tags
- Quality tags: masterpiece, best quality, great quality, good quality, normal quality, low quality, worst quality
- Rating tags: safe, sensitive, nsfw, explicit
- Date tags: newest, recent, mid, early, old
Quality Tags 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.
Rating tags
- General: safe
- Sensitive: sensitive
- Questionable: nsfw
- Explicit: nsfw, explicit
Note: During training, content tagged as "explicit" is also considered under "nsfw" to ensure a comprehensive understanding.
Date tags Date tags are based on the upload dates of the images, as the metadata does not include the actual creation dates. The periods are categorized as follows:
- 2005~2010: old
- 2011~2014: early
- 2015~2017: mid
- 2018~2020: recent
- 2021~2024: newest
Emphasis
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. For sd-webui users, please use version>=1.8.0 and switch the emphasis mode to "No norm" to prevent potential NaN issues.
Resolution
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.
For more information, please check out the metadata of the sample images provided.
How This Model Came to Be
Dataset
The dataset for training this model was sourced from HakuBooru, comprising 3.6 million images selected from the danbooru2023 dataset.[2][3]
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.
The selection was essentially random, but a fixed seed was utilized to ensure reproducibility.
Further Process
- Shuffle tags: The order of general tags was shuffled in each step.
- Tag dropout: Randomly, 10% of general tags were dropped in each step.
Training
The training of Kohaku XL Delta was facilitated by the LyCORIS project and the trainer from kohya-ss/sd-scripts. [1][4]
Base Model Refinement 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]
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.
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.
Algorithm: LoKr[7] 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.
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.
For detailed settings, refer to the LyCORIS config file.
Other Training Details
- Hardware: Dual RTX 3090s
- Num Train Images: 3,665,398
- Batch Size: 4
- Grad Accumulation Step: 16
- Equivalent Batch Size: 128
- Total Epoch: 1
- Total Steps: 28638
- Optimizer: Lion8bit
- Learning Rate: 4e-5 for UNet / 1e-5 for TE
- LR Scheduler: Constant
- Warmup Steps: 100
- Weight Decay: 0.1
- Betas: 0.9, 0.95
- Min SNR Gamma: 5
- Resolution: 1024x1024
- Min Bucket Resolution: 256
- Max Bucket Resolution: 4096
- Mixed Precision: FP16
Warning: Versions 0.36.0~0.41.0 of bitsandbytes have significant bugs in the 8bit optimizer that could compromise training, so updating is essential.[8]
Training Cost 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.
What's Next
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.
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.
(Funny thing, Delta started off as an experiment too, but turned out so well it became a main release!)
Special Thanks
AngelBottomless & Nyanko7: danbooru2023 dataset[3] Kohya-ss: Trainer[4] ChatGPT/GPT4: Refine this model card
AI art should be looked like AI, not like humans.
Reference & Resource
Reference
[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. https://arxiv.org/abs/2309.14859
[2] HakuBooru - text-image dataset maker for booru style image platform. https://github.com/KohakuBlueleaf/HakuBooru
[3] Danbooru2023: A Large-Scale Crowdsourced and Tagged Anime Illustration Dataset. https://huggingface.co/datasets/nyanko7/danbooru2023
[4] kohya-ss/sd-scripts. https://github.com/kohya-ss/sd-scripts
[5] Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX. https://github.com/huggingface/transformers/blob/b647acdb53d251cec126b79e505bac11821d7c93/src/transformers/models/clip/modeling_clip.py#L204-L205
[6] OpenCLIP - An open source implementation of CLIP. https://github.com/mlfoundations/open_clip/blob/73fa7f03a33da53653f61841eb6d69aef161e521/src/open_clip/transformer.py#L598-L604
[7] LyCORIS - Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion. https://github.com/KohakuBlueleaf/LyCORIS/blob/main/docs/Algo-Details.md#lokr
[8] TimDettmers/bitsandbytes - issue 659/152/227/262 - Wrong indented lines cause bugs for a long time. https://github.com/TimDettmers/bitsandbytes/issues/659
Resource
- Kohaku XL beta. https://civitai.com/models/162577/kohaku-xl-beta
- Kohaku XL gamma. https://civitai.com/models/270291/kohaku-xl-gamma
Appendix
Sample images will be put in here later. You can check the sample folder at first.
- Downloads last month
- 157