ACCC1380 commited on
Commit
2f68c6d
1 Parent(s): 321615d

Upload lora-scripts/sd-scripts/docs/config_README-en.md with huggingface_hub

Browse files
lora-scripts/sd-scripts/docs/config_README-en.md ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Original Source by kohya-ss
2
+
3
+ First version:
4
+ A.I Translation by Model: NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO, editing by Darkstorm2150
5
+
6
+ Some parts are manually added.
7
+
8
+ # Config Readme
9
+
10
+ This README is about the configuration files that can be passed with the `--dataset_config` option.
11
+
12
+ ## Overview
13
+
14
+ By passing a configuration file, users can make detailed settings.
15
+
16
+ * Multiple datasets can be configured
17
+ * For example, by setting `resolution` for each dataset, they can be mixed and trained.
18
+ * In training methods that support both the DreamBooth approach and the fine-tuning approach, datasets of the DreamBooth method and the fine-tuning method can be mixed.
19
+ * Settings can be changed for each subset
20
+ * A subset is a partition of the dataset by image directory or metadata. Several subsets make up a dataset.
21
+ * Options such as `keep_tokens` and `flip_aug` can be set for each subset. On the other hand, options such as `resolution` and `batch_size` can be set for each dataset, and their values are common among subsets belonging to the same dataset. More details will be provided later.
22
+
23
+ The configuration file format can be JSON or TOML. Considering the ease of writing, it is recommended to use [TOML](https://toml.io/ja/v1.0.0-rc.2). The following explanation assumes the use of TOML.
24
+
25
+
26
+ Here is an example of a configuration file written in TOML.
27
+
28
+ ```toml
29
+ [general]
30
+ shuffle_caption = true
31
+ caption_extension = '.txt'
32
+ keep_tokens = 1
33
+
34
+ # This is a DreamBooth-style dataset
35
+ [[datasets]]
36
+ resolution = 512
37
+ batch_size = 4
38
+ keep_tokens = 2
39
+
40
+ [[datasets.subsets]]
41
+ image_dir = 'C:\hoge'
42
+ class_tokens = 'hoge girl'
43
+ # This subset uses keep_tokens = 2 (the value of the parent datasets)
44
+
45
+ [[datasets.subsets]]
46
+ image_dir = 'C:\fuga'
47
+ class_tokens = 'fuga boy'
48
+ keep_tokens = 3
49
+
50
+ [[datasets.subsets]]
51
+ is_reg = true
52
+ image_dir = 'C:\reg'
53
+ class_tokens = 'human'
54
+ keep_tokens = 1
55
+
56
+ # This is a fine-tuning dataset
57
+ [[datasets]]
58
+ resolution = [768, 768]
59
+ batch_size = 2
60
+
61
+ [[datasets.subsets]]
62
+ image_dir = 'C:\piyo'
63
+ metadata_file = 'C:\piyo\piyo_md.json'
64
+ # This subset uses keep_tokens = 1 (the value of [general])
65
+ ```
66
+
67
+ In this example, three directories are trained as a DreamBooth-style dataset at 512x512 (batch size 4), and one directory is trained as a fine-tuning dataset at 768x768 (batch size 2).
68
+
69
+ ## Settings for datasets and subsets
70
+
71
+ Settings for datasets and subsets are divided into several registration locations.
72
+
73
+ * `[general]`
74
+ * This is where options that apply to all datasets or all subsets are specified.
75
+ * If there are options with the same name in the dataset-specific or subset-specific settings, the dataset-specific or subset-specific settings take precedence.
76
+ * `[[datasets]]`
77
+ * `datasets` is where settings for datasets are registered. This is where options that apply individually to each dataset are specified.
78
+ * If there are subset-specific settings, the subset-specific settings take precedence.
79
+ * `[[datasets.subsets]]`
80
+ * `datasets.subsets` is where settings for subsets are registered. This is where options that apply individually to each subset are specified.
81
+
82
+ Here is an image showing the correspondence between image directories and registration locations in the previous example.
83
+
84
+ ```
85
+ C:\
86
+ ├─ hoge -> [[datasets.subsets]] No.1 ┐ ┐
87
+ ├─ fuga -> [[datasets.subsets]] No.2 |-> [[datasets]] No.1 |-> [general]
88
+ ├─ reg -> [[datasets.subsets]] No.3 ┘ |
89
+ └─ piyo -> [[datasets.subsets]] No.4 --> [[datasets]] No.2 ┘
90
+ ```
91
+
92
+ The image directory corresponds to each `[[datasets.subsets]]`. Then, multiple `[[datasets.subsets]]` are combined to form one `[[datasets]]`. All `[[datasets]]` and `[[datasets.subsets]]` belong to `[general]`.
93
+
94
+ The available options for each registration location may differ, but if the same option is specified, the value in the lower registration location will take precedence. You can check how the `keep_tokens` option is handled in the previous example for better understanding.
95
+
96
+ Additionally, the available options may vary depending on the method that the learning approach supports.
97
+
98
+ * Options specific to the DreamBooth method
99
+ * Options specific to the fine-tuning method
100
+ * Options available when using the caption dropout technique
101
+
102
+ When using both the DreamBooth method and the fine-tuning method, they can be used together with a learning approach that supports both.
103
+ When using them together, a point to note is that the method is determined based on the dataset, so it is not possible to mix DreamBooth method subsets and fine-tuning method subsets within the same dataset.
104
+ In other words, if you want to use both methods together, you need to set up subsets of different methods belonging to different datasets.
105
+
106
+ In terms of program behavior, if the `metadata_file` option exists, it is determined to be a subset of fine-tuning. Therefore, for subsets belonging to the same dataset, as long as they are either "all have the `metadata_file` option" or "all have no `metadata_file` option," there is no problem.
107
+
108
+ Below, the available options will be explained. For options with the same name as the command-line argument, the explanation will be omitted in principle. Please refer to other READMEs.
109
+
110
+ ### Common options for all learning methods
111
+
112
+ These are options that can be specified regardless of the learning method.
113
+
114
+ #### Data set specific options
115
+
116
+ These are options related to the configuration of the data set. They cannot be described in `datasets.subsets`.
117
+
118
+
119
+ | Option Name | Example Setting | `[general]` | `[[datasets]]` |
120
+ | ---- | ---- | ---- | ---- |
121
+ | `batch_size` | `1` | o | o |
122
+ | `bucket_no_upscale` | `true` | o | o |
123
+ | `bucket_reso_steps` | `64` | o | o |
124
+ | `enable_bucket` | `true` | o | o |
125
+ | `max_bucket_reso` | `1024` | o | o |
126
+ | `min_bucket_reso` | `128` | o | o |
127
+ | `resolution` | `256`, `[512, 512]` | o | o |
128
+
129
+ * `batch_size`
130
+ * This corresponds to the command-line argument `--train_batch_size`.
131
+
132
+ These settings are fixed per dataset. That means that subsets belonging to the same dataset will share these settings. For example, if you want to prepare datasets with different resolutions, you can define them as separate datasets as shown in the example above, and set different resolutions for each.
133
+
134
+ #### Options for Subsets
135
+
136
+ These options are related to subset configuration.
137
+
138
+ | Option Name | Example | `[general]` | `[[datasets]]` | `[[dataset.subsets]]` |
139
+ | ---- | ---- | ---- | ---- | ---- |
140
+ | `color_aug` | `false` | o | o | o |
141
+ | `face_crop_aug_range` | `[1.0, 3.0]` | o | o | o |
142
+ | `flip_aug` | `true` | o | o | o |
143
+ | `keep_tokens` | `2` | o | o | o |
144
+ | `num_repeats` | `10` | o | o | o |
145
+ | `random_crop` | `false` | o | o | o |
146
+ | `shuffle_caption` | `true` | o | o | o |
147
+ | `caption_prefix` | `"masterpiece, best quality, "` | o | o | o |
148
+ | `caption_suffix` | `", from side"` | o | o | o |
149
+ | `caption_separator` | (not specified) | o | o | o |
150
+ | `keep_tokens_separator` | `“|||”` | o | o | o |
151
+ | `secondary_separator` | `“;;;”` | o | o | o |
152
+ | `enable_wildcard` | `true` | o | o | o |
153
+
154
+ * `num_repeats`
155
+ * Specifies the number of repeats for images in a subset. This is equivalent to `--dataset_repeats` in fine-tuning but can be specified for any training method.
156
+ * `caption_prefix`, `caption_suffix`
157
+ * Specifies the prefix and suffix strings to be appended to the captions. Shuffling is performed with these strings included. Be cautious when using `keep_tokens`.
158
+ * `caption_separator`
159
+ * Specifies the string to separate the tags. The default is `,`. This option is usually not necessary to set.
160
+ * `keep_tokens_separator`
161
+ * Specifies the string to separate the parts to be fixed in the caption. For example, if you specify `aaa, bbb ||| ccc, ddd, eee, fff ||| ggg, hhh`, the parts `aaa, bbb` and `ggg, hhh` will remain, and the rest will be shuffled and dropped. The comma in between is not necessary. As a result, the prompt will be `aaa, bbb, eee, ccc, fff, ggg, hhh` or `aaa, bbb, fff, ccc, eee, ggg, hhh`, etc.
162
+ * `secondary_separator`
163
+ * Specifies an additional separator. The part separated by this separator is treated as one tag and is shuffled and dropped. It is then replaced by `caption_separator`. For example, if you specify `aaa;;;bbb;;;ccc`, it will be replaced by `aaa,bbb,ccc` or dropped together.
164
+ * `enable_wildcard`
165
+ * Enables wildcard notation. This will be explained later.
166
+
167
+ ### DreamBooth-specific options
168
+
169
+ DreamBooth-specific options only exist as subsets-specific options.
170
+
171
+ #### Subset-specific options
172
+
173
+ Options related to the configuration of DreamBooth subsets.
174
+
175
+ | Option Name | Example Setting | `[general]` | `[[datasets]]` | `[[dataset.subsets]]` |
176
+ | ---- | ---- | ---- | ---- | ---- |
177
+ | `image_dir` | `'C:\hoge'` | - | - | o (required) |
178
+ | `caption_extension` | `".txt"` | o | o | o |
179
+ | `class_tokens` | `"sks girl"` | - | - | o |
180
+ | `cache_info` | `false` | o | o | o |
181
+ | `is_reg` | `false` | - | - | o |
182
+
183
+ Firstly, note that for `image_dir`, the path to the image files must be specified as being directly in the directory. Unlike the previous DreamBooth method, where images had to be placed in subdirectories, this is not compatible with that specification. Also, even if you name the folder something like "5_cat", the number of repeats of the image and the class name will not be reflected. If you want to set these individually, you will need to explicitly specify them using `num_repeats` and `class_tokens`.
184
+
185
+ * `image_dir`
186
+ * Specifies the path to the image directory. This is a required option.
187
+ * Images must be placed directly under the directory.
188
+ * `class_tokens`
189
+ * Sets the class tokens.
190
+ * Only used during training when a corresponding caption file does not exist. The determination of whether or not to use it is made on a per-image basis. If `class_tokens` is not specified and a caption file is not found, an error will occur.
191
+ * `cache_info`
192
+ * Specifies whether to cache the image size and caption. If not specified, it is set to `false`. The cache is saved in `metadata_cache.json` in `image_dir`.
193
+ * Caching speeds up the loading of the dataset after the first time. It is effective when dealing with thousands of images or more.
194
+ * `is_reg`
195
+ * Specifies whether the subset images are for normalization. If not specified, it is set to `false`, meaning that the images are not for normalization.
196
+
197
+ ### Fine-tuning method specific options
198
+
199
+ The options for the fine-tuning method only exist for subset-specific options.
200
+
201
+ #### Subset-specific options
202
+
203
+ These options are related to the configuration of the fine-tuning method's subsets.
204
+
205
+ | Option name | Example setting | `[general]` | `[[datasets]]` | `[[dataset.subsets]]` |
206
+ | ---- | ---- | ---- | ---- | ---- |
207
+ | `image_dir` | `'C:\hoge'` | - | - | o |
208
+ | `metadata_file` | `'C:\piyo\piyo_md.json'` | - | - | o (required) |
209
+
210
+ * `image_dir`
211
+ * Specify the path to the image directory. Unlike the DreamBooth method, specifying it is not mandatory, but it is recommended to do so.
212
+ * The case where it is not necessary to specify is when the `--full_path` is added to the command line when generating the metadata file.
213
+ * The images must be placed directly under the directory.
214
+ * `metadata_file`
215
+ * Specify the path to the metadata file used for the subset. This is a required option.
216
+ * It is equivalent to the command-line argument `--in_json`.
217
+ * Due to the specification that a metadata file must be specified for each subset, it is recommended to avoid creating a metadata file with images from different directories as a single metadata file. It is strongly recommended to prepare a separate metadata file for each image directory and register them as separate subsets.
218
+
219
+ ### Options available when caption dropout method can be used
220
+
221
+ The options available when the caption dropout method can be used exist only for subsets. Regardless of whether it's the DreamBooth method or fine-tuning method, if it supports caption dropout, it can be specified.
222
+
223
+ #### Subset-specific options
224
+
225
+ Options related to the setting of subsets that caption dropout can be used for.
226
+
227
+ | Option Name | `[general]` | `[[datasets]]` | `[[dataset.subsets]]` |
228
+ | ---- | ---- | ---- | ---- |
229
+ | `caption_dropout_every_n_epochs` | o | o | o |
230
+ | `caption_dropout_rate` | o | o | o |
231
+ | `caption_tag_dropout_rate` | o | o | o |
232
+
233
+ ## Behavior when there are duplicate subsets
234
+
235
+ In the case of the DreamBooth dataset, if there are multiple `image_dir` directories with the same content, they are considered to be duplicate subsets. For the fine-tuning dataset, if there are multiple `metadata_file` files with the same content, they are considered to be duplicate subsets. If duplicate subsets exist in the dataset, subsequent subsets will be ignored.
236
+
237
+ However, if they belong to different datasets, they are not considered duplicates. For example, if you have subsets with the same `image_dir` in different datasets, they will not be considered duplicates. This is useful when you want to train with the same image but with different resolutions.
238
+
239
+ ```toml
240
+ # If data sets exist separately, they are not considered duplicates and are both used for training.
241
+
242
+ [[datasets]]
243
+ resolution = 512
244
+
245
+ [[datasets.subsets]]
246
+ image_dir = 'C:\hoge'
247
+
248
+ [[datasets]]
249
+ resolution = 768
250
+
251
+ [[datasets.subsets]]
252
+ image_dir = 'C:\hoge'
253
+ ```
254
+
255
+ ## Command Line Argument and Configuration File
256
+
257
+ There are options in the configuration file that have overlapping roles with command line argument options.
258
+
259
+ The following command line argument options are ignored if a configuration file is passed:
260
+
261
+ * `--train_data_dir`
262
+ * `--reg_data_dir`
263
+ * `--in_json`
264
+
265
+ The following command line argument options are given priority over the configuration file options if both are specified simultaneously. In most cases, they have the same names as the corresponding options in the configuration file.
266
+
267
+ | Command Line Argument Option | Prioritized Configuration File Option |
268
+ | ------------------------------- | ------------------------------------- |
269
+ | `--bucket_no_upscale` | |
270
+ | `--bucket_reso_steps` | |
271
+ | `--caption_dropout_every_n_epochs` | |
272
+ | `--caption_dropout_rate` | |
273
+ | `--caption_extension` | |
274
+ | `--caption_tag_dropout_rate` | |
275
+ | `--color_aug` | |
276
+ | `--dataset_repeats` | `num_repeats` |
277
+ | `--enable_bucket` | |
278
+ | `--face_crop_aug_range` | |
279
+ | `--flip_aug` | |
280
+ | `--keep_tokens` | |
281
+ | `--min_bucket_reso` | |
282
+ | `--random_crop` | |
283
+ | `--resolution` | |
284
+ | `--shuffle_caption` | |
285
+ | `--train_batch_size` | `batch_size` |
286
+
287
+ ## Error Guide
288
+
289
+ Currently, we are using an external library to check if the configuration file is written correctly, but the development has not been completed, and there is a problem that the error message is not clear. In the future, we plan to improve this problem.
290
+
291
+ As a temporary measure, we will list common errors and their solutions. If you encounter an error even though it should be correct or if the error content is not understandable, please contact us as it may be a bug.
292
+
293
+ * `voluptuous.error.MultipleInvalid: required key not provided @ ...`: This error occurs when a required option is not provided. It is highly likely that you forgot to specify the option or misspelled the option name.
294
+ * The error location is indicated by `...` in the error message. For example, if you encounter an error like `voluptuous.error.MultipleInvalid: required key not provided @ data['datasets'][0]['subsets'][0]['image_dir']`, it means that the `image_dir` option does not exist in the 0th `subsets` of the 0th `datasets` setting.
295
+ * `voluptuous.error.MultipleInvalid: expected int for dictionary value @ ...`: This error occurs when the specified value format is incorrect. It is highly likely that the value format is incorrect. The `int` part changes depending on the target option. The example configurations in this README may be helpful.
296
+ * `voluptuous.error.MultipleInvalid: extra keys not allowed @ ...`: This error occurs when there is an option name that is not supported. It is highly likely that you misspelled the option name or mistakenly included it.
297
+
298
+ ## Miscellaneous
299
+
300
+ ### Multi-line captions
301
+
302
+ By setting `enable_wildcard = true`, multiple-line captions are also enabled. If the caption file consists of multiple lines, one line is randomly selected as the caption.
303
+
304
+ ```txt
305
+ 1girl, hatsune miku, vocaloid, upper body, looking at viewer, microphone, stage
306
+ a girl with a microphone standing on a stage
307
+ detailed digital art of a girl with a microphone on a stage
308
+ ```
309
+
310
+ It can be combined with wildcard notation.
311
+
312
+ In metadata files, you can also specify multiple-line captions. In the `.json` metadata file, use `\n` to represent a line break. If the caption file consists of multiple lines, `merge_captions_to_metadata.py` will create a metadata file in this format.
313
+
314
+ The tags in the metadata (`tags`) are added to each line of the caption.
315
+
316
+ ```json
317
+ {
318
+ "/path/to/image.png": {
319
+ "caption": "a cartoon of a frog with the word frog on it\ntest multiline caption1\ntest multiline caption2",
320
+ "tags": "open mouth, simple background, standing, no humans, animal, black background, frog, animal costume, animal focus"
321
+ },
322
+ ...
323
+ }
324
+ ```
325
+
326
+ In this case, the actual caption will be `a cartoon of a frog with the word frog on it, open mouth, simple background ...`, `test multiline caption1, open mouth, simple background ...`, `test multiline caption2, open mouth, simple background ...`, etc.
327
+
328
+ ### Example of configuration file : `secondary_separator`, wildcard notation, `keep_tokens_separator`, etc.
329
+
330
+ ```toml
331
+ [general]
332
+ flip_aug = true
333
+ color_aug = false
334
+ resolution = [1024, 1024]
335
+
336
+ [[datasets]]
337
+ batch_size = 6
338
+ enable_bucket = true
339
+ bucket_no_upscale = true
340
+ caption_extension = ".txt"
341
+ keep_tokens_separator= "|||"
342
+ shuffle_caption = true
343
+ caption_tag_dropout_rate = 0.1
344
+ secondary_separator = ";;;" # subset 側に書くこともできます / can be written in the subset side
345
+ enable_wildcard = true # 同上 / same as above
346
+
347
+ [[datasets.subsets]]
348
+ image_dir = "/path/to/image_dir"
349
+ num_repeats = 1
350
+
351
+ # ||| の前後はカンマは不要です(自動的に追加されます) / No comma is required before and after ||| (it is added automatically)
352
+ caption_prefix = "1girl, hatsune miku, vocaloid |||"
353
+
354
+ # ||| の後はシャッフル、drop されず残ります / After |||, it is not shuffled or dropped and remains
355
+ # 単純に文字列として連結されるので、カンマなどは自分で入れる必要があります / It is simply concatenated as a string, so you need to put commas yourself
356
+ caption_suffix = ", anime screencap ||| masterpiece, rating: general"
357
+ ```
358
+
359
+ ### Example of caption, secondary_separator notation: `secondary_separator = ";;;"`
360
+
361
+ ```txt
362
+ 1girl, hatsune miku, vocaloid, upper body, looking at viewer, sky;;;cloud;;;day, outdoors
363
+ ```
364
+ The part `sky;;;cloud;;;day` is replaced with `sky,cloud,day` without shuffling or dropping. When shuffling and dropping are enabled, it is processed as a whole (as one tag). For example, it becomes `vocaloid, 1girl, upper body, sky,cloud,day, outdoors, hatsune miku` (shuffled) or `vocaloid, 1girl, outdoors, looking at viewer, upper body, hatsune miku` (dropped).
365
+
366
+ ### Example of caption, enable_wildcard notation: `enable_wildcard = true`
367
+
368
+ ```txt
369
+ 1girl, hatsune miku, vocaloid, upper body, looking at viewer, {simple|white} background
370
+ ```
371
+ `simple` or `white` is randomly selected, and it becomes `simple background` or `white background`.
372
+
373
+ ```txt
374
+ 1girl, hatsune miku, vocaloid, {{retro style}}
375
+ ```
376
+ If you want to include `{` or `}` in the tag string, double them like `{{` or `}}` (in this example, the actual caption used for training is `{retro style}`).
377
+
378
+ ### Example of caption, `keep_tokens_separator` notation: `keep_tokens_separator = "|||"`
379
+
380
+ ```txt
381
+ 1girl, hatsune miku, vocaloid ||| stage, microphone, white shirt, smile ||| best quality, rating: general
382
+ ```
383
+ It becomes `1girl, hatsune miku, vocaloid, microphone, stage, white shirt, best quality, rating: general` or `1girl, hatsune miku, vocaloid, white shirt, smile, stage, microphone, best quality, rating: general` etc.
384
+