NokiMo
Furkan Gözükara
Furkan Gözükara

patreon


SDXL Kohya LoRA Training With 12 GB VRAM Having GPUs - Tested On RTX 3060

Patreon exclusive posts index

Join discord and tell me your discord username to get a special rank : SECourses Discord

Upgrade Kohya to latest version. Open a CMD and do a git pull.

Kohya repo : https://github.com/bmaltais/kohya_ss

SDXL training video : https://youtu.be/AY6DMBCIZ3A

SDXL training github file : click

I tested on my second GPU - RTX 3060 (12 GB). However since it is my second GPU it has 0 VRAM usage. Therefore I was able to use 96 Network Rank (Dimension). The more Network Rank (Dimension) means it will be able to learn more information.

But since you will use it on your main GPU there will be already some VRAM usage. Therefore start with Network Rank (Dimension) 8 and then increase until you get error as I have shown in video.

Sorry that it doesn't have audio because I am on vacation. Therefore I recorded via remote connection to my main computer.

Training command (training command.txt) with 32 Network Rank

32 Rank uses 11.5 GB VRAM

accelerate launch --num_cpu_threads_per_process=2 "./sdxl_train_network.py" --enable_bucket --min_bucket_reso=256 --max_bucket_reso=2048 --pretrained_model_name_or_path="F:/0 models/sd_xl_base_1.0.safetensors" --train_data_dir="F:/kohya sdxl tutorial files\img" --reg_data_dir="F:/kohya sdxl tutorial files\reg" --resolution="1024,1024" --output_dir="F:/kohya sdxl tutorial files\model" --logging_dir="F:/kohya sdxl tutorial files\log" --network_alpha="1" --save_model_as=safetensors --network_module=networks.lora --text_encoder_lr=0.0004 --unet_lr=0.0004 --network_dim=32 --output_name="tutorial_video" --lr_scheduler_num_cycles="10" --no_half_vae --full_bf16 --learning_rate="0.0004" --lr_scheduler="constant" --train_batch_size="1" --max_train_steps="5200" --save_every_n_epochs="1" --mixed_precision="bf16" --save_precision="bf16" --cache_latents --cache_latents_to_disk --optimizer_type="Adafactor" --optimizer_args scale_parameter=False 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

Training json file : test_video_lowVRAM.json

Comments

yes once it uses shared vram it reduces speed significantly sadly

Furkan Gözükara

You're right, it uses 0.2 on the shared ... i didnt see it

Anonyme pas trop anonyme

i think it still used shared VRAM. currently I am testing OneTrainer and it uses lesser VRAM than Kohya. but i need to find good hyper parameters

Furkan Gözükara

Information for people who wants to try : 11 training images - same parameters as the .json with 96 NETWORK RANK - before starting i had 0.8GB/12GB VRAM. It is working right now and i have 11.7 GB VRAM/12 GB VRAM. On a 3060(12GB), it take about 6H30 to complete.

Anonyme pas trop anonyme

i agree

Furkan Gözükara

I played around with it for a couple of hours. You can actually get some small improvements out of the refiner, by seeting a very small denoise and a smaller cfg and 5 steps or lower. Doesn't make a big difference though. We'll have to wait until we find out how to train a refiner lora.

Amazing Asians

That is correct. Refiner training is something I am waiting as well. Sadly none of the scripts supporting it as far as I know

Furkan Gözükara

I'm using a SDXL Lora like in your youtube tutorial and it works great. Thank you so much! But I would like to train a refiner Lora if that is possible. If i use the standard refiner model without my base lora, the results are great, but the ohwx man is changed to a random guy. If I add the base_lora after the refiner, the results just look terrible. Will you make a tutorial about how to train a refiner Lora? If not, do you have any tip for me so i can do it myself?

Amazing Asians

very nice

Furkan Gözükara

I made it: https://huggingface.co/alessandro893/sdxl_base_1.0_FP32

Alexander Kolesnikov

Sorry for late reply patreon didn't give me notifications. I am glad you solved

Furkan Gözükara

It ended up working when I used reg images, somehow.

Cryptosai

You are welcome and thank you so much for the comment.

Furkan Gözükara

I tested it with my 3060 and it worked. It took a long time but it was worth it, the quality of SDXL is amazing. Thanks for the tutorial!

San Milano

I have the most up to date drivers, are you aware of anyone that has had better success with 40 series GPUs and what drivers they might be using?

Cryptosai

Hello. that is not normal. not 50 hours or that error. i suspect it is due to nvidia driver. regularization will not make a difference. i made a whole tutorial for 12gb vram cards have you watched it? : https://youtu.be/sBFGitIvD2A I suspect drivers because RTX 4090 owners are barely getting RTX 3090 performance and even lower

Furkan Gözükara

