Releases: kohya-ss/sd-scripts
Version 0.5.4
Updates at 1 Apr. 2023, 2023/4/1:
- Fix an issue that
merge_lora.pydoes not work with the latest version. - Fix an issue that
merge_lora.pydoes not merge Conv2d3x3 weights. - 最新のバージョンで
merge_lora.pyが動作しない不具合を修正しました。 merge_lora.pyでno module found for LoRA weight: ...と表示され Conv2d3x3 拡張の重みがマージされない不具合を修正しました。
Updates at 31 Mar. 2023, 2023/3/31:
- Fix an issue that the VRAM usage temporarily increases when loading a model in
train_network.py. - Fix an issue that an error occurs when loading a
.safetensorsmodel intrain_network.py. #354 train_network.pyでモデル読み込み時にVRAM使用量が一時的に大きくなる不具合を修正しました。train_network.pyで.safetensors形式のモデルを読み込むとエラーになる不具合を修正しました。#354
Updates at 30 Mar. 2023, 2023/3/30:
-
Support P+ training. Thank you jakaline-dev!
- See #327 for details.
- Use
train_textual_inversion_XTI.pyfor training. The usage is almost the same astrain_textual_inversion.py. However, sample image generation during training is not supported. - Use
gen_img_diffusers.pyfor image generation (I think Web UI is not supported). Specify the embedding with--XTI_embeddingsoption.
-
Reduce RAM usage at startup in
train_network.py. #332 Thank you guaneec! -
Support pre-merge for LoRA in
gen_img_diffusers.py. Specify--network_mergeoption. Note that the--amoption of the prompt option is no longer available with this option. -
P+ の学習に対応しました。jakaline-dev氏に感謝します。
- 詳細は #327 をご参照ください。
- 学習には
train_textual_inversion_XTI.pyを使用します。使用法はtrain_textual_inversion.pyとほぼ同じです。た
だし学習中のサンプル生成には対応していません。 - 画像生成には
gen_img_diffusers.pyを使用してください(Web UIは対応していないと思われます)。--XTI_embeddingsオプションで学習したembeddingを指定してください。
-
train_network.pyで起動時のRAM使用量を削減しました。#332 guaneec氏に感謝します。 -
gen_img_diffusers.pyでLoRAの事前マージに対応しました。--network_mergeオプションを指定してください。なおプロンプトオプションの--amは使用できなくなります。
Version 0.5.3
Updates at 28 Mar. 2023, 2023/3/28:
- Fix an issue that the training script crashes when
max_data_loader_n_workersis 0. max_data_loader_n_workersが0の時に学習スクリプトがエラーとなる不具合を修正しました。
Updates at 27 Mar. 2023, 2023/3/27:
-
Fix issues when
--persistent_data_loader_workersis specified.- The batch members of the bucket are not shuffled.
--caption_dropout_every_n_epochsdoes not work.- These issues occurred because the epoch transition was not recognized correctly. Thanks to u-haru for reporting the issue.
-
Fix an issue that images are loaded twice in Windows environment.
-
Add Min-SNR Weighting strategy. Details are in #308. Thank you to AI-Casanova for this great work!
- Add
--min_snr_gammaoption to training scripts, 5 is recommended by paper.
- Add
-
Add tag warmup. Details are in #322. Thanks to u-haru!
- Add
token_warmup_minandtoken_warmup_stepto dataset settings. - Gradually increase the number of tokens from
token_warmup_mintotoken_warmup_step. - For example, if
token_warmup_minis3andtoken_warmup_stepis10, the first step will use the first 3 tokens, and the 10th step will use all tokens.
- Add
-
Fix a bug in
resize_lora.py. Thanks to mgz-dev! #328 -
Add
--debug_datasetoption to step to the next step withSkey and to the next epoch withEkey. -
Fix other bugs.
-
--persistent_data_loader_workersを指定した時の各種不具合を修正しました。--caption_dropout_every_n_epochsが効かない。- バケットのバッチメンバーがシャッフルされない。
- エポックの遷移が正しく認識されないために発生していました。ご指摘いただいたu-haru氏に感謝します。
-
Windows環境で画像が二重に読み込まれる不具合を修正しました。
-
Min-SNR Weighting strategyを追加しました。 詳細は #308 をご参照ください。AI-Casanova氏の素晴らしい貢献に感謝します。
--min_snr_gammaオプションを学習スクリプトに追加しました。論文では5が推奨されています。
-
タグのウォームアップを追加しました。詳細は #322 をご参照ください。u-haru氏に感謝します。
- データセット設定に
token_warmup_minとtoken_warmup_stepを追加しました。 token_warmup_minで指定した数のトークン(カンマ区切りの文字列)から、token_warmup_stepで指定したステップまで、段階的にトークンを増やしていきます。- たとえば
token_warmup_minに3を、token_warmup_stepに10を指定すると、最初のステップでは最初から3個のトークンが使われ、10ステップ目では全てのトークンが使われます。
- データセット設定に
-
resize_lora.pyの不具合を修正しました。mgz-dev氏に感謝します。#328 -
--debug_datasetオプションで、Sキーで次のステップへ、Eキーで次のエポックへ進めるようにしました。 -
その他の不具合を修正しました。
Updates at 21 Mar. 2023, 2023/3/21:
- Add
--vae_batch_sizefor faster latents caching to each training script. This batches VAE calls.- Please start with
2or4depending on the size of VRAM.
- Please start with
- Fix a number of training steps with
--gradient_accumulation_stepsand--max_train_epochs. Thanks to tsukimiya! - Extract parser setup to external scripts. Thanks to robertsmieja!
- Fix an issue without
.npzand with--full_pathin training. - Support extensions with upper cases for images for not Windows environment.
- Fix
resize_lora.pyto work with LoRA with dynamic rank (includingconv_dim != network_dim). Thanks to toshiaki! - latentsのキャッシュを高速化する
--vae_batch_sizeオプションを各学習スクリプトに追加しました。VAE呼び出しをバッチ化します。
-VRAMサイズに応じて、2か4程度から試してください。 --gradient_accumulation_stepsと--max_train_epochsを指定した時、当該のepochで学習が止まらない不具合を修正しました。tsukimiya氏に感謝します。- 外部のスクリプト用に引数parserの構築が関数化されました。robertsmieja氏に感謝します。
- 学習時、
--full_path指定時に.npzが存在しない場合の不具合を解消しました。 - Windows以外の環境向けに、画像ファイルの大文字の拡張子をサポートしました。
resize_lora.pyを dynamic rank (rankが各LoRAモジュールで異なる場合、conv_dimがnetwork_dimと異なる場合も含む)の時に正しく動作しない不具合を修正しました。toshiaki氏に感謝します。
Version 0.5.2
Updates at 19 Mar. 2023, 2023/3/19:
-
Add a function to load training config with
.tomlto each training script. Thanks to Linaqruf for this great contribution!- Specify
.tomlfile with--config_file..tomlfile haskey=valueentries. Keys are same as command line options. See #241 for details. - All sub-sections are combined to a single dictionary (the section names are ignored.)
- Omitted arguments are the default values for command line arguments.
- Command line args override the arguments in
.toml. - With
--output_configoption, you can output current command line options to the.tomlspecified with--config_file. Please use as a template.
- Specify
-
Add
--lr_scheduler_typeand--lr_scheduler_argsarguments for custom LR scheduler to each training script. Thanks to Isotr0py! #271- Same as the optimizer.
-
Add sample image generation with weight and no length limit. Thanks to mio2333! #288
( ),(xxxx:1.2)and[ ]can be used.
-
Fix exception on training model in diffusers format with
train_network.pyThanks to orenwang! #290 -
各学習スクリプトでコマンドライン引数の代わりに
.tomlファイルで引数を指定できるようになりました。Linaqruf氏の多大な貢献に感謝します。--config_fileで.tomlファイルを指定してください。ファイルはkey=value形式の行で指定し、key はコマンドラインオプションと同じです。詳細は #241 をご覧ください。- ファイル内のサブセクションはすべて無視されます。
- 省略した引数はコマンドライン引数のデフォルト値になります。
- コマンドライン引数で
.tomlの設定を上書きできます。 --output_configオプションを指定すると、現在のコマンドライン引数を--config_fileオプションで指定した.tomlファイルに出力します。ひな形としてご利用ください。
-
任意のスケジューラを使うための
--lr_scheduler_typeと--lr_scheduler_argsオプションを各学習スクリプトに追加しました。Isotr0py氏に感謝します。 #271- 任意のオプティマイザ指定と同じ形式です。
-
学習中のサンプル画像出力でプロンプトの重みづけができるようになりました。また長さ制限も緩和されています。mio2333氏に感謝します。 #288
( )、(xxxx:1.2)や[ ]が使えます。
-
train_network.pyでローカルのDiffusersモデルを指定した時のエラーを修正しました。orenwang氏に感謝します。 #290
Updates at 11 Mar. 2023, 2023/3/11:
- Fix
svd_merge_lora.pycauses an error about the device. svd_merge_lora.pyでデバイス関連のエラーが発生する不具合を修正しました。
Version 0.5.1
Updates at 10 Mar. 2023, 2023/3/10: release v0.5.1
-
Fix to LoRA modules in the model are same to the previous (before 0.5.0) if Conv2d-3x3 is disabled (no
conv_dimarg, default).- Conv2D with kernel size 1x1 in ResNet modules were accidentally included in v0.5.0.
- Trained models with v0.5.0 will work with Web UI's built-in LoRA and Additional Networks extension.
-
Fix an issue that dim (rank) of LoRA module is limited to the in/out dimensions of the target Linear/Conv2d (in case of the dim > 320).
-
resize_lora.pynow have a feature todynamic resizingwhich means each LoRA module can have different ranks (dims). Thanks to mgz-dev for this great work!- The appropriate rank is selected based on the complexity of each module with an algorithm specified in the command line arguments. For details: #243
-
Multiple GPUs training is finally supported in
train_network.py. Thanks to ddPn08 to solve this long running issue! -
Dataset with fine-tuning method (with metadata json) now works without images if
.npzfiles exist. Thanks to rvhfxb! -
train_network.pycan work if the current directory is not the directory where the script is in. Thanks to mio2333! -
Fix
extract_lora_from_models.pyandsvd_merge_lora.pydoesn't work with higher rank (>320). -
LoRAのConv2d-3x3拡張を行わない場合(
conv_dimを指定しない場合)、以前(v0.5.0)と同じ構成になるよう修正しました。- ResNetのカーネルサイズ1x1のConv2dが誤って対象になっていました。
- ただv0.5.0で学習したモデルは Additional Networks 拡張、およびWeb UIのLoRA機能で問題なく使えると思われます。
-
LoRAモジュールの dim (rank) が、対象モジュールの次元数以下に制限される不具合を修正しました(320より大きい dim を指定した場合)。
-
resize_lora.pyにdynamic resizing(リサイズ後の各LoRAモジュールが異なるrank (dim) を持てる機能)を追加しました。mgz-dev 氏の貢献に感謝します。- 適切なランクがコマンドライン引数で指定したアルゴリズムにより自動的に選択されます。詳細はこちらをご覧ください: #243
-
train_network.pyでマルチGPU学習をサポートしました。長年の懸案を解決された ddPn08 氏に感謝します。 -
fine-tuning方式のデータセット(メタデータ.jsonファイルを使うデータセット)で
.npzが存在するときには画像がなくても動作するようになりました。rvhfxb 氏に感謝します。 -
他のディレクトリから
train_network.pyを呼び出しても動作するよう変更しました。 mio2333 氏に感謝します。 -
extract_lora_from_models.pyおよびsvd_merge_lora.pyが320より大きいrankを指定すると動かない不具合を修正しました。
Updates at 9 Mar. 2023, 2023/3/9: release v0.5.0
- There may be problems due to major changes. If you cannot revert back to the previous version when problems occur, please do not update for a while.
- Minimum metadata (module name, dim, alpha and network_args) is recorded even with
--no_metadata, issue #254 train_network.pysupports LoRA for Conv2d-3x3 (extended to conv2d with a kernel size not 1x1).- Same as a current version of LoCon. Thank you very much KohakuBlueleaf for your help!
- LoCon will be enhanced in the future. Compatibility for future versions is not guaranteed.
- Specify
--network_argsoption like:--network_args "conv_dim=4" "conv_alpha=1" - Additional Networks extension version 0.5.0 or later is required to use 'LoRA for Conv2d-3x3' in Stable Diffusion web UI.
- Stable Diffusion web UI built-in LoRA does not support 'LoRA for Conv2d-3x3' now. Consider carefully whether or not to use it.
- Same as a current version of LoCon. Thank you very much KohakuBlueleaf for your help!
- Merging/extracting scripts also support LoRA for Conv2d-3x3.
- Free CUDA memory after sample generation to reduce VRAM usage, issue #260
- Empty caption doesn't cause error now, issue #258
- Fix sample generation is crashing in Textual Inversion training when using templates, or if height/width is not divisible by 8.
- Update documents (Japanese only).
Version 0.4.5
Updates at 2 Mar. 2023, 2023/3/2:
-
Dependencies are updated, Please upgrade the repo.
-
Add detail dataset config feature by extra config file. Thanks to fur0ut0 for this great contribution!
- Documentation is here (only in Japanese currently.)
- Specify
.tomlfile with--dataset_configoption. - The previous options for dataset can be used as is.
- There might be a bug due to the large scale of update, please report any problems if you find.
-
Add feature to generate sample images in the middle of training for each training scripts.
--sample_every_n_stepsand--sample_every_n_epochsoptions: frequency to generate.--sample_promptsoption: the file contains prompts (each line generates one image.)- The prompt is subset of
gen_img_diffusers.py. The prompt optionsw, h, d, l, s, nare supported.
- The prompt is subset of
--sample_sampleroption: sampler (scheduler) for generating, such as ddim or k_euler. See help for useable samplers.
-
Add
--tokenizer_cache_dirto each training and generation scripts to cache Tokenizer locally from Diffusers.- Scripts will support offline training/generation after caching.
-
Support letents upscaling for highres. fix, and VAE batch size in
gen_img_diffusers.py(no documentation yet.) -
ライブラリを更新しました。アップグレードに従って更新してください。
-
設定ファイルによるデータセット定義機能を追加しました。素晴らしいPRを提供していただいた fur0ut0 氏に感謝します。
- ドキュメントはこちら。
--dataset_configオプションで.tomlファイルを指定してください。- 今までのオプションはそのまま使えます。
- 大規模なアップデートのため、もし不具合がありましたらご報告ください。
-
学習の途中でサンプル画像を生成する機能を各学習スクリプトに追加しました。
--sample_every_n_stepsと--sample_every_n_epochsオプション:生成頻度を指定--sample_promptsオプション:プロンプトを記述したファイルを指定(1行ごとに1枚の画像を生成)- プロンプトには
gen_img_diffusers.pyのプロンプトオプションの一部、w, h, d, l, s, nが使えます。
- プロンプトには
--sample_samplerオプション:ddim や k_euler などの sampler (scheduler) を指定します。使用できる sampler についてはヘルプをご覧ください。
-
--tokenizer_cache_dirオプションを各学習スクリプトおよび生成スクリプトに追加しました。Diffusers から Tokenizer を取得してきてろーかるに保存します。- 一度キャッシュしておくことでオフライン学習、生成ができるかもしれません。
-
gen_img_diffusers.pyで highres. fix での letents upscaling と VAE のバッチサイズ指定に対応しました。
Version 0.4.4
Updates at 23 Feb. 2023, 2023/2/23:
- Fix instability training issue in
train_network.py.fp16training is probably not affected by this issue.- Training with
floatfor SD2.x models will work now. Also training withbf16might be improved. - This issue seems to have occurred in PR#190.
- Add some metadata to LoRA model. Thanks to space-nuko!
- Raise an error if optimizer options conflict (e.g.
--optimizer_typeand--use_8bit_adam.) - Support ControlNet in
gen_img_diffusers.py(no documentation yet.) train_network.pyで学習が不安定になる不具合を修正しました。fp16精度での学習には恐らくこの問題は影響しません。float精度での SD2.x モデルの学習が正しく動作するようになりました。またbf16精度の学習も改善する可能性があります。- この問題は PR#190 から起きていたようです。
- いくつかのメタデータを LoRA モデルに追加しました。 space-nuko 氏に感謝します。
- オプティマイザ関係のオプションが矛盾していた場合、エラーとするように修正しました(例:
--optimizer_typeと--use_8bit_adam)。 gen_img_diffusers.pyで ControlNet をサポートしました(ドキュメントはのちほど追加します)。
Updates at 22 Feb. 2023, 2023/2/22:
- Refactor optmizer options. Thanks to mgz-dev!
- Add
--optimizer_typeoption for each training script. Please see help. Japanese documentation is here. --use_8bit_adamand--use_lion_optimizeroptions also work, but override above option.
- Add
- Add SGDNesterov and its 8bit.
- Add D-Adaptation optimizer. Thanks to BootsofLagrangian and all!
- Please install D-Adaptation optimizer with
pip install dadaptation(it is not in requirements.txt currently.) - Please see #181 for details.
- Please install D-Adaptation optimizer with
- Add AdaFactor optimizer. Thanks to Toshiaki!
- Extra lr scheduler settings (num_cycles etc.) are working in training scripts other than
train_network.py. - Add
--max_grad_normoption for each training script for gradient clipping.0.0disables clipping. - Symbolic link can be loaded in each training script. Thanks to TkskKurumi!
- オプティマイザ関連のオプションを見直しました。mgz-dev氏に感謝します。
--optimizer_typeを各学習スクリプトに追加しました。ドキュメントはこちら。--use_8bit_adamと--use_lion_optimizerのオプションは依然として動作しますがoptimizer_typeを上書きしますのでご注意ください。
- SGDNesterov オプティマイザおよびその8bit版を追加しました。
- D-Adaptation オプティマイザを追加しました。BootsofLagrangian 氏および諸氏に感謝します。
pip install dadaptationコマンドで別途インストールが必要です(現時点ではrequirements.txtに含まれておりません)。- こちらのissueもあわせてご覧ください。 #181
- AdaFactor オプティマイザを追加しました。Toshiaki氏に感謝します。
- 追加のスケジューラ設定(num_cycles等)が
train_network.py以外の学習スクリプトでも使えるようになりました。 - 勾配クリップ時の最大normを指定する
--max_grad_normオプションを追加しました。0.0を指定するとクリップしなくなります。 - 各学習スクリプトでシンボリックリンクが読み込めるようになりました。TkskKurumi氏に感謝します。
Version 0.4.3
Updates at 19 Feb. 2023, 2023/2/19:
-
Add
--use_lion_optimizerto each training script to use Lion optimizer.- Please install Lion optimizer with
pip install lion-pytorch(it is not inrequirements.txtcurrently.)
- Please install Lion optimizer with
-
Add
--lowramoption totrain_network.py. Load models to VRAM instead of VRAM (for machines which have bigger VRAM than RAM such as Colab and Kaggle). Thanks to Isotr0py!- Default behavior (without lowram) has reverted to the same as before 14 Feb.
-
Fixed git commit hash to be set correctly regardless of the working directory. Thanks to vladmandic!
-
--use_lion_optimizerオプションを各学習スクリプトに追加しました。 Lion optimizer を使用できます。- あらかじめ
pip install lion-pytorchでインストールしてください(現在はrequirements.txtに含まれていません)。
- あらかじめ
-
--lowramオプションをtrain_network.pyに追加しました。モデルをRAMではなくVRAMに読み込みます(ColabやKaggleなど、VRAMがRAMに比べて多い環境で有効です)。 Isotr0py 氏に感謝します。- lowram オプションなしのデフォルト動作は2/14より前と同じに戻しました。
-
git commit hash を現在のフォルダ位置に関わらず正しく取得するように修正しました。vladmandic 氏に感謝します。
Updates at 16 Feb. 2023, 2023/2/16:
- Noise offset is recorded to the metadata. Thanks to space-nuko!
- Show the moving average loss to prevent loss jumping in
train_network.pyandtrain_db.py. Thanks to shirayu! - Noise offsetがメタデータに記録されるようになりました。space-nuko氏に感謝します。
train_network.pyとtrain_db.pyで学習中に表示されるlossの値が移動平均になりました。epochの先頭で表示されるlossが大きく変動する事象を解決します。shirayu氏に感謝します。- 14 Feb. 2023, 2023/2/14:
- Add support with multi-gpu trainining for
train_network.py. Thanks to Isotr0py! - Add
--verboseoption forresize_lora.py. For details, see this PR. Thanks to mgz-dev! - Git commit hash is added to the metadata for LoRA. Thanks to space-nuko!
- Add
--noise_offsetoption for each training scripts.- Implementation of https://www.crosslabs.org//blog/diffusion-with-offset-noise
- This option may improve ability to generate darker/lighter images. May work with LoRA.
train_network.pyでマルチGPU学習をサポートしました。Isotr0py氏に感謝します。--verboseオプションをresize_lora.pyに追加しました。表示される情報の詳細は こちらのPR をご参照ください。mgz-dev氏に感謝します。- LoRAのメタデータにgitのcommit hashを追加しました。space-nuko氏に感謝します。
--noise_offsetオプションを各学習スクリプトに追加しました。- こちらの記事の実装になります: https://www.crosslabs.org//blog/diffusion-with-offset-noise
- 全体的に暗い、明るい画像の生成結果が良くなる可能性があるようです。LoRA学習でも有効なようです。
- Add support with multi-gpu trainining for
Updates at 11 Feb. 2023, 2023/2/11:
-
lora_interrogator.pyis added innetworksfolder. Seepython networks\lora_interrogator.py -hfor usage.- For LoRAs where the activation word is unknown, this script compares the output of Text Encoder after applying LoRA to that of unapplied to find out which token is affected by LoRA. Hopefully you can figure out the activation word. LoRA trained with captions does not seem to be able to interrogate.
- Batch size can be large (like 64 or 128).
-
train_textual_inversion.pynow supports multiple init words. -
Following feature is reverted to be the same as before. Sorry for confusion:
Now the number of data in each batch is limited to the number of actual images (not duplicated). Because a certain bucket may contain smaller number of actual images, so the batch may contain same (duplicated) images.
-
lora_interrogator.pyをnetworkフォルダに追加しました。使用法はpython networks\lora_interrogator.py -hでご確認ください。- このスクリプトは、起動promptがわからないLoRAについて、LoRA適用前後のText Encoderの出力を比較することで、どのtokenの出力が変化しているかを調べます。運が良ければ起動用の単語が分かります。キャプション付きで学習されたLoRAは影響が広範囲に及ぶため、調査は難しいようです。
- バッチサイズはわりと大きくできます(64や128など)。
-
train_textual_inversion.pyで複数のinit_word指定が可能になりました。 -
次の機能を削除し元に戻しました。混乱を招き申し訳ありません。
これらのオプションによりbucketが細分化され、ひとつのバッチ内に同一画像が重複して存在することが増えたため、バッチサイズを
そのbucketの画像種類数までに制限する機能を追加しました。
Updates at 10 Feb. 2023, 2023/2/10:
- Updated
requirements.txtto prevent upgrading with pip taking a long time or failure to upgrade. resize_lora.pykeeps the metadata of the model.dimension is resized from ...is added to the top ofss_training_comment.merge_lora.pysupports models with differentalphas. If there is a problem, old version ismerge_lora_old.py.svd_merge_lora.pyis added. This script merges LoRA models with any rank (dim) and alpha, and approximate a new LoRA with svd for a specified rank (dim).- Note: merging scripts erase the metadata currently.
resize_images_to_resolution.pysupports multibyte characters in filenames.- pipでの更新が長時間掛かったり、更新に失敗したりするのを防ぐため、
requirements.txtを更新しました。 resize_lora.pyがメタデータを保持するようになりました。dimension is resized from ...という文字列がss_training_commentの先頭に追加されます。merge_lora.pyがalphaが異なるモデルをサポートしました。 何か問題がありましたら旧バージョンmerge_lora_old.pyをお使いください。svd_merge_lora.pyを追加しました。 複数の任意のdim (rank)、alphaのLoRAモデルをマージし、svdで任意dim(rank)のLoRAで近似します。- 注:マージ系のスクリプトは現時点ではメタデータを消去しますのでご注意ください。
resize_images_to_resolution.pyが日本語ファイル名をサポートしました。
Updates at 9 Feb. 2023, 2023/2/9:
- Caption dropout is supported in
train_db.py,fine_tune.pyandtrain_network.py. Thanks to forestsource!--caption_dropout_rateoption specifies the dropout rate for captions (0~1.0, 0.1 means 10% chance for dropout). If dropout occurs, the image is trained with the empty caption. Default is 0 (no dropout).--caption_dropout_every_n_epochsoption specifies how many epochs to drop captions. If3is specified, in epoch 3, 6, 9 ..., images are trained with all captions empty. Default is None (no dropout).--caption_tag_dropout_rateoption specified the dropout rate for tags (comma separated tokens) (0~1.0, 0.1 means 10% chance for dropout). If dropout occurs, the tag is removed from the caption. If--keep_tokensoption is set, these tokens (tags) are not dropped. Default is 0 (no droupout).- The bulk image downsampling script is added. Documentation is here (in Jpanaese). Thanks to bmaltais!
- Typo check is added. Thanks to shirayu!
- キャプションのドロップアウトを
train_db.py、fine_tune.py、train_network.pyの各スクリプトに追加しました。forestsource氏に感謝します。--caption_dropout_rateオプションでキャプションのドロップアウト率を指定します(0~1.0、 0.1を指定すると10%の確率でドロップアウト)。ドロップアウトされた場合、画像は空のキャプションで学習されます。デフォルトは 0 (ドロップアウトなし)です。--caption_dropout_every_n_epochsオプションで何エポックごとにキャプションを完全にドロップアウトするか指定します。たとえば3を指定すると、エポック3、6、9……で、すべての画像がキャプションなしで学習されます。デフォルトは None (ドロップアウトなし)です。--caption_tag_dropout_rateオプションで各タグ(カンマ区切りの各部分)のドロップアウト率を指定します(0~1.0、 0.1を指定すると10%の確率でドロップアウト)。ドロップアウトが起きるとそのタグはそのときだけキャプションから取り除かれて学習されます。--keep_tokensオプションを指定していると、シャッフルされない部分のタグはドロップアウトされません。デフォルトは 0 (ドロップアウトなし)です。- 画像の一括縮小スクリプトを追加しました。ドキュメントは こちら です。bmaltais氏に感謝します。
- 誤字チェッカが追加されました。shirayu氏に感謝します。
Updates at 6 Feb. 2023, 2023/2/6:
-
--bucket_reso_stepsand--bucket_no_upscaleoptions are added to training scripts (fine tuning, DreamBooth, LoRA and Textual Inversion) andprepare_buckets_latents.py. -
--bucket_reso_stepstakes the steps for buckets in aspect ratio bucketing. Default is 64, same as before.- Any value greater than or equal to 1 can be specified; 64 is highly recommended and a value divisible by 8 is recommended.
- If less than 64 is specified, padding will occur within U-Net. The result is unknown.
- If you specify a value that is not divisible by 8, it will be truncated to divisible by 8 inside VAE, because the size of the latent is 1/8 of the image size.
-
If
--bucket_no_upscaleoption is specified, images smaller than the bucket size will be processed without upscaling.- Internally, a bucket smaller than the image size is created (for example, if the image is 300x300 and
bucket_reso_steps=64, the bucket is 256x256). The image will be trimmed. - Implementation of #130.
- Images with an area larger than the maximum size specified by
--resolutionare downsampled to the max bucket size.
- Internally, a bucket smaller than the image size is created (for example, if the image is 300x300 and
-
Now the number of data in each batch is limited to the number of actual images (not duplicated). Because a certain bucket may contain smaller number of actual images, so the batch may contain same (duplicated) images.
-
--random_cropnow also works with buckets enabled.- Instead of always cropping the center of the image, the image is shifted left, right, up, and down to be used as the training data. This is expected to train to the edges of the image.
- Implementation of discussion #34.
-
--bucket_reso_stepsおよび--bucket_no_upscaleオプションを、学習スクリプトおよびprepare_buckets_latents.pyに追加しました。 -
--bucket_reso_stepsオプションでは、bucketの解像度の単位を指定できます。デフォルトは64で、今までと同じ動作です。- 1以上の任意の値を指定できます。基本的には64を推奨します。64以外の値では、8で割り切れる値を推奨します。
- 64未満を指定するとU-Netの内部でpaddingが発生します。どのような結果になるかは未知数です。
- 8で割り切れない値を指定すると余りはVAE内部で切り捨てられます。
-
--bucket_no_upscaleオプションを指定すると、bucketサイズよりも小さい画像は拡大せずそのまま処理します。- 内部的には画像サイズ以下のサイズのbucketを作成します(たとえば画像が300x300で
bucket_reso_steps=64の場合、256x256のbucket)。余りは都度trimmingされます。 - #130 を実装したものです。
--resolutionで指定した最大サイズよりも面積が大きい画像は、最大サイズと同じ面積になるようアスペクト比を維持したまま縮小され、そのサイズを元にbucketが作られます。
- 内部的には画像サイズ以下のサイズのbucketを作成します(たとえば画像が300x300で
-
これらのオプションによりbucketが細分化され、ひとつのバッチ内に同一画像が重複して存在することが増えたため、バッチサイズを``そのbucket...
Version 0.4.2
Updates at 4 Feb. 2023, 2023/2/4
--persistent_data_loader_workersoption is added tofine_tune.py,train_db.pyandtrain_network.py. This option may significantly reduce the waiting time between epochs. Thanks to hitomi!--debug_datasetoption is now working on non-Windows environment. Thanks to tsukimiya!networks/resize_lora.pyscript is added. This can approximate the higher-rank (dim) LoRA model by a lower-rank LoRA model, e.g. 128 by 4. Thanks to mgz-dev!--helpoption shows usage.- Currently the metadata is not copied. This will be fixed in the near future.
--persistent_data_loader_workersオプションがfine_tune.py、train_db.py、train_network.pyの各スクリプトに追加されました。このオプションを指定するとエポック間の待ち時間が大幅に短縮される可能性があります。hitomi氏に感謝します。--debug_datasetオプションがWindows環境以外でも動くようになりました。tsukimiya氏に感謝します。networks/resize_lora.pyスクリプトを追加しました。高rankのLoRAモデルを低rankのLoRAモデルで近似します(つまり128 rank (dim)のLoRAに似た、4 rank (dim)のLoRAを作ることができます)。mgz-dev氏に感謝します。- 使い方は
--helpオプションを指定して参照してください。 - 現時点ではメタデータはコピーされません。近日中に対応予定です。
- 使い方は
Updates at 3 Feb. 2023, 2023/2/3
-
Update finetune preprocessing scripts.
.bmpand.jpegare supported. Thanks to breakcore2 and p1atdev!- The default weights of
tag_images_by_wd14_tagger.pyis nowSmilingWolf/wd-v1-4-convnext-tagger-v2. You can specify another model id fromSmilingWolfby--repo_idoption. Thanks to SmilingWolf for the great work.- To change the weight, remove
wd14_tagger_modelfolder, and run the script again.
- To change the weight, remove
--max_data_loader_n_workersoption is added to each script. This option uses the DataLoader for data loading to speed up loading, 20%~30% faster.- Please specify 2 or 4, depends on the number of CPU cores.
--recursiveoption is added tomerge_dd_tags_to_metadata.pyandmerge_captions_to_metadata.py, only works with--full_path.make_captions_by_git.pyis added. It uses GIT microsoft/git-large-textcaps for captioning.requirements.txtis updated. If you use this script, please update the libraries.- Usage is almost the same as
make_captions.py, but batch size should be smaller. --remove_wordsoption removes as much text as possible (such asthe word "XXXX" on it).
--skip_existingoption is added toprepare_buckets_latents.py. Images with existing npz files are ignored by this option.clean_captions_and_tags.pyis updated to remove duplicated or conflicting tags, e.g.shirtis removed whenwhite shirtexists. ifblack hairis withred hair, both are removed.
-
Tag frequency is added to the metadata in
train_network.py. Thanks to space-nuko!- All tags and number of occurrences of the tag are recorded. If you do not want it, disable metadata storing with
--no_metadataoption.
- All tags and number of occurrences of the tag are recorded. If you do not want it, disable metadata storing with
-
fine tuning用の前処理スクリプト群を更新しました。
- 拡張子
.bmpと.jpegをサポートしました。breakcore2氏およびp1atdev氏に感謝します。 tag_images_by_wd14_tagger.pyのデフォルトの重みをSmilingWolf/wd-v1-4-convnext-tagger-v2に更新しました。他のSmilingWolf氏の重みも--repo_idオプションで指定可能です。SmilingWolf氏に感謝します。- 重みを変更するときには
wd14_tagger_modelフォルダを削除してからスクリプトを再実行してください。
- 重みを変更するときには
--max_data_loader_n_workersオプションが各スクリプトに追加されました。DataLoaderを用いることで読み込み処理を並列化し、処理を20~30%程度高速化します。- CPUのコア数に応じて2~4程度の値を指定してください。
--recursiveオプションをmerge_dd_tags_to_metadata.pyとmerge_captions_to_metadata.pyに追加しました。--full_pathを指定したときのみ使用可能です。make_captions_by_git.pyを追加しました。GIT microsoft/git-large-textcaps を用いてキャプションニングを行います。requirements.txtが更新されていますので、ライブラリをアップデートしてください。- 使用法は
make_captions.pyとほぼ同じですがバッチサイズは小さめにしてください。 --remove_wordsオプションを指定するとテキスト読み取りを可能な限り削除します(the word "XXXX" on itのようなもの)。
--skip_existingをprepare_buckets_latents.pyに追加しました。すでにnpzファイルがある画像の処理をスキップします。clean_captions_and_tags.pyを重複タグや矛盾するタグを削除するよう機能追加しました。例:white shirtタグがある場合、shirtタグは削除されます。またblack hairとred hairの両方がある場合、両方とも削除されます。
- 拡張子
-
train_network.pyで使用されているタグと回数をメタデータに記録するようになりました。space-nuko氏に感謝します。- すべてのタグと回数がメタデータに記録されます 望まない場合には
--no_metadata optionオプションでメタデータの記録を停止してください。
- すべてのタグと回数がメタデータに記録されます 望まない場合には
Version 0.4.1
Updates at 29 Jan. 2023, 2023/1/29
- Add
--lr_scheduler_num_cyclesand--lr_scheduler_poweroptions fortrain_network.pyfor cosine_with_restarts and polynomial learning rate schedulers. Thanks to mgz-dev! - Fixed U-Net
sample_sizeparameter to64when converting from SD to Diffusers format, inconvert_diffusers20_original_sd.py --lr_scheduler_num_cyclesと--lr_scheduler_powerオプションをtrain_network.pyに追加しました。前者は cosine_with_restarts、後者は polynomial の学習率スケジューラに有効です。mgz-dev氏に感謝します。convert_diffusers20_original_sd.pyで SD 形式から Diffusers に変換するときの U-Net のsample_sizeパラメータを64に修正しました。
Updates at 26 Jan. 2023, 2023/1/26
- Add Textual Inversion training. Documentation is here (in Japanese.)
- Textual Inversionの学習をサポートしました。ドキュメントはこちら。
Updates at 24 Jan. 2023, 2023/1/24
- Change the default save format to
.safetensorsfortrain_network.py. - Add
--save_n_epoch_ratiooption to specify how often to save. Thanks to forestsource!- For example, if 5 is specified, 5 (or 6) files will be saved in training.
- Add feature to pre-calculate hash to reduce loading time in the extension. Thanks to space-nuko!
- Add bucketing metadata. Thanks to space-nuko!
- Fix an error with bf16 model in
gen_img_diffusers.py. train_network.pyのモデル保存形式のデフォルトを.safetensorsに変更しました。- モデルを保存する頻度を指定する
--save_n_epoch_ratioオプションが追加されました。forestsource氏に感謝します。- たとえば 5 を指定すると、学習終了までに合計で5個(または6個)のファイルが保存されます。
- 拡張でモデル読み込み時間を短縮するためのハッシュ事前計算の機能を追加しました。space-nuko氏に感謝します。
- メタデータにbucket情報が追加されました。space-nuko氏に感謝します。
gen_img_diffusers.pyでbf16形式のモデルを読み込んだときのエラーを修正しました。
Version 0.4.0
-
Add
--network_alphaoption to specifyalphavalue to prevent underflows for stable training. Thanks to CCRcmcpe!- Details of the issue are described in kohya-ss/sd-webui-additional-networks#49 .
- The default value is
1, scale1 / rank (or dimension). Set same value asnetwork_dimfor same behavior to old version. - LoRA with a large dimension (rank) seems to require a higher learning rate with
alpha=1(e.g. 1e-3 for 128-dim, still investigating).
-
Add logging for the learning rate for U-Net and Text Encoder independently, and for running average epoch loss. Thanks to mgz-dev!
-
Add more metadata such as dataset/reg image dirs, session ID, output name etc... See #77 for details. Thanks to space-nuko!
- Now the metadata includes the folder name (the basename of the folder contains image files, not fullpath). If you do not want it, disable metadata storing with
--no_metadataoption.
- Now the metadata includes the folder name (the basename of the folder contains image files, not fullpath). If you do not want it, disable metadata storing with
-
Add
--training_commentoption. You can specify an arbitrary string and refer to it by the extension. -
アンダーフローを防ぎ安定して学習するための
alpha値を指定する、--network_alphaオプションを追加しました。CCRcmcpe 氏に感謝します。- 問題の詳細はこちらをご覧ください: kohya-ss/sd-webui-additional-networks#49
- デフォルト値は
1で、LoRAの計算結果を1 / rank (dimension・次元数)倍します(つまり小さくなります。これにより同じ効果を出すために必要なLoRAの重みの変化が大きくなるため、アンダーフローが避けられるようになります)。network_dimと同じ値を指定すると旧バージョンと同じ動作になります。 alpha=1の場合、次元数(rank)の多いLoRAモジュールでは学習率を高めにしたほうが良いようです(128次元で1e-3など)。
-
U-Net と Text Encoder のそれぞれの学習率、エポックの平均lossをログに記録するようになりました。mgz-dev 氏に感謝します。
-
画像ディレクトリ、セッションID、出力名などいくつかの項目がメタデータに追加されました(詳細は #77 を参照)。space-nuko氏に感謝します。
- メタデータにフォルダ名が含まれるようになりました(画像を含むフォルダの名前のみで、フルパスではありません)。 もし望まない場合には
--no_metadataオプションでメタデータの記録を止めてください。
- メタデータにフォルダ名が含まれるようになりました(画像を含むフォルダの名前のみで、フルパスではありません)。 もし望まない場合には
-
--training_commentオプションを追加しました。任意の文字列を指定でき、Web UI拡張から参照できます。