kohya-ss / kohya-ss/sd-scripts
Problem with training LoRAs
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
Hei, I'm having some issues training LoRAs.
I did what was suggested in this thread: https://github.com/kohya-ss/sd-scripts/issues/405 and did both things angelOnly (editing the huggingface_util.py file) and what ProGamerGov suggested (editing train_network.py and library/train_util.py). Once I launch Kohya_SS and try to train a LoRA I get an error and the process is interrupted, here is the console.
19:31:09-484871 INFO Version: v22.1.0
19:31:09-486871 INFO nVidia toolkit detected
19:31:10-447877 INFO Torch 2.0.1+cu118
19:31:10-461355 INFO Torch backend: nVidia CUDA 11.8 cuDNN 8700
19:31:10-462866 INFO Torch detected GPU: NVIDIA GeForce RTX 3080 VRAM 10239 Arch (8, 6) Cores 68
19:31:10-463879 INFO Verifying modules installation status from requirements_windows_torch2.txt...
19:31:10-465878 INFO Verifying modules installation status from requirements.txt...
19:31:11-990720 INFO headless: False
19:31:11-992783 INFO Load CSS...
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
19:32:13-709766 INFO Copy C:/Users/The_f/Desktop/GenerativeAI/Sophie to
C:/Users/The_f/Desktop/GenerativeAI/Sophie\img/20_Kim Kardashian woman...
19:32:13-745980 INFO Copy C:/Users/The_f/Desktop/GenerativeAI/Regularisation Images/woman to
C:/Users/The_f/Desktop/GenerativeAI/Sophie\reg/1_woman...
19:32:14-055043 INFO Done creating kohya_ss training folder structure at
C:/Users/The_f/Desktop/GenerativeAI/Sophie...
19:35:10-764766 INFO Start training LoRA Standard ...
19:35:10-765766 INFO Checking for duplicate image filenames in training data directory...
19:35:10-767271 INFO Valid image folder names found in: C:/Users/The_f/Desktop/GenerativeAI/Sophie\img
19:35:10-767271 INFO Valid image folder names found in: C:/Users/The_f/Desktop/GenerativeAI/Sophie\reg
19:35:10-768267 INFO Folder 20_Kim Kardashian woman: 32 images found
19:35:10-769264 INFO Folder 20_Kim Kardashian woman: 640 steps
19:35:10-769264 WARNING Regularisation images are used... Will double the number of steps required...
19:35:10-770264 INFO Total steps: 640
19:35:10-771264 INFO Train batch size: 1
19:35:10-771264 INFO Gradient accumulation steps: 1
19:35:10-772264 INFO Epoch: 10
19:35:10-772264 INFO Regulatization factor: 2
19:35:10-773265 INFO max_train_steps (640 / 1 / 1 * 10 * 2) = 12800
19:35:10-773265 INFO stop_text_encoder_training = 0
19:35:10-774265 INFO lr_warmup_steps = 0
19:35:10-775265 INFO Saving training config to
C:/Users/The_f/Desktop/GenerativeAI/Sophie\model\SOPHIE_KOHYA-KIM_KARDASHIAN_20231020-193510.js on...
19:35:10-775265 INFO accelerate launch --num_cpu_threads_per_process=2 "./train_network.py" --enable_bucket
--min_bucket_reso=256 --max_bucket_reso=2048
--pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5"
--train_data_dir="C:/Users/The_f/Desktop/GenerativeAI/Sophie\img"
--reg_data_dir="C:/Users/The_f/Desktop/GenerativeAI/Sophie\reg" --resolution="1024,1024"
--output_dir="C:/Users/The_f/Desktop/GenerativeAI/Sophie\model"
--logging_dir="C:/Users/The_f/Desktop/GenerativeAI/Sophie\log" --network_alpha="1"
--save_model_as=safetensors --network_module=networks.lora --text_encoder_lr=0.0003
--unet_lr=0.0003 --network_dim=256 --output_name="SOPHIE_KOHYA-KIM_KARDASHIAN"
--lr_scheduler_num_cycles="10" --no_half_vae --learning_rate="0.0003" --lr_scheduler="constant" --train_batch_size="1" --max_train_steps="12800" --save_every_n_epochs="1"
--mixed_precision="bf16" --save_precision="bf16" --caption_extension=".txt" --cache_latents
--cache_latents_to_disk --optimizer_type="Adafactor" --optimizer_args scale_parameter=Flase
relative_step=False warmup_init=False --max_data_loader_n_workers="0" --bucket_reso_steps=64
--gradient_checkpointing --xformers --bucket_no_upscale --noise_offset=0.0
prepare tokenizer
Using DreamBooth method.
prepare images.
found directory C:\Users\The_f\Desktop\GenerativeAI\Sophie\img\20_Kim Kardashian woman contains 32 image files
found directory C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman contains 501 image files
No caption file found for 501 images. Training will continue without captions for these images. If class token exists, it will be used. / 501枚の画像にキャプションファイルが見つかりませんでした。これらの画像についてはキャプションなしで学習 を続行します。class tokenが存 在する場合はそれを使います。
C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman\woman_0K1QCRYe.png
C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman\woman_0L8Vyudv.jpg
C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman\woman_0LT4LeKH.jpg
C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman\woman_0RJh4xal.png
C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman\woman_0S2MwZDs.png
C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman\woman_0XvgZ31Z.jpg... and 496 more
640 train images with repeating.
501 reg images.
[Dataset 0]
batch_size: 1
resolution: (1024, 1024)
enable_bucket: True
min_bucket_reso: 256
max_bucket_reso: 2048
bucket_reso_steps: 64
bucket_no_upscale: True
[Subset 0 of Dataset 0]
image_dir: "C:\Users\The_f\Desktop\GenerativeAI\Sophie\img\20_Kim Kardashian woman"
image_count: 32
num_repeats: 20
shuffle_caption: False
keep_tokens: 0
caption_dropout_rate: 0.0
caption_dropout_every_n_epoches: 0
caption_tag_dropout_rate: 0.0
caption_prefix: None
caption_suffix: None
color_aug: False
flip_aug: False
face_crop_aug_range: None
random_crop: False
token_warmup_min: 1,
token_warmup_step: 0,
is_reg: False
class_tokens: Kim Kardashian woman
caption_extension: .txt
[Subset 1 of Dataset 0]
image_dir: "C:\Users\The_f\Desktop\GenerativeAI\Sophie\reg\1_woman"
image_count: 501
num_repeats: 1
shuffle_caption: False
keep_tokens: 0
caption_dropout_rate: 0.0
caption_dropout_every_n_epoches: 0
caption_tag_dropout_rate: 0.0
caption_prefix: None
caption_suffix: None
color_aug: False
flip_aug: False
face_crop_aug_range: None
random_crop: False
token_warmup_min: 1,
token_warmup_step: 0,
is_reg: True
class_tokens: woman
caption_extension: .txt
[Dataset 0]
loading image sizes.
100%|███████████████████████████████████████████████████████████████████████████████| 533/533 [00:00<00:00, 550.19it/s]
make buckets
min_bucket_reso and max_bucket_reso are ignored if bucket_no_upscale is set, because bucket reso is defined by image size automatically / bucket_no_upscaleが指定された場合は、bucketの解像度は画像サイズから自動計算されるため、min_bucket_resoとmax_bucket_resoは無視されま す
number of images (including repeats) / 各bucketの画像枚数(繰り返し回数を含む)
bucket 0: resolution (896, 1024), count: 120
bucket 1: resolution (896, 1088), count: 460
bucket 2: resolution (1024, 1024), count: 700
mean ar error (without repeats): 0.0010824334794051562
preparing accelerator
loading model for process 0/1
load Diffusers pretrained models: runwayml/stable-diffusion-v1-5
vae\diffusion_pytorch_model.safetensors not found
Loading pipeline components...: 100%|████████████████████████████████████████████████████| 5/5 [00:01<00:00, 4.71it/s]
You have disabled the safety checker for by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .
UNet2DConditionModel: 64, 8, 768, False, False
U-Net converted to original U-Net
Enable xformers for U-Net
A matching Triton is not available, some optimizations will not be enabled.
Error caught was: No module named 'triton'
import network module: networks.lora
[Dataset 0]
caching latents.
checking cache validity...
100%|████████████████████████████████████████████████████████████████████████████| 533/533 [00:00<00:00, 118427.93it/s]
caching latents...
100%|████████████████████████████████████████████████████████████████████████████████| 533/533 [03:29<00:00, 2.54it/s]
create LoRA network. base dim (rank): 256, alpha: 1.0
neuron dropout: p=None, rank dropout: p=None, module dropout: p=None
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
CrossAttnDownBlock2D False -> True
CrossAttnDownBlock2D False -> True
CrossAttnDownBlock2D False -> True
DownBlock2D False -> True
UNetMidBlock2DCrossAttn False -> True
UpBlock2D False -> True
CrossAttnUpBlock2D False -> True
CrossAttnUpBlock2D False -> True
CrossAttnUpBlock2D False -> True
prepare optimizer, data loader etc.
Traceback (most recent call last):
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\train_network.py", line 1009, in
trainer.train(args)
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\train_network.py", line 338, in train
optimizer_name, optimizer_args, optimizer = train_util.get_optimizer(args, trainable_params)
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\library\train_util.py", line 3389, in get_optimizer
value = ast.literal_eval(value)
File "C:\Users\The_f\AppData\Local\Programs\Python\Python310\lib\ast.py", line 108, in literal_eval
return _convert(node_or_string)
File "C:\Users\The_f\AppData\Local\Programs\Python\Python310\lib\ast.py", line 107, in _convert
return _convert_signed_num(node)
File "C:\Users\The_f\AppData\Local\Programs\Python\Python310\lib\ast.py", line 81, in _convert_signed_num
return _convert_num(node)
File "C:\Users\The_f\AppData\Local\Programs\Python\Python310\lib\ast.py", line 72, in _convert_num
_raise_malformed_node(node)
File "C:\Users\The_f\AppData\Local\Programs\Python\Python310\lib\ast.py", line 69, in _raise_malformed_node
raise ValueError(msg + f': {node!r}')
ValueError: malformed node or string on line 1:
Traceback (most recent call last):
File "C:\Users\The_f\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\The_f\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\venv\Scripts\accelerate.exe\__main__.py", line 7, in
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\accelerate_cli.py", line 47, in main
args.func(args)
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\launch.py", line 986, in launch_command
simple_launcher(args)
File "C:\Users\The_f\StableDiffusion\Kohya\kohya_ss\venv\lib\site-packages\accelerate\commands\launch.py", line 628, in simple_launcher
raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['C:\\Users\\The_f\\StableDiffusion\\Kohya\\kohya_ss\\venv\\Scripts\\python.exe', './train_network.py', '--enable_bucket', '--min_bucket_reso=256', '--max_bucket_reso=2048', '--pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5', '--train_data_dir=C:/Users/The_f/Desktop/GenerativeAI/Sophie\\img', '--reg_data_dir=C:/Users/The_f/Desktop/GenerativeAI/Sophie\\reg', '--resolution=1024,1024', '--output_dir=C:/Users/The_f/Desktop/GenerativeAI/Sophie\\model', '--logging_dir=C:/Users/The_f/Desktop/GenerativeAI/Sophie\\log', '--network_alpha=1', '--save_model_as=safetensors', '--network_module=networks.lora', '--text_encoder_lr=0.0003', '--unet_lr=0.0003', '--network_dim=256', '--output_name=SOPHIE_KOHYA-KIM_KARDASHIAN', '--lr_scheduler_num_cycles=10', '--no_half_vae', '--learning_rate=0.0003', '--lr_scheduler=constant', '--train_batch_size=1', '--max_train_steps=12800', '--save_every_n_epochs=1', '--mixed_precision=bf16', '--save_precision=bf16', '--caption_extension=.txt', '--cache_latents', '--cache_latents_to_disk', '--optimizer_type=Adafactor', '--optimizer_args', 'scale_parameter=Flase', 'relative_step=False', 'warmup_init=False', '--max_data_loader_n_workers=0', '--bucket_reso_steps=64', '--gradient_checkpointing', '--xformers', '--bucket_no_upscale', '--noise_offset=0.0']' returned non-zero exit status 1.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the traceback in train_network.py at line 338 and inspect the optimizer argument handling in library/train_util.py at line 3389. Reproduce the reported LoRA training command and follow the values passed to optimizer parsing, especially the optimizer_args shown in the console. Done means training proceeds past optimizer setup without the reported ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- huggingface, python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100