When testing on my 4070 TI, the process is estimated to take 50h and then stops with RuntimeError: CUDA error: unspecified launch failure after 1h and a half of running. The differences, in my case, is that I did not use any regularization images, I used 30 images as training samples, and the images had .txt files with descriptions (as that is the way I used to train in SD 1.5) Edit: For the record, my VRAM usage when nothing is running is 0.4, and I do have the latest Kohya version

Cryptosai

yes this happens when overtrained. you should do x/y/z checkpoint comparison. moreover improving the training dataset really really important. i have recorded a new video and explaining both of these very well. hopefully coming today. still editing . and thank you so much for your Patreon support. sorry for late reply

Furkan Gözükara

Hello ty for everything you do, new patreon. I was able to train the SDXL lora with gtx1080ti but when i prompt "photo of ohwx man +lora" the resemblance is good, the moment I start adding to the prompt it goes away and never resembles. Any suggestions? TY

PhilipRikoZen

yes definitely dont use any instead of male. alternatively you can generate your own class images from text2img tab of automatic1111. hopefully i will show in upcoming video

Furkan Gözükara

Hey thanks for your answer. So it is better to use no regularization instead of the male one in my case? When nothing is running I use 0,5 gig excactly

Clive Oven

yesterday one another patreon member were having same issue. out of vram error. it turns out he wasn't using the latest version. can update your kohya to latest with git pull? also what is your VRAM usage when nothing is running? try to get it below 500 MB it helps a lot and regularization pictures do matter. for woman you need woman dataset. hopefully i will release it

Furkan Gözükara

Even on a 4070 (12gig ram) it seems not to work. But I have 50 pictures, maybe reduce the pictures in the folder? What is the optimal picture number anyhow for SDXL? And about the 1024x regulation pictures, does it matter if the subject is a woman? Because they all show a man. Sorry for the stupid question haha. Anyway keep up the good work. You are amazing.

Clive Oven

you are welcome.

Furkan Gözükara

thank you very very much!

Andrex Selivanov

not yet sorry about delay. i will message you hopefully in 30 minutes.

Furkan Gözükara

yes, did you see it?

Andrex Selivanov

can you message me from discord? i can connect your pc and try myself.

Furkan Gözükara

Trying 8, 7, 6, 5, 4, ... the same results (( , maybe 2 monitors 4k eating vram?

Andrex Selivanov

ok you need to try with rank 16 probably. 0.6 is a lot usage :/ have you tried rank 16 and rank 8?

Furkan Gözükara

you are welcome

Furkan Gözükara

0,6 - 0,9 gb i think so CUDA out of memory. Tried to allocate 50.00 MiB (GPU 0; 12.00 GiB total capacity; 11.10 GiB already allocated; 0 bytes free; 11.34 GiB reserved in total by PyTorch)

Andrex Selivanov

Thank you!

Alexander Kolesnikov

I made 2 topics for you : https://discuss.huggingface.co/t/how-can-we-convert-sdxl-diffusers-to-fp32-safetensors/49394/1 https://github.com/kohya-ss/sd-scripts/issues/710

Furkan Gözükara

hello. can you check how much vram your system is using when you dont do training? i did a lot of training recently on rtx 3060

Furkan Gözükara

unfortunately not work for me (( 3060 12GB (OutOfMemoryError: CUDA out of memory.)

Andrex Selivanov

I will check and let you know hopefully

Furkan Gözükara

Yes I mean diffusers. I did not find any scripts for sdxl converting in Kohya repo, but I know that the answer should be somewhere in this script: https://github.com/kohya-ss/sd-scripts/blob/sdxl/sdxl_train.py

Alexander Kolesnikov

you mean diffusers i believe? kohya has such interface but i haven't tested yet. did you test?

Furkan Gözükara

it shouldnt matter. your mac should upcast it into fp32 while working. bu8t i dont have a mac so cant test. training fp32 will consume more vram. but if you can afford such training you can do training with fp32. may yield slightly better results . so sorry for late reply

Furkan Gözükara

One more question - do you know how to convert sdxl raw model to .safetensors? I want to make sdxl-1.0 float32.

Alexander Kolesnikov

Hello, I'm Mac user, mac works only with float32, should I need to train full precision fp32 model or it's fine to use fp16 model and upcast it to fp32? I also noticed that sdxl 1.0 is fp16 model, while sdxl 0.9 is fp32, which is better for training fp32? I tried training both - lora and dreambooth, both in fp32, and lora have much better result than dreambooth. (I used runpod RTX A6000).

Alexander Kolesnikov

dreambooth of realistic vision for face is still better than SDXL LoRA. I think we need refiner training as well. I am working on even a better workflow for SDXL

Furkan Gözükara

What have you discovered with the SDXL LORA training image quality vs the dreambooth training you have done recently? My latest RV5.1 & RV4.0 based dreambooth training have yielded amazing results.

Ec Jep

10 gb pretty low :/ i find that 32 rank is decent but uses 11.5 GB vram on my RTX 3060 - this is for SDXL 1024x1024

Furkan Gözükara

What rank would you recommend for a 3080fe with 10gb vram?

Virtamouse


Related Creators