Akegarasu / lora-scripts

LoRA & Dreambooth training scripts & GUI use kohya-ss's trainer, for diffusion model.
GNU Affero General Public License v3.0
4.53k stars 560 forks source link

能支持设置连续训练队列吗 #40

Open Reekin opened 1 year ago

Reekin commented 1 year ago

每个lora训练几个小时,睡前开始跑,早上急着出门来不及重开一轮,一天里大部分时间都浪费了有点可惜

petercham commented 1 year ago

挂个远程桌面吧

DoubleCake commented 1 year ago

把配置写好,比如在batchTrain文件夹里写好a.ps1,b.ps1 然后再写个ps1脚本依次运行文件夹里的脚本就行了

wakening commented 1 year ago

简单改了下train_by_toml.ps1,可以按配置批量炼丹,把下面代码复制到记事本保存,后缀改成ps1,放到根目录 2024.03.17更新适配v1.8.0.fix1版本,再试试看 @cindylaii @dahuzi773

# LoRA train script by @Akegarasu

# 2024.03.17
# 批量配置文件,每行以逗号结尾,最后一行不要逗号
# 若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1
# 若想看图表可执行:tensorboard.ps1
[string[]]$my_batch_tomls=(
"./toml/批次1.toml",
"./toml/批次2.toml",
"./toml/批次3.toml"
)
# 若你执行此脚本还剩N小时才能跑完想继续加任务,
# 下方代码可提供等待功能,等待时间到了才会执行,
# 页面上导出几个新的训练参数toml,复制一个此脚本,修改上方toml名字,
# 删除下一行的#井号,修改等待秒数7200为N乘以3600秒后的值
#Get-Date; Start-Sleep -Seconds 7200; Get-Date

#$config_file = "./config/default.toml"      # config_file | 使用toml文件指定训练参数
#$sample_prompts = "./config/sample_prompts.txt"         # sample_prompts | 采样prompts文件,留空则不启用采样功能

$sdxl = 0        # for sdxl model | SDXL 训练
$multi_gpu = 0       # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用

# ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================

# Activate python venv
.\venv\Scripts\activate

$Env:HF_HOME = "huggingface"
$Env:PYTHONUTF8 = 1

$ext_args = [System.Collections.ArrayList]::new()
$launch_args = [System.Collections.ArrayList]::new()

if ($multi_gpu) {
  [void]$launch_args.Add("--multi_gpu")
}
if ($sdxl) {
  [void]$launch_args.Add("--sdxl")
}

for ($i = 0; $i -lt $my_batch_tomls.Length; ++$i) {
    Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train start$($i+1): $($my_batch_tomls[$i])"
    # run train
    $script_name = if ($sdxl) { "sdxl_train_network.py" } else { "train_network.py" }
    python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/$script_name" `
      --config_file=$($my_batch_tomls[$i]) `
      #--sample_prompts=$sample_prompts `
      $ext_args

    Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train finished$($i+1): $($my_batch_tomls[$i])"
}

Write-Output "Train finished"
Read-Host | Out-Null
dahuzi773 commented 11 months ago

简单改了下train_by_toml.ps1,可以按配置批量炼丹,把下面代码复制到记事本保存,后缀改成ps1,放到根目录

# LoRA train script by @Akegarasu

# 批量配置文件,每行以逗号结尾,最后一行不要逗号
# 若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1
# 若想看图表可执行:tensorboard.ps1
[string[]]$my_batch_tomls=(
"./toml/批次1.toml",
"./toml/批次2.toml",
"./toml/批次3.toml"
)

$multi_gpu = 0         # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
#$config_file = "./toml/default.toml"      # config_file | 使用toml文件指定训练参数
#$sample_prompts = "./toml/sample_prompts.txt"         # sample_prompts | 采样prompts文件,留空则不启用采样功能
$utf8 = 1      # utf8 | 使用utf-8编码读取toml;以utf-8编码编写的、含中文的toml必须开启

# ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================

# Activate python venv
.\venv\Scripts\activate

$Env:HF_HOME = "huggingface"

$ext_args = [System.Collections.ArrayList]::new()
$launch_args = [System.Collections.ArrayList]::new()

if ($multi_gpu) {
  [void]$launch_args.Add("--multi_gpu")
}
if ($utf8 -eq 1) {
  $Env:PYTHONUTF8 = 1
}

for ($i = 0; $i -lt $my_batch_tomls.Length; ++$i) {
  Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train start$($i+1): $($my_batch_tomls[$i])"
  # run train
  python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
  --config_file=$($my_batch_tomls[$i]) `
  #--sample_prompts=$sample_prompts `
  $ext_args

  Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train finished$($i+1): $($my_batch_tomls[$i])"
}

Read-Host | Out-Null ;

请问下这个ps1是直接用powershell运行吗?我运行总是提示.\venv\Scripts\activate不存在,确实根目录里也没这个venv虚拟环境

cindylaii commented 7 months ago

简单改了下train_by_toml.ps1,可以按配置批量炼丹,把下面代码复制到记事本保存,后缀改成ps1,放到根目录

# LoRA train script by @Akegarasu

# 批量配置文件,每行以逗号结尾,最后一行不要逗号
# 若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1
# 若想看图表可执行:tensorboard.ps1
[string[]]$my_batch_tomls=(
"./toml/批次1.toml",
"./toml/批次2.toml",
"./toml/批次3.toml"
)

$multi_gpu = 0       # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
#$config_file = "./toml/default.toml"        # config_file | 使用toml文件指定训练参数
#$sample_prompts = "./toml/sample_prompts.txt"       # sample_prompts | 采样prompts文件,留空则不启用采样功能
$utf8 = 1        # utf8 | 使用utf-8编码读取toml;以utf-8编码编写的、含中文的toml必须开启

# ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================

# Activate python venv
.\venv\Scripts\activate

$Env:HF_HOME = "huggingface"

$ext_args = [System.Collections.ArrayList]::new()
$launch_args = [System.Collections.ArrayList]::new()

if ($multi_gpu) {
  [void]$launch_args.Add("--multi_gpu")
}
if ($utf8 -eq 1) {
  $Env:PYTHONUTF8 = 1
}

for ($i = 0; $i -lt $my_batch_tomls.Length; ++$i) {
    Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train start$($i+1): $($my_batch_tomls[$i])"
    # run train
    python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
    --config_file=$($my_batch_tomls[$i]) `
    #--sample_prompts=$sample_prompts `
    $ext_args

    Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train finished$($i+1): $($my_batch_tomls[$i])"
}

Read-Host | Out-Null ;

请问下这个ps1是直接用powershell运行吗?我运行总是提示.\venv\Scripts\activate不存在,确实根目录里也没这个venv虚拟环境

請參考原文:若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1 我不在中國,我使用 install.ps1裝完環境,然後再執行上面大大寫的xxx.ps1,可執行但是後面還是有問題

wakening commented 7 months ago

简单改了下train_by_toml.ps1,可以按配置批量炼丹,把下面代码复制到记事本保存,后缀改成ps1,放到根目录

# LoRA train script by @Akegarasu

# 批量配置文件,每行以逗号结尾,最后一行不要逗号
# 若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1
# 若想看图表可执行:tensorboard.ps1
[string[]]$my_batch_tomls=(
"./toml/批次1.toml",
"./toml/批次2.toml",
"./toml/批次3.toml"
)

$multi_gpu = 0         # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
#$config_file = "./toml/default.toml"      # config_file | 使用toml文件指定训练参数
#$sample_prompts = "./toml/sample_prompts.txt"         # sample_prompts | 采样prompts文件,留空则不启用采样功能
$utf8 = 1      # utf8 | 使用utf-8编码读取toml;以utf-8编码编写的、含中文的toml必须开启

# ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================

# Activate python venv
.\venv\Scripts\activate

$Env:HF_HOME = "huggingface"

$ext_args = [System.Collections.ArrayList]::new()
$launch_args = [System.Collections.ArrayList]::new()

if ($multi_gpu) {
  [void]$launch_args.Add("--multi_gpu")
}
if ($utf8 -eq 1) {
  $Env:PYTHONUTF8 = 1
}

for ($i = 0; $i -lt $my_batch_tomls.Length; ++$i) {
  Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train start$($i+1): $($my_batch_tomls[$i])"
  # run train
  python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
  --config_file=$($my_batch_tomls[$i]) `
  #--sample_prompts=$sample_prompts `
  $ext_args

  Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train finished$($i+1): $($my_batch_tomls[$i])"
}

Read-Host | Out-Null ;

请问下这个ps1是直接用powershell运行吗?我运行总是提示.\venv\Scripts\activate不存在,确实根目录里也没这个venv虚拟环境

請參考原文:若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1 我不在中國,我使用 install.ps1裝完環境,然後再執行上面大大寫的xxx.ps1,可執行但是後面還是有問題

已更新适配新版

cindylaii commented 7 months ago

简单改了下train_by_toml.ps1,可以按配置批量炼丹,把下面代码复制到记事本保存,后缀改成ps1,放到根目录

# LoRA train script by @Akegarasu

# 批量配置文件,每行以逗号结尾,最后一行不要逗号
# 若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1
# 若想看图表可执行:tensorboard.ps1
[string[]]$my_batch_tomls=(
"./toml/批次1.toml",
"./toml/批次2.toml",
"./toml/批次3.toml"
)

$multi_gpu = 0       # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
#$config_file = "./toml/default.toml"        # config_file | 使用toml文件指定训练参数
#$sample_prompts = "./toml/sample_prompts.txt"       # sample_prompts | 采样prompts文件,留空则不启用采样功能
$utf8 = 1        # utf8 | 使用utf-8编码读取toml;以utf-8编码编写的、含中文的toml必须开启

# ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================

# Activate python venv
.\venv\Scripts\activate

$Env:HF_HOME = "huggingface"

$ext_args = [System.Collections.ArrayList]::new()
$launch_args = [System.Collections.ArrayList]::new()

if ($multi_gpu) {
  [void]$launch_args.Add("--multi_gpu")
}
if ($utf8 -eq 1) {
  $Env:PYTHONUTF8 = 1
}

for ($i = 0; $i -lt $my_batch_tomls.Length; ++$i) {
    Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train start$($i+1): $($my_batch_tomls[$i])"
    # run train
    python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
    --config_file=$($my_batch_tomls[$i]) `
    #--sample_prompts=$sample_prompts `
    $ext_args

    Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train finished$($i+1): $($my_batch_tomls[$i])"
}

Read-Host | Out-Null ;

请问下这个ps1是直接用powershell运行吗?我运行总是提示.\venv\Scripts\activate不存在,确实根目录里也没这个venv虚拟环境

請參考原文:若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1 我不在中國,我使用 install.ps1裝完環境,然後再執行上面大大寫的xxx.ps1,可執行但是後面還是有問題

已更新适配新版

非常感謝你快速的回覆,我剛才試仍有錯誤。 我仔細想了一下先試一下內建的程式, 發現"train_by_toml.ps1"都不能用,錯誤如下。所以是我這裡環境的問題。 但是我用GUI一切正常,我這兩週練了5個LORA,今天凌晨也剛用GUI練完一個。 目前打算再開一個資料夾全部重裝試試。

