|
|
|
|
|
|
|
$pretrained_model = "./sd-models/model.ckpt" |
|
$model_type = "sd1.5" |
|
$parameterization = 0 |
|
|
|
$train_data_dir = "./train/aki" |
|
$reg_data_dir = "" |
|
|
|
|
|
$network_module = "networks.lora" |
|
$network_weights = "" |
|
$network_dim = 32 |
|
$network_alpha = 32 |
|
|
|
|
|
$resolution = "512,512" |
|
$batch_size = 1 |
|
$max_train_epoches = 10 |
|
$save_every_n_epochs = 2 |
|
|
|
$train_unet_only = 0 |
|
$train_text_encoder_only = 0 |
|
$stop_text_encoder_training = 0 |
|
|
|
$noise_offset = 0 |
|
$keep_tokens = 0 |
|
$min_snr_gamma = 0 |
|
|
|
|
|
$lr = "1e-4" |
|
$unet_lr = "1e-4" |
|
$text_encoder_lr = "1e-5" |
|
$lr_scheduler = "cosine_with_restarts" |
|
$lr_warmup_steps = 0 |
|
$lr_restart_cycles = 1 |
|
|
|
|
|
$optimizer_type = "AdamW8bit" |
|
|
|
|
|
$output_name = "aki" |
|
$save_model_as = "safetensors" |
|
|
|
|
|
$save_state = 0 |
|
$resume = "" |
|
|
|
|
|
$min_bucket_reso = 256 |
|
$max_bucket_reso = 1024 |
|
$persistent_data_loader_workers = 1 |
|
$clip_skip = 2 |
|
$multi_gpu = 0 |
|
$lowram = 0 |
|
|
|
|
|
$algo = "lora" |
|
$conv_dim = 4 |
|
$conv_alpha = 4 |
|
$dropout = "0" |
|
|
|
|
|
$use_wandb = 0 |
|
$wandb_api_key = "" |
|
$log_tracker_name = "" |
|
|
|
|
|
|
|
.\venv\Scripts\activate |
|
|
|
$Env:HF_HOME = "huggingface" |
|
$Env:XFORMERS_FORCE_DISABLE_TRITON = "1" |
|
$ext_args = [System.Collections.ArrayList]::new() |
|
$launch_args = [System.Collections.ArrayList]::new() |
|
|
|
$trainer_file = "./scripts/train_network.py" |
|
|
|
if ($model_type -eq "sd1.5") { |
|
[void]$ext_args.Add("--clip_skip=$clip_skip") |
|
} elseif ($model_type -eq "sd2.0") { |
|
[void]$ext_args.Add("--v2") |
|
} elseif ($model_type -eq "sdxl") { |
|
$trainer_file = "./scripts/sdxl_train_network.py" |
|
} |
|
|
|
if ($multi_gpu) { |
|
[void]$launch_args.Add("--multi_gpu") |
|
[void]$launch_args.Add("--num_processes=2") |
|
} |
|
|
|
if ($lowram) { |
|
[void]$ext_args.Add("--lowram") |
|
} |
|
|
|
if ($parameterization) { |
|
[void]$ext_args.Add("--v_parameterization") |
|
} |
|
|
|
if ($train_unet_only) { |
|
[void]$ext_args.Add("--network_train_unet_only") |
|
} |
|
|
|
if ($train_text_encoder_only) { |
|
[void]$ext_args.Add("--network_train_text_encoder_only") |
|
} |
|
|
|
if ($network_weights) { |
|
[void]$ext_args.Add("--network_weights=" + $network_weights) |
|
} |
|
|
|
if ($reg_data_dir) { |
|
[void]$ext_args.Add("--reg_data_dir=" + $reg_data_dir) |
|
} |
|
|
|
if ($optimizer_type) { |
|
[void]$ext_args.Add("--optimizer_type=" + $optimizer_type) |
|
} |
|
|
|
if ($optimizer_type -eq "DAdaptation") { |
|
[void]$ext_args.Add("--optimizer_args") |
|
[void]$ext_args.Add("decouple=True") |
|
} |
|
|
|
if ($network_module -eq "lycoris.kohya") { |
|
[void]$ext_args.Add("--network_args") |
|
[void]$ext_args.Add("conv_dim=$conv_dim") |
|
[void]$ext_args.Add("conv_alpha=$conv_alpha") |
|
[void]$ext_args.Add("algo=$algo") |
|
[void]$ext_args.Add("dropout=$dropout") |
|
} |
|
|
|
if ($noise_offset -ne 0) { |
|
[void]$ext_args.Add("--noise_offset=$noise_offset") |
|
} |
|
|
|
if ($stop_text_encoder_training -ne 0) { |
|
[void]$ext_args.Add("--stop_text_encoder_training=$stop_text_encoder_training") |
|
} |
|
|
|
if ($save_state -eq 1) { |
|
[void]$ext_args.Add("--save_state") |
|
} |
|
|
|
if ($resume) { |
|
[void]$ext_args.Add("--resume=" + $resume) |
|
} |
|
|
|
if ($min_snr_gamma -ne 0) { |
|
[void]$ext_args.Add("--min_snr_gamma=$min_snr_gamma") |
|
} |
|
|
|
if ($persistent_data_loader_workers) { |
|
[void]$ext_args.Add("--persistent_data_loader_workers") |
|
} |
|
|
|
if ($use_wandb -eq 1) { |
|
[void]$ext_args.Add("--log_with=all") |
|
if ($wandb_api_key) { |
|
[void]$ext_args.Add("--wandb_api_key=" + $wandb_api_key) |
|
} |
|
|
|
if ($log_tracker_name) { |
|
[void]$ext_args.Add("--log_tracker_name=" + $log_tracker_name) |
|
} |
|
} |
|
else { |
|
[void]$ext_args.Add("--log_with=tensorboard") |
|
} |
|
|
|
|
|
python -m accelerate.commands.launch $launch_args --num_cpu_threads_per_process=4 $trainer_file ` |
|
--enable_bucket ` |
|
--pretrained_model_name_or_path=$pretrained_model ` |
|
--train_data_dir=$train_data_dir ` |
|
--output_dir="./output" ` |
|
--logging_dir="./logs" ` |
|
--log_prefix=$output_name ` |
|
--resolution=$resolution ` |
|
--network_module=$network_module ` |
|
--max_train_epochs=$max_train_epoches ` |
|
--learning_rate=$lr ` |
|
--unet_lr=$unet_lr ` |
|
--text_encoder_lr=$text_encoder_lr ` |
|
--lr_scheduler=$lr_scheduler ` |
|
--lr_warmup_steps=$lr_warmup_steps ` |
|
--lr_scheduler_num_cycles=$lr_restart_cycles ` |
|
--network_dim=$network_dim ` |
|
--network_alpha=$network_alpha ` |
|
--output_name=$output_name ` |
|
--train_batch_size=$batch_size ` |
|
--save_every_n_epochs=$save_every_n_epochs ` |
|
--mixed_precision="fp16" ` |
|
--save_precision="fp16" ` |
|
--seed="1337" ` |
|
--cache_latents ` |
|
--prior_loss_weight=1 ` |
|
--max_token_length=225 ` |
|
--caption_extension=".txt" ` |
|
--save_model_as=$save_model_as ` |
|
--min_bucket_reso=$min_bucket_reso ` |
|
--max_bucket_reso=$max_bucket_reso ` |
|
--keep_tokens=$keep_tokens ` |
|
--xformers --shuffle_caption $ext_args |
|
Write-Output "Train finished" |
|
Read-Host | Out-Null ; |
|
|