
LECOでSDXLモデルを学習する
需要があったので軽くまとめ。LECOとはいったいなんぞや、何ができるんやということに対する解説は以下の記事を参照。とてもわかりやすいです。
では早速学習方法を書いていきます。
環境前提
Python:3.10.8(3.8だと動きません)
CUDA:11.8
環境構築方法(winローカル)
①winローカルの場合、簡単にセットアップできるツールがあるのでそれを使っていきます。
①上記のzipを適当なところで解凍し、install.ps1を右クリックしpowerShellから実行
"Install completed"と表示されたらOK
②examplesフォルダ以下のconfig.yamlとprompts.yamlをコピーして編集。以下、自分の例です。
neg4all_config.yaml
prompts_file: "examples/neg4all_prompts.yaml"
pretrained_model:
name_or_path: "C:/stable-diffusion-webui/models/Stable-diffusion/XeLblend1.fp16.safetensors" # you can also use .ckpt or .safetensors models
v2: false # true if model is v2.x
v_pred: false # true if model uses v-prediction
network:
type: "lierla"
rank: 16
alpha: 1.0
train:
precision: "bfloat16"
noise_scheduler: "ddim"
iterations: 2000
lr: 1e-4
optimizer: "lion"
lr_scheduler: "cosine"
save:
name: "neg4all"
path: "./output/neg4all"
per_steps: 100
precision: "bfloat16"
logging:
use_wandb: true
verbose: true
other:
use_xformers: true
neg4all_prompts.yaml
- target: "worst quality, low quality, ugly" # what word for erasing the positive concept from
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "poorly drawn hands, poorly drawn feet, poorly drawn face" # what word for erasing the positive concept from
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed" # what word for erasing the positive concept from
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "out of frame,body out of frame" # what word for erasing the positive concept from
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "bad art, bad anatomy" # what word for erasing the positive concept from
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "text, watermark" # what word for erasing the positive concept from
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "1girl" # what word for erasing the positive concept from
positive: "masterpiece, best quality, ultra high res, 8k, clearly fine detailed" # concept to erase
unconditional: "" # word to take the difference from the positive concept
neutral: "1girl" # starting point for conditioning the target
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
- target: "boy" # what word for erasing the positive concept from
positive: " masterpiece, best quality, ultra high res, 8k, clearly fine detailed" # concept to erase
unconditional: "" # word to take the difference from the positive concept
neutral: "boy" # starting point for conditioning the target
action: "erase" # erase or enhance
guidance_scale: 1.0
resolution: 1024
dynamic_resolution: true
batch_size: 1
各パラメータの解説は一番上に張ったリンクが詳しいので割愛。
Promptの設定について解説すると、お約束のnegativeプロンプト概念をモデルから消して、また1girl、boyに含まれる高品質になるprompt概念をモデルから消しています。
③train_leco.ps1を編集
config_fileを作成したものに変更する。
# LoRA train script by @bdsqlsz
$train_mode = "sdxl_lora"
$config_file = "examples/neg4all_config.yaml"
.\venv\Scripts\activate
$Env:HF_HOME = "huggingface"
$Env:XFORMERS_FORCE_DISABLE_TRITON = "1"
$ext_args = [System.Collections.ArrayList]::new()
$laungh_script = "train_lora"
if ($train_mode -ilike "sdxl*"){
$laungh_script = $laungh_script + "_xl"
}
# run train
python "./$laungh_script.py" `
--config_file=$config_file
Write-Output "Train finished"
Read-Host | Out-Null ;
④train_leco.ps1を右クリックしてpowerShellから実行
RTX3090で3時間ほど放置して学習終了した気がします(うろ覚え
結果は上のコードでこんな感じ。一応意味はありそう。
うおおおおー
— とりにく@毎日体重計に乗れ (@tori29umai) August 21, 2023
LOCOでSDXL用のネガティブプロンプト爪合わせのマイナスLoRA作ったった!!
1枚目:LoRAなし
2枚目:LoRAマイナス適用
3枚目:LoRAプラス適用
おおー確かに絵の破綻がなくなっている!プラスに関してはもはやよくわからんことになっている!!! pic.twitter.com/Cb7rOisjdV
以下は無料コラボではシステムメモリ不足で動かなかったコラボ。誰か試してけろ