k4d3
/

English
Not-For-All-Audiences
k4d3 commited on
Commit
4776524
1 Parent(s): f5517c7

Signed-off-by: Balazs Horvath <acsipont@gmail.com>

Files changed (2) hide show
  1. README.md +85 -10
  2. scripts/sdp_benchmark.py +39 -0
README.md CHANGED
@@ -24,12 +24,22 @@ The Yiff Toolkit is a comprehensive set of tools designed to enhance your creati
24
 
25
  - [Hotdogwolf's Yiff Toolkit](#hotdogwolfs-yiff-toolkit)
26
  - [Table of Contents](#table-of-contents)
 
 
 
 
 
 
 
 
 
27
  - [Embeddings for 1.5 and SDXL](#embeddings-for-15-and-sdxl)
28
  - [ComfyUI Walkthrough any%](#comfyui-walkthrough-any)
29
  - [AnimateDiff for Masochists](#animatediff-for-masochists)
30
  - [Stable Cascade Furry Bible](#stable-cascade-furry-bible)
31
  - [Resonance Cascade](#resonance-cascade)
32
  - [SDXL Furry Bible](#sdxl-furry-bible)
 
33
  - [Pony Diffusion V6](#pony-diffusion-v6)
34
  - [Requirements](#requirements)
35
  - [Positive Prompt Stuff](#positive-prompt-stuff)
@@ -82,9 +92,76 @@ The Yiff Toolkit is a comprehensive set of tools designed to enhance your creati
82
  </details>
83
  </div>
84
 
85
- ## Embeddings for 1.5 and SDXL
86
 
87
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  Embeddings in Stable Diffusion are high-dimensional representations of input data, such as images or text, that capture their essential features and relationships. These embeddings are used to guide the diffusion process, enabling the model to generate outputs that closely match the desired characteristics specified in the input.
90
 
@@ -92,14 +169,10 @@ You can find in the [`/embeddings`](https://huggingface.co/k4d3/yiff_toolkit/tre
92
 
93
  ## ComfyUI Walkthrough any%
94
 
95
- ---
96
-
97
  ⚠️ Coming next year! ⚠️
98
 
99
  ## AnimateDiff for Masochists
100
 
101
- ---
102
-
103
  ⚠️ Coming in 2026! ⚠️
104
 
105
  ## Stable Cascade Furry Bible
@@ -110,18 +183,20 @@ You can find in the [`/embeddings`](https://huggingface.co/k4d3/yiff_toolkit/tre
110
 
111
  ## SDXL Furry Bible
112
 
 
 
 
 
113
  ### Pony Diffusion V6
114
 
115
  ---
116
 
117
  #### Requirements
118
 
119
- [Resolution Lora](https://huggingface.co/jiaxiangc/res-adapter/resolve/main/sdxl-i/resolution_lora.safetensors?download=true) is a nice thing to have and of course the [model](https://civitai.com/models/257749/pony-diffusion-v6-xl) itself. Regarding the res-lora, it will help with consistency but you might want to turn it off especially when you img2img to higher resolution than 1024x1024 if you notice something really fucked up is happening to your generations.
120
 
121
  #### Positive Prompt Stuff
122
 
123
- You need this thing for what we are about to do..
124
-
125
  ```sd
126
  score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry,
127
  ```
@@ -155,7 +230,7 @@ Its a good thing to describe your subject or subjects start with `solo` or `duo`
155
 
156
  #### Negative Prompt Stuff
157
 
158
- ⚠️ **WARNING: Under construction!** ⚠️
159
 
160
  ### SeaArt Furry
161
 
 
24
 
25
  - [Hotdogwolf's Yiff Toolkit](#hotdogwolfs-yiff-toolkit)
26
  - [Table of Contents](#table-of-contents)
27
+ - [LoRA Training Guide](#lora-training-guide)
28
+ - [Installation Tips](#installation-tips)
29
+ - [Dataset Preparation](#dataset-preparation)
30
+ - [Pony Training](#pony-training)
31
+ - [`--dataset_repeats`](#--dataset_repeats)
32
+ - [`--max_train_steps`](#--max_train_steps)
33
+ - [`--shuffle_caption`](#--shuffle_caption)
34
+ - [`--sdpa`](#--sdpa)
35
+ - [`--sample_sampler`](#--sample_sampler)
36
  - [Embeddings for 1.5 and SDXL](#embeddings-for-15-and-sdxl)
37
  - [ComfyUI Walkthrough any%](#comfyui-walkthrough-any)
38
  - [AnimateDiff for Masochists](#animatediff-for-masochists)
39
  - [Stable Cascade Furry Bible](#stable-cascade-furry-bible)
40
  - [Resonance Cascade](#resonance-cascade)
41
  - [SDXL Furry Bible](#sdxl-furry-bible)
42
+ - [Some Common Knowledge Stuff](#some-common-knowledge-stuff)
43
  - [Pony Diffusion V6](#pony-diffusion-v6)
44
  - [Requirements](#requirements)
45
  - [Positive Prompt Stuff](#positive-prompt-stuff)
 
92
  </details>
93
  </div>
94
 
95
+ ## LoRA Training Guide
96
 
97
+ ### Installation Tips
98
+
99
+ Firstly, download kohya_ss' [sd-scripts](https://github.com/kohya-ss/sd-scripts), you need to set up your environment either like [this](https://github.com/kohya-ss/sd-scripts?tab=readme-ov-file#windows-installation) tells you for Windows, or if you are using Linux or Miniconda on Windows, you are probably smart enough to figure out the installation for it. I recommend always installing the latest [PyTorch](https://pytorch.org/get-started/locally/) in the virtual environment you are going to use, which at the time of writing is `2.2.2`. I hope future me has faster PyTorch!
100
+
101
+ If someone told you to install `xformers` call them stinky, because ever since the fused implementation of `sdpa` landed in torch it has been the king of my benchmarks.
102
+ For training you will have to go with either `--sdpa` or `--xformers`
103
+
104
+ ### Dataset Preparation
105
+
106
+ ⚠️ **TODO:** Awoo this section.
107
+
108
+ ### Pony Training
109
+
110
+ I'm not going to lie, it is a bit complicated to explain everything. But here is my best attempt going through each line:
111
+
112
+ #### `--dataset_repeats`
113
+
114
+ Repeats the dataset when training with captions, by default it is set to `1` so we'll set this to `0` with:
115
+
116
+ ```py
117
+ --dataset_repeats=0 \
118
+ ```
119
+
120
+ #### `--max_train_steps`
121
+
122
+ Specify the number of steps or epochs to train. If both `--max_train_steps` and `--max_train_epochs` are specified, the number of epochs takes precedence.
123
+
124
+ ```py
125
+ --max_train_steps=500 \
126
+ ```
127
+
128
+ #### `--shuffle_caption`
129
+
130
+ Shuffles the captions set by `--caption_separator`, it is a comma `,` by default which will work perfectly for our case since our captions look like this:
131
+
132
+ ```txt
133
+ rating_questionable, 5 fingers, anthro, bent over, big breasts, blue eyes, blue hair, breasts, butt, claws, curved horn, female, finger claws, fingers, fur, hair, huge breasts, looking at viewer, looking back, looking back at viewer, nipples, nude, pink body, pink hair, pink nipples, rear view, solo, tail, tail tuft, tuft, by lunarii, by x-leon-x, mythology, krystal \(darkmaster781\), dragon, scalie, wickerbeast, The image showcases a pink-scaled wickerbeast a furred dragon creature with blue eyes., She has large breasts and a thick tail., Her blue and pink horns are curved and pointy and she has a slight smiling expression on her face., Her scales are shiny and she has a blue and pink pattern on her body., Her hair is a mix of pink and blue., She is looking back at the viewer with a curious expression., She has a slight blush.,
134
+ ```
135
+
136
+ As you can tell, I have separated the caption part not just the tags with a `,` to make sure everything gets shuffled. I'm at this point pretty certain this is beneficial especially when your caption file contains more than 77 tokens.
137
+
138
+ #### `--sdpa`
139
+
140
+ The choice between `--xformers` and `--spda` will depend on your GPU. You can benchmark it by repeating a training with both!
141
+
142
+ #### `--sample_sampler`
143
+
144
+ You have the option of generating images during training so you can check the progress, the argument let's you pick between different samplers, by default it is on `ddim`, so you better change it!
145
+
146
+ You can also use `--sample_every_n_epochs` instead which will take precedence over steps. The `k_` prefix means karras and the `_a` suffix means ancestral.
147
+
148
+ ```py
149
+ --sample_sampler="euler_a" \
150
+ --sample_every_n_steps=100
151
+ ```
152
+
153
+ My recommendation for Pony is to use `euler_a` for toony and for realistic `k_dpm_2`.
154
+ Your options include the following:
155
+
156
+ ```bash
157
+ ddim, pndm, lms, euler, euler_a, heun, dpm_2, dpm_2_a, dpmsolver, dpmsolver++, dpmsingle, k_lms, k_euler, k_euler_a, k_dpm_2, k_dpm_2_a
158
+ ```
159
+
160
+ ```bash
161
+
162
+ ```
163
+
164
+ ## Embeddings for 1.5 and SDXL
165
 
166
  Embeddings in Stable Diffusion are high-dimensional representations of input data, such as images or text, that capture their essential features and relationships. These embeddings are used to guide the diffusion process, enabling the model to generate outputs that closely match the desired characteristics specified in the input.
167
 
 
169
 
170
  ## ComfyUI Walkthrough any%
171
 
 
 
172
  ⚠️ Coming next year! ⚠️
173
 
174
  ## AnimateDiff for Masochists
175
 
 
 
176
  ⚠️ Coming in 2026! ⚠️
177
 
178
  ## Stable Cascade Furry Bible
 
183
 
184
  ## SDXL Furry Bible
185
 
186
+ ### Some Common Knowledge Stuff
187
+
188
+ [Resolution Lora](https://huggingface.co/jiaxiangc/res-adapter/resolve/main/sdxl-i/resolution_lora.safetensors?download=true) is a nice thing to have, it will help with consistency. For SDXL it is just a LoRA you can load in and it will do its magic. No need for a custom node or extension in this case.
189
+
190
  ### Pony Diffusion V6
191
 
192
  ---
193
 
194
  #### Requirements
195
 
196
+ Download the [model](https://civitai.com/models/257749/pony-diffusion-v6-xl) and load it in to whatever you use to generate models.
197
 
198
  #### Positive Prompt Stuff
199
 
 
 
200
  ```sd
201
  score_9, score_8_up, score_7_up, score_6_up, rating_explicit, source_furry,
202
  ```
 
230
 
231
  #### Negative Prompt Stuff
232
 
233
+ ⚠️ **WARNING: Super under construction!** ⚠️
234
 
235
  ### SeaArt Furry
236
 
scripts/sdp_benchmark.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn.functional as F
3
+ import torch.utils.benchmark as benchmark
4
+ from torch.backends.cuda import sdp_kernel, SDPBackend
5
+
6
+ device = "cuda" if torch.cuda.is_available() else "cpu"
7
+
8
+ def benchmark_torch_function_in_milliseconds(f, *args, **kwargs):
9
+ t0 = benchmark.Timer(
10
+ stmt="f(*args, **kwargs)", globals={"args": args, "kwargs": kwargs, "f": f}
11
+ )
12
+ return t0.blocked_autorange().mean * 1e3 # Convert to milliseconds
13
+
14
+ batch_size = 32
15
+ max_sequence_len = 1024
16
+ num_heads = 32
17
+ embed_dimension = 32
18
+
19
+ dtype = torch.float16
20
+
21
+ query = torch.rand(batch_size, num_heads, max_sequence_len, embed_dimension, device=device, dtype=dtype)
22
+ key = torch.rand(batch_size, num_heads, max_sequence_len, embed_dimension, device=device, dtype=dtype)
23
+ value = torch.rand(batch_size, num_heads, max_sequence_len, embed_dimension, device=device, dtype=dtype)
24
+
25
+ print(f"The default implementation runs in {benchmark_torch_function_in_milliseconds(F.scaled_dot_product_attention, query, key, value):.3f} milliseconds")
26
+
27
+ backend_map = {
28
+ SDPBackend.MATH: {"enable_math": True, "enable_flash": False, "enable_mem_efficient": False},
29
+ SDPBackend.EFFICIENT_ATTENTION: {"enable_math": False, "enable_flash": False, "enable_mem_efficient": True}
30
+ }
31
+
32
+ with sdp_kernel(**backend_map[SDPBackend.MATH]):
33
+ print(f"The math implementation runs in {benchmark_torch_function_in_milliseconds(F.scaled_dot_product_attention, query, key, value):.3f} milliseconds")
34
+
35
+ with sdp_kernel(**backend_map[SDPBackend.EFFICIENT_ATTENTION]):
36
+ try:
37
+ print(f"The memory efficient implementation runs in {benchmark_torch_function_in_milliseconds(F.scaled_dot_product_attention, query, key, value):.3f} milliseconds")
38
+ except RuntimeError:
39
+ print("EfficientAttention is not supported. See warnings for reasons.")