2024-03-17 08:53:02 INFO loading u-net: model_util.py:1009 2024-03-17 08:53:03 INFO loading vae: model_util.py:1017 2024-03-17 08:53:04 INFO loading text encoder: model_util.py:1074 2024-03-17 08:53:05 INFO Enable xformers for U-Net train_util.py:2577 Traceback (most recent call last): File "D:\StableDiffusion\lora-scripts-gui\sd-scripts\train_network.py", line 1063, in trainer.train(args) File "D:\StableDiffusion\lora-scripts-gui\sd-scripts\train_network.py", line 243, in train vae.set_use_memory_efficient_attention_xformers(args.xformers) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 262, in set_use_memory_efficient_attention_xformers fn_recursive_set_mem_eff(module) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 258, in fn_recursive_set_mem_eff fn_recursive_set_mem_eff(child) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 258, in fn_recursive_set_mem_eff fn_recursive_set_mem_eff(child) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 258, in fn_recursive_set_mem_eff fn_recursive_set_mem_eff(child) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 255, in fn_recursive_set_mem_eff module.set_use_memory_efficient_attention_xformers(valid, attention_op) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\attention_processor.py", line 273, in set_use_memory_efficient_attention_xformers raise e File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\attention_processor.py", line 267, in set_use_memory_efficient_attentionxformers = xformers.ops.memory_efficient_attention( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha__init.py", line 247, in memory_efficient_attention return _memory_efficient_attention( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha__init__.py", line 365, in _memory_efficient_attention return _memory_efficient_attention_forward( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha\init__.py", line 381, in _memory_efficient_attention_forward op = _dispatch_fw(inp, False) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha\dispatch.py", line 125, in _dispatch_fw return _run_priority_list( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha\dispatch.py", line 65, in _run_priority_list raise NotImplementedError(msg) NotImplementedError: No operator found for memory_efficient_attention_forward with inputs: query : shape=(1, 2, 1, 40) (torch.float32) key : shape=(1, 2, 1, 40) (torch.float32) value : shape=(1, 2, 1, 40) (torch.float32) attn_bias : <class 'NoneType'> p : 0.0 decoderF is not supported because: xFormers wasn't build with CUDA support attn_bias type is <class 'NoneType'> operator wasn't built - see python -m xformers.info for more info flshattF@0.0.0 is not supported because: xFormers wasn't build with CUDA support dtype=torch.float32 (supported: {torch.bfloat16, torch.float16}) operator wasn't built - see python -m xformers.info for more info cutlassF is not supported because: xFormers wasn't build with CUDA support operator wasn't built - see python -m xformers.info for more info smallkF is not supported because: max(query.shape[-1] != value.shape[-1]) > 32 xFormers wasn't build with CUDA support operator wasn't built - see python -m xformers.info for more info unsupported embed per head: 40 Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 1027, in main() File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 1023, in main launch_command(args) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 1017, in launch_command simple_launcher(args) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 637, in simple_launcher raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd) subprocess.CalledProcessError: Command '['D:\StableDiffusion\lora-scripts-gui\venv\Scripts\python.exe', './sd-scripts/train_network.py', '--config_file=./toml/batch_2.toml', '--sample_prompts=./config/sample_prompts.txt']' returned non-zero exit status 1. Train finished

cindylaii commented 7 months ago

放棄了...一早起來重裝環境就是裝不起來, CUDA也裝了,也照網友說的用release 1.8.3,還是不能訓練..暈

create LoRA for Text Encoder: create LoRA for Text Encoder: 72 modules. create LoRA for U-Net: 192 modules. enable LoRA for text encoder enable LoRA for U-Net prepare optimizer, data loader etc. Traceback (most recent call last): File "D:\StableDiffusion\lora-scripts-1.8.3\sd-scripts\train_network.py", line 996, in trainer.train(args) File "D:\StableDiffusion\lora-scripts-1.8.3\sd-scripts\train_network.py", line 348, in train optimizer_name, optimizer_args, optimizer = train_util.get_optimizer(args, trainable_params) File "D:\StableDiffusion\lora-scripts-1.8.3\sd-scripts\library\train_util.py", line 3491, in get_optimizer import bitsandbytes as bnb File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\bitsandbytes__init.py", line 16, in from .nn import modules File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\bitsandbytes\nn__init__.py", line 17, in from .triton_based_modules import ( File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\bitsandbytes\nn\triton_based_modules.py", line 6, in from bitsandbytes.triton.dequantize_rowwise import dequantize_rowwise File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\bitsandbytes\triton\dequantize_rowwise.py", line 11, in import triton File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\init.py", line 13, in from . import language File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\language\init.py", line 2, in from . import core, extern, libdevice, random File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\language\core.py", line 1141, in def abs(x): File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\runtime\jit.py", line 386, in jit return JITFunction(args[0], **kwargs) File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\runtime\jit.py", line 315, in init self.run = self._make_launcher() File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\runtime\jit.py", line 282, in _make_launcher scope = {"version_key": version_key(), "get_cuda_stream": get_cuda_stream, File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\triton\runtime\jit.py", line 82, in version_key with open(triton._C.libtriton.file__, "rb") as f: AttributeError: partially initialized module 'triton' has no attribute '_C' (most likely due to a circular import) Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\accelerate\commands\launch.py", line 1027, in main() File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\accelerate\commands\launch.py", line 1023, in main launch_command(args) File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\accelerate\commands\launch.py", line 1017, in launch_command simple_launcher(args) File "D:\StableDiffusion\lora-scripts-1.8.3\venv\lib\site-packages\accelerate\commands\launch.py", line 637, in simple_launcher raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd) subprocess.CalledProcessError: Command '['D:\StableDiffusion\lora-scripts-1.8.3\venv\Scripts\python.exe', './sd-scripts/train_network.py', '--config_file=./toml/batch_2.toml', '--sample_prompts=./config/sample_prompts.txt']' returned non-zero exit status 1. Train finished

wakening commented 7 months ago

简单改了下train_by_toml.ps1,可以按配置批量炼丹,把下面代码复制到记事本保存,后缀改成ps1,放到根目录

# LoRA train script by @Akegarasu

# 批量配置文件,每行以逗号结尾,最后一行不要逗号
# 若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1
# 若想看图表可执行:tensorboard.ps1
[string[]]$my_batch_tomls=(
"./toml/批次1.toml",
"./toml/批次2.toml",
"./toml/批次3.toml"
)

$multi_gpu = 0         # multi gpu | 多显卡训练 该参数仅限在显卡数 >= 2 使用
#$config_file = "./toml/default.toml"      # config_file | 使用toml文件指定训练参数
#$sample_prompts = "./toml/sample_prompts.txt"         # sample_prompts | 采样prompts文件,留空则不启用采样功能
$utf8 = 1      # utf8 | 使用utf-8编码读取toml;以utf-8编码编写的、含中文的toml必须开启

# ============= DO NOT MODIFY CONTENTS BELOW | 请勿修改下方内容 =====================

# Activate python venv
.\venv\Scripts\activate

$Env:HF_HOME = "huggingface"

$ext_args = [System.Collections.ArrayList]::new()
$launch_args = [System.Collections.ArrayList]::new()

if ($multi_gpu) {
  [void]$launch_args.Add("--multi_gpu")
}
if ($utf8 -eq 1) {
  $Env:PYTHONUTF8 = 1
}

for ($i = 0; $i -lt $my_batch_tomls.Length; ++$i) {
  Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train start$($i+1): $($my_batch_tomls[$i])"
  # run train
  python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=8 "./sd-scripts/train_network.py" `
  --config_file=$($my_batch_tomls[$i]) `
  #--sample_prompts=$sample_prompts `
  $ext_args

  Write-Output "$((Get-Date).ToString("yyyy:MM:dd HH:mm:ss"))  Train finished$($i+1): $($my_batch_tomls[$i])"
}

Read-Host | Out-Null ;

请问下这个ps1是直接用powershell运行吗?我运行总是提示.\venv\Scripts\activate不存在,确实根目录里也没这个venv虚拟环境

請參考原文:若报错先分别执行:A强制更新-国内加速.bat install-cn.ps1 我不在中國,我使用 install.ps1裝完環境,然後再執行上面大大寫的xxx.ps1,可執行但是後面還是有問題

已更新适配新版

非常感謝你快速的回覆,我剛才試仍有錯誤。 我仔細想了一下先試一下內建的程式, 發現"train_by_toml.ps1"都不能用,錯誤如下。所以是我這裡環境的問題。 但是我用GUI一切正常,我這兩週練了5個LORA,今天凌晨也剛用GUI練完一個。 目前打算再開一個資料夾全部重裝試試。

2024-03-17 08:53:02 INFO loading u-net: model_util.py:1009 2024-03-17 08:53:03 INFO loading vae: model_util.py:1017 2024-03-17 08:53:04 INFO loading text encoder: model_util.py:1074 2024-03-17 08:53:05 INFO Enable xformers for U-Net train_util.py:2577 Traceback (most recent call last): File "D:\StableDiffusion\lora-scripts-gui\sd-scripts\train_network.py", line 1063, in trainer.train(args) File "D:\StableDiffusion\lora-scripts-gui\sd-scripts\train_network.py", line 243, in train vae.set_use_memory_efficient_attention_xformers(args.xformers) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 262, in set_use_memory_efficient_attention_xformers fn_recursive_set_mem_eff(module) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 258, in fn_recursive_set_mem_eff fn_recursive_set_mem_eff(child) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 258, in fn_recursive_set_mem_eff fn_recursive_set_mem_eff(child) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 258, in fn_recursive_set_mem_eff fn_recursive_set_mem_eff(child) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\modeling_utils.py", line 255, in fn_recursive_set_mem_eff module.set_use_memory_efficient_attention_xformers(valid, attention_op) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\attention_processor.py", line 273, in set_use_memory_efficient_attention_xformers raise e File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\diffusers\models\attention_processor.py", line 267, in set_use_memory_efficient_attentionxformers = xformers.ops.memory_efficient_attention( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmhainit.py", line 247, in memory_efficient_attention return _memory_efficient_attention( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmhainit.py", line 365, in _memory_efficient_attention return _memory_efficient_attention_forward( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmhainit.py", line 381, in _memory_efficient_attention_forward op = _dispatch_fw(inp, False) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha\dispatch.py", line 125, in _dispatch_fw return _run_priority_list( File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\xformers\ops\fmha\dispatch.py", line 65, in _run_priority_list raise NotImplementedError(msg) NotImplementedError: No operator found for memory_efficient_attention_forward with inputs: query : shape=(1, 2, 1, 40) (torch.float32) key : shape=(1, 2, 1, 40) (torch.float32) value : shape=(1, 2, 1, 40) (torch.float32) attn_bias : <class 'NoneType'> p : 0.0 decoderF is not supported because: xFormers wasn't build with CUDA support attn_bias type is <class 'NoneType'> operator wasn't built - see python -m xformers.info for more info flshattF@0.0.0 is not supported because: xFormers wasn't build with CUDA support dtype=torch.float32 (supported: {torch.bfloat16, torch.float16}) operator wasn't built - see python -m xformers.info for more info cutlassF is not supported because: xFormers wasn't build with CUDA support operator wasn't built - see python -m xformers.info for more info smallkF is not supported because: max(query.shape[-1] != value.shape[-1]) > 32 xFormers wasn't build with CUDA support operator wasn't built - see python -m xformers.info for more info unsupported embed per head: 40 Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 1027, in main() File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 1023, in main launch_command(args) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 1017, in launch_command simple_launcher(args) File "D:\StableDiffusion\lora-scripts-gui\venv\lib\site-packages\accelerate\commands\launch.py", line 637, in simple_launcher raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd) subprocess.CalledProcessError: Command '['D:\StableDiffusion\lora-scripts-gui\venv\Scripts\python.exe', './sd-scripts/train_network.py', '--config_file=./toml/batch_2.toml', '--sample_prompts=./config/sample_prompts.txt']' returned non-zero exit status 1. Train finished

此版本为基础,先确认已执行 A强制更新.bat 和 install.ps1; 看日志是xFormers有问题,在页面 专家 -速度优化选项下关闭xFormers; 再重新跑一遍,提供启动到报错的完整日志和toml

cindylaii commented 7 months ago

此版本为基础,先确认已执行 A强制更新.bat 和 install.ps1; 看日志是xFormers有问题,在页面 专家 -速度优化选项下关闭xFormers; 再重新跑一遍,提供启动到报错的完整日志和toml

成功了,您的程式很好。很感謝您的幫忙。這樣我以後可以一次排程練3個。放一個晚上就好了。

是我對安裝不太熟。 寫一下我的流程:

我的環境Windows 11, RTX4080 Laptop

1) 安裝CUDA 11.8 2) 下載秋葉訓練器(lora-scripts) release版1.8.3 2) 在Windows裡要用管理員權限打開Powershell 輸入Set-ExecutionPolicy RemoteSigned 執行.\install.ps1

安裝好後,再試script .\train_by_toml_new_cindy_2_lora.ps1 (即您的程式..我放2個照片集訓練)

若不能用,試一下.\run_gui.ps1 訓練,我用GUI訓練是正常的。 再回到Powershell試.\train_by_toml_new_cindy_2_lora.ps1 (即您的程式..我放2個照片集訓練)

就可以用了,可掛上多個toml訓練 看起來是正常的

cindylaii commented 7 months ago

我今天試還是有問題..一樣是gui能用,script不能用.. 抱歉上面的留言可能沒什麼幫助..

cindylaii commented 7 months ago

剛才的大發現,train.ps1我能用 但是train_by_toml.ps1不能用。 如果我在train_by_toml.ps1裡加一行 $Env:XFORMERS_FORCE_DISABLE_TRITON = "1" 就可以用了。我不知道這有什麼影響。

zk495539792 commented 1 week ago

请问连续训练成功了?训练的是flux lora吗? 如果成功了可以分享下流程? @cindylaii

cindylaii commented 1 week ago

連續訓練成功,但是我是用在SD 1.5,沒試過Flux。

zk495539792 commented 1 week ago

連續訓練成功,但是我是用在SD 1.5,沒試過Flux。

那请问你的.\train_by_toml_new_cindy_2_lora.ps1是怎么编写的?

cindylaii commented 1 week ago

連續訓練成功,但是我是用在SD 1.5,沒試過Flux。

那请问你的.\train_by_toml_new_cindy_2_lora.ps1是怎么编写的?

請照下面先試試,我試是可以用的。

https://github.com/Akegarasu/lora-scripts/issues/40#issuecomment-1684038447

zk495539792 commented 1 week ago

連續訓練成功,但是我是用在SD 1.5,沒試過Flux。

那请问你的.\train_by_toml_new_cindy_2_lora.ps1是怎么编写的?

請照下面先試試,我試是可以用的。

#40 (comment)

好的,非常感谢,我尝试下,如果能连续训练flux的话就太棒了

zk495539792 commented 1 week ago

連續訓練成功,但是我是用在SD 1.5,沒試過Flux。

那请问你的.\train_by_toml_new_cindy_2_lora.ps1是怎么编写的?

請照下面先試試,我試是可以用的。

#40 (comment)

我试了一下,出现以下报错:2024:10:10 14:08:29 Train start1: ./toml/批次1.toml H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\diffusers\utils\outputs.py:63: FutureWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. torch.utils._pytree._register_pytree_node( H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\xformers\ops\fmha\flash.py:211: FutureWarning: torch.library.impl_abstract was renamed to torch.library.register_fake. Please use that instead; we will remove torch.library.impl_abstract in a future version of PyTorch. @torch.library.impl_abstract("xformers_flash::flash_fwd") H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\xformers\ops\fmha\flash.py:344: FutureWarning: torch.library.impl_abstract was renamed to torch.library.register_fake. Please use that instead; we will remove torch.library.impl_abstract in a future version of PyTorch. @torch.library.impl_abstract("xformers_flash::flash_bwd") 2024-10-10 14:08:48 WARNING A matching Triton is not available, some optimizations will not be enabled init.py:61 Traceback (most recent call last): File "H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\xformers__init__.py", line 57, in _is_triton_available import triton # noqa ^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'triton' H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\diffusers\utils\outputs.py:63: FutureWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. torch.utils._pytree._register_pytree_node( INFO Loading settings from ./toml/批次1.toml... train_util.py:4189 INFO ./toml/批次1 train_util.py:4208 2024-10-10 14:08:48 INFO Using v1 tokenizer strategy_sd.py:26 H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\transformers\tokenization_utils_base.py:1601: FutureWarning: clean_up_tokenization_spaces was not set. It will be set to True by default. This behavior will be depracted in transformers v4.45, and will be then set to False by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884 warnings.warn( 2024-10-10 14:08:49 INFO Using DreamBooth method. train_network.py:279 INFO prepare images. train_util.py:1803 INFO 0 train images with repeating. train_util.py:1844 INFO 0 reg images. train_util.py:1847 WARNING no regularization images / 正則化画像が見つかりませんでした train_util.py:1852 INFO [Dataset 0] config_util.py:570 batch_size: 1 resolution: (512, 512) enable_bucket: False network_multiplier: 1.0

                INFO     [Dataset 0]                                                              config_util.py:576
                INFO     loading image sizes.                                                      train_util.py:876

0it [00:00, ?it/s] INFO make buckets train_util.py:882 WARNING min_bucket_reso and max_bucket_reso are ignored if bucket_no_upscale is train_util.py:899 set, because bucket reso is defined by image size automatically / bucket_no_upscaleが指定された場合は、bucketの解像度は画像サイズから自動計 算されるため、min_bucket_resoとmax_bucket_resoは無視されます INFO number of images (including repeats) / train_util.py:928 各bucketの画像枚数(繰り返し回数を含む) H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\numpy\core\fromnumeric.py:3504: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\numpy\core_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide ret = ret.dtype.type(ret / rcount) INFO mean ar error (without repeats): nan train_util.py:938 ERROR No data found. Please verify arguments (train_data_dir must be the train_network.py:320 parent of folders with images) / 画像がありません。引数指定を確認してください(train_data_dirには画像が あるフォルダではなく、画像があるフォルダの親フォルダを指定する必要があ ります) 2024:10:10 14:08:50 Train finished1: ./toml/批次1.toml 2024:10:10 14:08:50 Train start2: ./toml/批次2.toml H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\diffusers\utils\outputs.py:63: FutureWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. torch.utils._pytree._register_pytree_node( H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\xformers\ops\fmha\flash.py:211: FutureWarning: torch.library.impl_abstract was renamed to torch.library.register_fake. Please use that instead; we will remove torch.library.impl_abstract in a future version of PyTorch. @torch.library.impl_abstract("xformers_flash::flash_fwd") H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\xformers\ops\fmha\flash.py:344: FutureWarning: torch.library.impl_abstract was renamed to torch.library.register_fake. Please use that instead; we will remove torch.library.impl_abstract in a future version of PyTorch. @torch.library.impl_abstract("xformers_flash::flash_bwd") 2024-10-10 14:09:08 WARNING A matching Triton is not available, some optimizations will not be enabled init.py:61 Traceback (most recent call last): File "H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\xformers__init__.py", line 57, in _is_triton_available import triton # noqa ^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'triton' H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\diffusers\utils\outputs.py:63: FutureWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. torch.utils._pytree._register_pytree_node( 2024-10-10 14:09:09 INFO Loading settings from ./toml/批次2.toml... train_util.py:4189 INFO ./toml/批次2 train_util.py:4208 2024-10-10 14:09:09 INFO Using v1 tokenizer strategy_sd.py:26 H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\transformers\tokenization_utils_base.py:1601: FutureWarning: clean_up_tokenization_spaces was not set. It will be set to True by default. This behavior will be depracted in transformers v4.45, and will be then set to False by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884 warnings.warn( INFO Using DreamBooth method. train_network.py:279 INFO prepare images. train_util.py:1803 INFO 0 train images with repeating. train_util.py:1844 INFO 0 reg images. train_util.py:1847 WARNING no regularization images / 正則化画像が見つかりませんでした train_util.py:1852 INFO [Dataset 0] config_util.py:570 batch_size: 1 resolution: (512, 512) enable_bucket: False network_multiplier: 1.0

                INFO     [Dataset 0]                                                              config_util.py:576
                INFO     loading image sizes.                                                      train_util.py:876

0it [00:00, ?it/s] INFO make buckets train_util.py:882 WARNING min_bucket_reso and max_bucket_reso are ignored if bucket_no_upscale is train_util.py:899 set, because bucket reso is defined by image size automatically / bucket_no_upscaleが指定された場合は、bucketの解像度は画像サイズから自動計 算されるため、min_bucket_resoとmax_bucket_resoは無視されます INFO number of images (including repeats) / train_util.py:928 各bucketの画像枚数(繰り返し回数を含む) H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\numpy\core\fromnumeric.py:3504: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, H:\00Alchemy furnace\lora-scripts\venv\Lib\site-packages\numpy\core_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide ret = ret.dtype.type(ret / rcount) INFO mean ar error (without repeats): nan train_util.py:938 ERROR No data found. Please verify arguments (train_data_dir must be the train_network.py:320 parent of folders with images) / 画像がありません。引数指定を確認してください(train_data_dirには画像が あるフォルダではなく、画像があるフォルダの親フォルダを指定する必要があ ります) 2024:10:10 14:09:11 Train finished2: ./toml/批次2.toml

wakening commented 1 week ago

先跑通官方脚本train_by_toml.ps1,再仔细阅读此脚本内的中文 @zk495539792

zk495539792 commented 1 week ago

先跑通官方脚本train_by_toml.ps1,再仔细阅读此脚本内的中文 @zk495539792

好的,但我目测此脚本也许是只适用于SD1.5/SDXL,查看调用的参数是这两个的,因为FLUX训练逻辑与SD1.5/SDXL存在根本都不同,所以并不太适用,因为我目标是用于批量连续训练FLUX LoRA

wakening commented 1 week ago

我没有训练过FLUX,理论上是可以的,页面上训练也是调脚本,你只要知道训练FLUX的命令然后改改就行了

zk495539792 commented 1 week ago

我没有训练过FLUX,理论上是可以的,页面上训练也是调脚本,你只要知道训练FLUX的命令然后改改就行了 没有编程基础,所以之前用GPT O1进行过整理,也发送过部分代码给GPT帮忙分析,甚至试过修改GUI将训练过程中调用的文件都存为TXT,但还是找到脚本。

1.A启动脚本.bat(位于 根目录下):使用目录内的 Python 解释器启动 SD-Trainer Mikazuki GUI。于启动整个训练应用程序的批处理脚本。它设置环境并启动主GUI或服务器应用程序。这个批处理脚本用于启动整个训练应用程序,具体来说,它运行了gui.py,也就是启动了图形用户界面(GUI)。

2.gui.py(位于 根目录下): 是应用程序的入口,启动了 Web 服务器,提供 GUI 界面供用户配置和管理训练任务,并启动了辅助服务(标签编辑器和 TensorBoard)。

3.flux_train_network.py(位于 .\scripts 目录下):用于训练 Flux LoRA 模型的主脚本。个脚本负责处理 Flux 模型训练所需的特定配置和流程,包括模型加载、数据处理、训练循环等。文件作用:flux_train_network.py 是 Flux LoRA 模型训练的主脚本,定义了 FluxNetworkTrainer 类,处理 Flux 模型训练的特定流程。 主要功能: 模型加载和准备:加载 Flux 模型、CLIP-L、T5XXL 和自动编码器,根据配置进行模型分割和数据类型设置。 数据处理和缓存:实现潜变量和文本编码器输出的缓存策略,减少重复计算,提高训练效率。 训练逻辑:定义了训练过程中各个步骤的实现,包括前向传播、损失计算和反向传播。 配置和参数管理:通过命令行参数和配置文件,灵活地控制训练过程中的各种参数。 与训练流程的关联: 继承关系:FluxNetworkTrainer 继承自 train_network.NetworkTrainer,复用了通用的训练流程。 特定实现:针对 Flux 模型的特点,重写了部分方法,如模型加载、前向传播和损失计算等。

4.train_network.py(位于 .\scripts 目录下): 提供用于加载和管理Flux模型组件的函数,如Flux模型本身、CLIP-L、T5XXL和自动编码器(AE)。包含处理模型状态字典、设置模型和任何Flux特定处理的工具。用于训练通用网络模型的主脚本,它提供了一个基类 NetworkTrainer,并定义了训练过程中所需的各种方法和流程。该脚本支持多种模型的训练,包括 Stable Diffusion 相关的模型。flux_train_network.py 继承自这个基类,并针对 Flux 模型进行了定制。 文件作用:train_network.py 是通用的网络训练脚本,提供了基类和通用方法,用于训练各种网络模型。 训练流程: 参数解析和验证:解析命令行参数,验证训练配置。 模型加载和准备:加载预训练模型,准备训练所需的组件。 数据集准备:根据配置加载和处理数据集。 训练循环:在每个 epoch 和步骤中,执行前向传播、损失计算、反向传播和优化。 模型保存和日志记录:定期保存模型检查点,记录训练日志和元数据。 与 Flux LoRA 的关系:flux_train_network.py 继承并扩展了 NetworkTrainer,针对 Flux 模型的特殊需求实现了定制的训练逻辑。

5.train_util.py(位于 .\scripts\library 目录下):包含训练过程中各种实用函数和类的定义。 涉及数据集的定义和管理,包括图像信息的存储、Bucket 管理、数据增强、文本处理和缓存机制等。通过分析,我们可以了解到: ImageInfo 类用于存储单个图像的详细信息,包括路径、文本描述、尺寸等。 BucketManager 类用于根据图像的尺寸和长宽比,将图像分配到不同的 Bucket,以便在训练时批量处理相同尺寸的图像。 AugHelper 类提供了数据增强的功能,目前主要实现了颜色增强。 BaseDataset 类是数据集的基类,实现了数据加载、预处理、缓存和 Bucket 管理等功能。 这些类和方法在训练流程中扮演着关键的角色,确保数据被正确加载、预处理和提供给模型进行训练。 数据集的定义和处理,包括潜变量和文本编码器输出的缓存、数据集的子类实现(如 DreamBoothDataset、FineTuningDataset、ControlNetDataset),以及它们的具体方法。以下是对各个部分的详细分析。 数据集的定义、缓存机制的实现,以及它们在训练流程中的作用。这些组件在整个 Flux LoRA 的训练过程中扮演着关键的角色: 数据加载和预处理:确保模型能够获取到正确且高质量的输入数据。 缓存机制:通过缓存潜变量和文本编码器输出,减少重复计算,提高训练效率。 灵活的扩展性:通过定义不同的子类(如 DreamBoothDataset、FineTuningDataset),可以适应不同的训练需求。 DatasetGroup 类提供了统一管理多个数据集的功能,方便在训练时使用。 缓存机制的辅助函数:提供了检查缓存有效性、加载和保存潜变量和文本编码器输出的方法,确保缓存的数据与预期匹配。 debug_dataset 函数:在训练前调试数据集,确保数据加载和预处理正确。 辅助函数:如图像加载、图像裁剪和调整大小,为数据预处理提供了支持。 MinimalDataset 类:为用户自定义数据集提供了一个模板,可以根据需要进行扩展。 模型模块替换的代码:尽管被注释掉了,但显示了如何通过替换模型的某些部分来提高训练效率。 元数据的定义和处理:定义了一些关键的元数据键,以及用于构建元数据的函数。 命令行参数的添加:提供了多个函数,用于向命令行解析器添加不同的参数组,包括模型参数、优化器参数、训练参数等。 配置文件的读取和参数验证:包含了读取配置文件、验证训练参数的函数,确保训练过程的参数设置正确。 参数管理:通过清晰的参数定义和验证,确保训练过程的可控性和可靠性。 元数据记录:在模型保存时记录重要的元数据信息,有助于模型的管理和再利用。 配置文件支持:提高了训练设置的灵活性,方便用户保存和加载训练配置。 训练恢复和状态管理:支持从本地或远程恢复训练,确保训练的连续性。 优化器和调度器的灵活配置:允许用户根据需要选择和定制优化器和学习率调度器。 数据处理和设备管理:准备数据集参数,初始化加速器和处理数据类型,确保训练过程高效运行。 模型加载和保存:正确加载预训练模型,并在训练过程中和结束时保存模型,支持版本控制和中断恢复。 损失和噪声处理:实现了自定义的损失函数和噪声添加方法,满足不同的训练需求。 日志记录:在训练过程中记录关键参数,方便监控和分析。 调度器的定义和获取:定义了用于采样的调度器,以及获取调度器的函数。 样本图像生成:包括生成样本图像的函数,以及解析和处理提示的函数。 数据预处理:定义了用于加载图像的数据集类,以及用于数据加载的协作者类。 损失记录器:定义了一个用于记录和计算损失的类。 为训练流程提供了重要的辅助功能,特别是在模型的验证、调试和性能监控方面。通过生成样本图像,用户可以直观地观察模型的生成效果;通过调度器的选择和配置,可以影响生成的质量和风格;通过数据预处理,确保了训练数据的质量;通过损失记录器,可以监控模型的训练进展。 参数解析和验证:定义和解析训练所需的命令行参数,支持从配置文件读取参数,并对参数进行验证。 模型加载和保存:提供函数用于加载预训练模型(如 Stable Diffusion 的检查点或 Diffusers 格式的模型),以及在训练过程中和训练结束时保存模型。 优化器和学习率调度器的配置:根据用户提供的参数,初始化适当的优化器和学习率调度器,支持多种优化器类型和调度策略。 数据加载和预处理:定义了数据集类和协作者类,用于加载和预处理训练数据,支持各种数据增强和处理方式。 训练辅助功能:包括损失函数的定义、样本图像的生成、训练状态的保存和恢复等。 日志记录和监控:在训练过程中记录关键的参数和指标,支持 TensorBoard 和 WandB 等日志工具。

6.flux_utils.py(位于 .\scripts\library 目录下):提供了 Flux LoRA 训练和推理中所需的模型加载和数据处理函数。 模型加载功能:确保各种模型(如 Flux、AutoEncoder、CLIP、T5 等)能够正确地构建和加载权重,为训练和推理提供了基础。 数据处理工具:提供了潜变量的打包和解包,以及图像 ID 的准备函数,支持数据在模型中的高效处理。 实用工具函数:通过安全的权重加载和元设备初始化,提供了高效的内存管理和模型加载方式。 模型加载:flux_utils.py 提供了加载各种模型的函数,包括 Flux 模型、自动编码器、CLIP 和 T5 编码器。这些模型在训练和推理过程中是核心组件,确保它们正确加载对于模型的性能和稳定性至关重要。 数据处理:提供的打包和解包潜变量的函数,以及图像 ID 的准备函数,确保了数据在模型中的正确流动和处理。这对于模型的训练效率和生成质量都有重要影响。 工具支持:通过安全地加载权重文件和在元设备上初始化模型,flux_utils.py 提供了高效和安全的模型加载方式,避免了内存溢出等问题,提高了训练的稳定性。

7.lora_flux.py(位于 .\scripts\networks 目录下):主要实现了 Flux LoRA 模型的核心功能,具体包括: LoRA 模块的定义:实现了用于替换原始模型中线性层或卷积层的 LoRA 模块,支持训练和推理两种模式。 LoRA 网络的构建:提供了创建 LoRA 网络的函数,包括从零开始创建网络,以及从已有的权重文件加载网络。 LoRA 网络的核心类 LoRANetwork:负责将 LoRA 模块应用到模型的各个部分,包括文本编码器和 Flux 模型,管理 LoRA 模块的训练、加载和保存。 辅助函数和工具:包括一些实用函数,用于配置和管理 LoRA 网络的行为,如设置学习率、梯度检查点等。 LoRA 模块的核心实现:LoRAModule 和 LoRAInfModule 定义了 LoRA 模块的具体实现,包括训练和推理阶段的行为。 LoRA 网络的管理:LoRANetwork 类负责将 LoRA 模块应用到模型的各个部分,管理 LoRA 模块的加载、保存和训练过程。 模型的扩展和定制:通过 create_network 和 create_network_from_weights 函数,可以根据需要创建和加载 LoRA 网络,支持各种自定义配置。 训练过程中的支持:提供了参数组的准备、学习率的设置、权重的备份和恢复等功能,支持训练过程的顺利进行。 推理过程的优化:通过权重的合并和预计算,可以在推理阶段加速模型的运行,减少计算开销。 LoRA 模块的具体实现:定义了如何在模型的线性层和卷积层中应用 LoRA,实现参数高效的微调。 LoRA 网络的构建和管理:提供了创建、加载和应用 LoRA 网络的函数和类,支持对模型的扩展和定制。 训练和推理的支持功能:包括权重的加载和保存、优化器参数的配置、权重的备份和恢复等,确保训练和推理过程的高效和稳定。

zk495539792 commented 1 week ago

我没有训练过FLUX,理论上是可以的,页面上训练也是调脚本,你只要知道训练FLUX的命令然后改改就行了

问题存在于对图像的处理和调用lux模型本身、CLIP-L、T5XXL和自动编码器(AE)。包含处理模型状态字典、设置模型和任何Flux特定处理的工具