kohya-ss / sd-scripts
- понедельник, 20 февраля 2023 г. в 00:13:49
This repository contains training, generation and utility scripts for Stable Diffusion.
Change History is moved to the bottom of the page. 更新履歴はページ末尾に移しました。
For easier use (GUI and PowerShell scripts etc...), please visit the repository maintained by bmaltais. Thanks to @bmaltais!
This repository contains the scripts for:
Stable Diffusion web UI now seems to support LoRA trained by sd-scripts
. (SD 1.x based only) Thank you for great work!!!
These files do not contain requirements for PyTorch. Because the versions of them depend on your environment. Please install PyTorch at first (see installation guide below.)
The scripts are tested with PyTorch 1.12.1 and 1.13.0, Diffusers 0.10.2.
All documents are in Japanese currently, and CUI based.
Python 3.10.6 and Git:
Give unrestricted script access to powershell so venv can work:
Set-ExecutionPolicy Unrestricted
and answer AOpen a regular Powershell terminal and type the following inside:
git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
python -m venv venv
.\venv\Scripts\activate
pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install --upgrade -r requirements.txt
pip install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl
cp .\bitsandbytes_windows\*.dll .\venv\Lib\site-packages\bitsandbytes\
cp .\bitsandbytes_windows\cextension.py .\venv\Lib\site-packages\bitsandbytes\cextension.py
cp .\bitsandbytes_windows\main.py .\venv\Lib\site-packages\bitsandbytes\cuda_setup\main.py
accelerate config
update: python -m venv venv
is seemed to be safer than python -m venv --system-site-packages venv
(some user have packages in global python).
Answers to accelerate config:
- This machine
- No distributed training
- NO
- NO
- NO
- all
- fp16
note: Some user reports ValueError: fp16 mixed precision requires a GPU
is occurred in training. In this case, answer 0
for the 6th question:
What GPU(s) (by id) should be used for training on this machine as a comma-separated list? [all]:
(Single GPU with id 0
will be used.)
Other versions of PyTorch and xformers seem to have problems with training. If there is no other reason, please install the specified version.
When a new release comes out you can upgrade your repo with the following command:
cd sd-scripts
git pull
.\venv\Scripts\activate
pip install --use-pep517 --upgrade -r requirements.txt
Once the commands have completed successfully you should be ready to use the new version.
The implementation for LoRA is based on cloneofsimo's repo. Thank you for great work!!!
The majority of scripts is licensed under ASL 2.0 (including codes from Diffusers, cloneofsimo's), however portions of the project are available under separate license terms:
Memory Efficient Attention Pytorch: MIT
bitsandbytes: MIT
BLIP: BSD-3-Clause
19 Feb. 2023, 2023/2/19:
Add --use_lion_optimizer
to each training script to use Lion optimizer.
pip install lion-pytorch
(it is not in requirements.txt
currently.)Add --lowram
option to train_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!
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 氏に感謝します。
git commit hash を現在のフォルダ位置に関わらず正しく取得するように修正しました。vladmandic 氏に感謝します。
16 Feb. 2023, 2023/2/16:
train_network.py
and train_db.py
. Thanks to shirayu!train_network.py
とtrain_db.py
で学習中に表示されるlossの値が移動平均になりました。epochの先頭で表示されるlossが大きく変動する事象を解決します。shirayu氏に感謝します。14 Feb. 2023, 2023/2/14:
train_network.py
. Thanks to Isotr0py!--verbose
option for resize_lora.py
. For details, see this PR. Thanks to mgz-dev!--noise_offset
option for each training scripts.
train_network.py
でマルチGPU学習をサポートしました。Isotr0py氏に感謝します。--verbose
オプションを resize_lora.py
に追加しました。表示される情報の詳細は こちらのPR をご参照ください。mgz-dev氏に感謝します。--noise_offset
オプションを各学習スクリプトに追加しました。
11 Feb. 2023, 2023/2/11:
lora_interrogator.py
is added in networks
folder. See python networks\lora_interrogator.py -h
for usage.
train_textual_inversion.py
now 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
でご確認ください。
train_textual_inversion.py
で複数のinit_word指定が可能になりました。
次の機能を削除し元に戻しました。混乱を招き申し訳ありません。
これらのオプションによりbucketが細分化され、ひとつのバッチ内に同一画像が重複して存在することが増えたため、バッチサイズを
そのbucketの画像種類数
までに制限する機能を追加しました。
10 Feb. 2023, 2023/2/10:
requirements.txt
to prevent upgrading with pip taking a long time or failure to upgrade.resize_lora.py
keeps the metadata of the model. dimension is resized from ...
is added to the top of ss_training_comment
.merge_lora.py
supports models with different alpha
s. If there is a problem, old version is merge_lora_old.py
.svd_merge_lora.py
is added. This script merges LoRA models with any rank (dim) and alpha, and approximate a new LoRA with svd for a specified rank (dim).resize_images_to_resolution.py
supports multibyte characters in filenames.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
が日本語ファイル名をサポートしました。9 Feb. 2023, 2023/2/9:
train_db.py
, fine_tune.py
and train_network.py
. Thanks to forestsource!
--caption_dropout_rate
option 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_epochs
option specifies how many epochs to drop captions. If 3
is specified, in epoch 3, 6, 9 ..., images are trained with all captions empty. Default is None (no dropout).--caption_tag_dropout_rate
option 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_tokens
option is set, these tokens (tags) are not dropped. Default is 0 (no droupout).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 (ドロップアウトなし)です。6 Feb. 2023, 2023/2/6:
--bucket_reso_steps
and --bucket_no_upscale
options are added to training scripts (fine tuning, DreamBooth, LoRA and Textual Inversion) and prepare_buckets_latents.py
.
--bucket_reso_steps
takes the steps for buckets in aspect ratio bucketing. Default is 64, same as before.
If --bucket_no_upscale
option is specified, images smaller than the bucket size will be processed without upscaling.
bucket_reso_steps=64
, the bucket is 256x256). The image will be trimmed.--resolution
are downsampled to the max bucket size.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_crop
now also works with buckets enabled.
--bucket_reso_steps
および--bucket_no_upscale
オプションを、学習スクリプトおよびprepare_buckets_latents.py
に追加しました。
--bucket_reso_steps
オプションでは、bucketの解像度の単位を指定できます。デフォルトは64で、今までと同じ動作です。
--bucket_no_upscale
オプションを指定すると、bucketサイズよりも小さい画像は拡大せずそのまま処理します。
bucket_reso_steps=64
の場合、256x256のbucket)。余りは都度trimmingされます。--resolution
で指定した最大サイズよりも面積が大きい画像は、最大サイズと同じ面積になるようアスペクト比を維持したまま縮小され、そのサイズを元にbucketが作られます。これらのオプションによりbucketが細分化され、ひとつのバッチ内に同一画像が重複して存在することが増えたため、バッチサイズをそのbucketの画像種類数
までに制限する機能を追加しました。
--random_crop
がbucketを有効にした場合にも機能するようになりました。
Please read Releases for recent updates. 最近の更新情報は Release をご覧ください。