Stable Diffusion XL (SDXL) DreamBooth: Easy, Fast & Free | Beginner Friendly
In this video, I'll show you how to train amazing dreambooth models with the newly released SDXL 1.0! In addition to that, we will also learn how to generate images using SDXL base model and the use of refiner to enhance the quality of generated images.
The commands used for training in this video are as follows:
!pip install -U autotrain-advanced
!autotrain setup --update-torch
!autotrain dreambooth \
--model stabilityai/stable-diffusion-xl-base-1.0 \
--output output/ \
--image-path images/ \
--prompt "photo of sks dog" \
--resolution 1024 \
--batch-size 1 \
--num-steps 500 \
--fp16 \
--gradient-accumulation 4 \
--lr 1e-4
On google colab, you can add --use-8bit-adam parameter and change resolution to 512 if you are on free version of google colab.
Inference code:
Please subscribe and like the video to help me keep motivated to make awesome videos like this one. :)
My book, Approaching (Almost) Any Machine Learning problem, is available for free here: bit.ly/approachingml
Follow me on:
Twitter: / abhi1thakur
LinkedIn: / abhi1thakur
Kaggle: kaggle.com/abhishek
Пікірлер: 136
Please subscribe and like the video to help me keep motivated to make awesome videos like this one. :) Inference code: gist.github.com/abhishekkrthakur/ebe82f7140d3b5bff925320d59972b14 Training part is in video description!
@Pakmandesign
Жыл бұрын
What version of autotrain are you using? My doesn't let me run autotrain setup. and threw this error usage: autotrain [] AutoTrain advanced CLI: error: argument {app}: invalid choice: 'setup' (choose from 'app')
@abhishekkrthakur
Жыл бұрын
@@Pakmandesign always on latest release: pypi.org/project/autotrain-advanced/
@gunasekhar8440
Жыл бұрын
Should we change the prompt? Or else we need to use only those words except images?
@abhishekkrthakur
Жыл бұрын
@@gunasekhar8440 prompt can be anything. just remember it as you have to use the same keyword during inference. in my case "sks dog"
@gunasekhar8440
Жыл бұрын
@@abhishekkrthakur really very thanks for the reply
Very helpful tutorials on the latest updates Abhishek, thanks!!
I don't see the option to select after creating a new space with docker and autotrain.. It's running on A10G but the backend options are totally different and there's no option to select projecttype. The tabs available to me are llm, text, and tabular
A beginner's question maybe, "How can I train the model on different things" like this dog example you shared. How can I build on that and add more concepts for the same model.
doest work. mem error in last step. tried on colab as well gcp office machin
Does this use .txt file or filename captions? Or is it just a single 'sks' keyword type prompt for every image?
Great Tutorial!
Thank you for a great video. I got some problem. When training is end and it's time to save lora weights and checkpoint, i get cuda out of memory. Do you have any idea how to fix it? solution: use --checkpointing-steps 100000 to save only lora weights
Thanks for your tutorial. Do you know if it is possible to use Kohya for SDXL dreambooth training ?
Can you help me? I'm trying to use the huggingface "AutoTrain_Dreambooth" notebook on Kaggle, with two T4 Gpus, to train faces on sdxl Worked, but it's only using one gpu I tried to launch using the accelerator changing !autotrain dreambooth \ to !accelerate launch autotrain dreambooth \ But this error message appears "can't open file 'kaggle/working/autotrain': [Errno 2] No such file or directory" How can i fix that? Or is there any other way to force the notebook to use two Nvidia t4?? Sorry to bother you
What might i be doing wrong if it is giving me an error after like 25 minutes of working?
Thanks for sharing :)
how to add different objects to same model like cat , dog , car etc
i see that we have a --resume-from-checkpoint parameter. can we have continue training one model that we start in other colab session? i trained one model until 1300 steps but i think we need more train. if i can resume this checkpoint i will not spen a lot of hours in processing data. i tryed add this parameter in colab and local but allways get error.
Is a 4070Ti 12gb enough? I've seen that the recommended setup is 16gb vram. I don't care if it takes longer, what I don't want is to run into too many OOM errors
how can i use realistic vision v5.1 instead of Stable Diffusion XL?
Amazing work, I am going to try this on a local machine I am buying new GPU for this and I will need to used it for local LLMa what GPU you think will work the best and I am going to try this on FPGA next just see how this can perform.
Great tutorial! So if I'm following the idea here, you are training to make an object (the dog in the pictures) to be prompted into different styles basically. But what about if you want to train it for a style that you can turn any object into that style? So basically how does the training differ if you want to train it to output a specific style across different objects?
@harnageaa
Жыл бұрын
think about this, the model learns the way the pixels get arranged in an imagine. If ur image have dogs, then he learns the pixels are shaped in a dog shape, so u get dogs.., if u get images with an 'artist' name in mind, then all the pixels will be shaped in that specific style, then once you train on "anime girls" for example from a hentai artist. You will still get "objects", drawn in his style even if you had zero objects with that stype in the training dataset. Does that make sense? if u think of shape, just find shape of what u want, if u want style just add only that type of style in dataset. same for pose (pose = shape for AI)
@harnageaa
Жыл бұрын
@@BarbSmith-fw7vbthen you will get all 10 + combined. Basically you might get 'random' styles, Some people train with tags each image(filewords)? at least in SD 1.5, and that meant when you use certain tags you retrieve that data. Simpler would be a Lora, where u have 10 images, and 10 txt for each image, where u have 'tags', assuming each file has different "artstyle tag" in the txt file then when you use that tag with the artstyle name you will get it. Also how u think these 'generalistic' models are made of that can create literally any type of stylistic image. They just add every genre and train 1 model. So I guess if u want to retrieve a certain style, u would need a 'tag'. In dreambooth SD1.5 I used to use 'concepts', where you had 4 keywords for dreambooth (I didn't used filewords), and I would teach the AI 4 keyword and everytime you use one of them, he gives exactly what I want (1 a pose, 1 a style, a manga style and a generalistic term that generate default images when prompted, so you use 1 word to generate what the model is suppose to). You will have to experiment to see what exactly happen when u use 10 artstyles in 1 . My guess, all in one + combined at the same time
Thanks for getting this up so quick!! A couple notes: 1. it's !autotrain setup --update-torch (not upgrade) 2. getting the error 'RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'' when trying to run dreambooth training specifically after '> INFO Computing text embeddings for prompt: subject wearing sks' is printed Any ideas?
@abhishekkrthakur
Жыл бұрын
uff! sorry! thanks for the correction. the error is because either sd pipe or refiner is not moved to cuda
@numera123
10 ай бұрын
was this resolved i still get this error
I can't make it work on Kaggle ! --output parameter doesn't exist --project-name parameter is required I have solved the 2 parameters problems but I have this error : RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'
how we can train a DreamBooth model with multiple "characters"?Please guide
does this run on Apple silicon MacBooks ?
I get below message on cmd when i run the following command, "C:\Windows\system32>autotrain setup --update-torch usage: autotrain [] AutoTrain advanced CLI: error: argument {app}: invalid choice: 'setup' (choose from 'app')" How do i fix this?
@abhishekkrthakur
Жыл бұрын
that means you have an old version of autotrain installed
thanks for this nice tutorial and the autotrain-advanced tool. I am able to reproduce everything you do. One slight question tho; I'm new to ML & SD so I don't understand everything in detail. What we train here; "pytorch_lora_weights.safetensors" is just a LORA weight right? not a full checkpoint. (since the size is also very small) - I've copied this file into "loras" directory in comfy-ui, set the base model as sdxl and load this one as lora, however it doesn't seem to do anything when I prompt "sks man", I just get a random image and hundreds of "lora key not loaded unet.up_blocks.1.attentions.2.transformer_blocks.1..........." errors - is this not supposed to work as standalone lora?
@archonoff
Жыл бұрын
I've got exactly the same behaviour. A bunch on 'lora key not loaded ...' messages and no effenct on the final result. The results were just random people. I also tried to use this lora in a1111, but the same result: just random people. Have you finally find the solution? What was wrong?
@andresmartin8895
Жыл бұрын
I have the same problem
@cemal6950
11 ай бұрын
have u type the in prompt? also use the "sks man"
@trsd8640
11 ай бұрын
Yes, thats right. The Lora did not work anywhere. I try it in automatic1111, comfyUi, Draw Things,.. it does definitiv NOT work.
In the last step, it is showing me an error in the first line, "diffuser" not installed. What to do? I am new to this.
@PingPongReview
10 ай бұрын
Got it, I have to run the first part again
how to load the pytorch_lora_weights.safetensors file to webui?
just tried the hugging face spaces method and keep getting errors. Some around creation of /tmp/training. Not sure what the exact issue is since everything is automated but followed the same setup from the video with four 512x512 training .jpeg images
@abhishekkrthakur
Жыл бұрын
weird. whats the error in the logs?
@pranaviyer6291
Жыл бұрын
@@abhishekkrthakur The main one was no such directory called /tmp/training --> I assume it was attempting to move the created training dataset there and perhaps didn't actually create it?
It is complusory to download dreambooth ,as my laptop is old ??
does the aspect ratio matter? Does the aspect ratio need to be consistent across the training set?
@chrisrosch4731
7 ай бұрын
would like to know too
@chinmoybasak7749
4 ай бұрын
Did you find out?
Even when I use the prompt that I trained the model with I still can't get it to generate what I trained it to generate. Does anyone have an idea why this could be the case?
@JamalanJuda
Жыл бұрын
make sure the prompt you give it when you train is somewhat unique, so in the video he says sks dog, make your prompt something like "photo of hbvkdnvdkvfnj" and then when you prompt it back use "hbvkdnvdkvfnj" as the subject name.
@trsd8640
11 ай бұрын
It simply doesnt works. I tried the generated lora on nearly every ui, but it dont works.
@abhishekkrthakur
11 ай бұрын
you can use the code for inference. ill see if there is a conversion script
now, AttributeError: 'DownBlock2D' object has no attribute 'attentions' what to do?
@PingPongReview
10 ай бұрын
this is the code i was using from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline import torch prj_path = "/content/my_first_project" model = "stabilityai/stable-diffusion-xl-base-1.0" pipe = DiffusionPipeline.from_pretrained( model, torch_dtype=torch.float16, ) pipe.to("cuda") pipe.load_lora_weights(prj_path, weight_name="pytorch_lora_weights.safetensors") refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, ) refiner.to("cuda") prompt = "Linkedin photo of me" seed = 42 generator = torch.Generator("cuda").manual_seed(seed) image = pipe(prompt=prompt, generator=generator).images[0] image = refiner(prompt=prompt, generator=generator, image=image).images[0] image.save(f"generated_image.png")
Hello. Is it possible to use the pytorch_lora_weights.safetensors file inside Webui ?
@abhishekkrthakur
Жыл бұрын
i guess so. but since i dont use any webui, i dont know. afaik, most webui support LoRA weights
any tips on using this method (via hugginface spaces) to train for faces? would it need significantly more reference images and steps to produce a reliable output? also do these .safetensor files act the same as any other lora when used in a SDXL workflow utilizing comfyui for example?
@abhishekkrthakur
Жыл бұрын
Using face images should be fine. Unless i dont understand the question 🤔. yes the safetensors should be compatible anywhere
i failed to run on free colab with 8bit and resolution 512 options because of lack of GPU i guess.....
@abhishekkrthakur
Жыл бұрын
you need to attach a gpu to colab. free works with 512 resolution
Hi everyone! I have a noobie question. AutoTrain advanced CLI: error: unrecognized arguments: --output model/ How to fix this error and specify the output model?
Could I have to know how many Graphic Card Memory and System Memory for SDXL with StableDiffusion WebUI?
@abhishekkrthakur
Жыл бұрын
16gb for this tutorial
Receiving the below error while running in colab. Have used the same autotrain command given. Please assist on the error. File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/normalization.py", line 190, in forward return F.layer_norm( File "/usr/local/lib/python3.10/dist-packages/torch/nn/functional.py", line 2515, in layer_norm return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled) RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'
@benjaminm.1053
Жыл бұрын
Are you sure you attached a GPU to your google colab Notebook?
@abhishekkrthakur
Жыл бұрын
if you did attach a gpu, you need to run the setup command. please see description
How do I run inference on huggingface spaces?
@nidesharumugam5488
6 ай бұрын
Hi, did you find a way to deploy it ?
i trained on huggingfaces it went trough, but i only got a file with 23.4mb i thought it would be much bigger
@abhishekkrthakur
Жыл бұрын
its LoRA
@andreasfischer8916
Жыл бұрын
@@abhishekkrthakur ok thank you
fyi: the model training took around 20mins with 16GB gpu memory.
holy shit. can you do another one in a1111 or something?
Thanks a lot for this tutorial! I kept running into the import error that says I can't import 'randn_tensor' from 'diffusers.utils' in colab. Does anyone know how I could fix this?
@abhishekkrthakur
10 ай бұрын
fixed now
@davidyang1322
10 ай бұрын
Awesome!! Thank you for the quick fix!@@abhishekkrthakur
@davidyang1322
10 ай бұрын
Hi again! I was still getting the CUDA out of memory error when using free colab, even after adding the checkpointing_steps and changing res + using 8bit adam adapter, could you please adjust the colab link so that it avoids these errors? maybe it could be that I added the code to the wrong line? Thx in advance@@abhishekkrthakur
@abhishekkrthakur
10 ай бұрын
@@davidyang1322 colab link as it is works perfectly fine.
@abhishekkrthakur
10 ай бұрын
colab.research.google.com/github/huggingface/autotrain-advanced/blob/main/colabs/AutoTrain_Dreambooth.ipynb use this
Same error always! usage: autotrain [] AutoTrain advanced CLI: error: unrecognized arguments: --output output/
@abhishekkrthakur
8 ай бұрын
args have changed after video, use --help to see new args
Image folder name - Kutta 😂😂.. Nice😁
@abhishekkrthakur
10 ай бұрын
i made it too visible and you are the first person who observed this 🤣
@shinchan9075
10 ай бұрын
@@abhishekkrthakur yes😁
Does this work with a 4060TI 16GB VRAM?
@abhishekkrthakur
Жыл бұрын
it should barely fit in 16GB ram. dont forget to enable 8bit adam
@DrHanes
Жыл бұрын
@@abhishekkrthakur hmm barely dosent sound good, and with two 4060TI = 32GB VRAM? Does it support multi GPU?
Looked very easy but no way to use captions?
Hey I would like to train , hindu gods and goddess , could you please suggest me , how can i do that , I am newbie in AI Thank you
@pipmuzik
11 ай бұрын
@abhishekkrthakur
hf with the beefiest gpu FileNotFoundError: [Errno 2] No such file or directory: '/tmp/training'
@abhishekkrthakur
Жыл бұрын
did it happen in first run? can you factory reset the gpu and try again?
@grebenshyo
Жыл бұрын
@@abhishekkrthakur yes, in the first run. thanks for the tip, i'm thinking i might have missed to dial down the batch size. rerunning now. will try if it doesn't work 🙌🏾
@grebenshyo
Жыл бұрын
nope. batch size wasn't the issue... need to figure out how that's done and will try
@abhishekkrthakur
Жыл бұрын
@@grebenshyo in settings
@grebenshyo
Жыл бұрын
@@abhishekkrthakur thank you 👍🏾 i actually lied: was on the entry level gpu tier. switched to the beefier and it seems to work now
Thanks very much for this tutorial! I tried running this code on colab and got this error: Input type (c10::Half) and bias type (float) should be the same
@user-wn3ro1tc6z
Жыл бұрын
Actually, adding this fixed it: !pip install super-gradients==3.1.3
@abhishekkrthakur
Жыл бұрын
did you run autotrain setup command?
@user-wn3ro1tc6z
Жыл бұрын
it turned out that fixing this: !autotrain setup --update-torch (not upgrade) resolved the issue, also. Thanks again! @@abhishekkrthakur
This code doesn't work anymore.
@abhishekkrthakur
9 ай бұрын
use this: colab.research.google.com/github/huggingface/autotrain-advanced/blob/main/colabs/AutoTrain_Dreambooth.ipynb
@Deathless-ye7xb
9 ай бұрын
Thanks, it worked very good!@@abhishekkrthakur, do you know if we can use another model as a base (I mean another sdxl 1.0 model from civitai or huggingface as a base for training our LoRA)? I'll appreciate the response.
@abhishekkrthakur
9 ай бұрын
glad to know. yeah you can use any other compatible model from huggingface. not sure about civitai
@Deathless-ye7xb
9 ай бұрын
It will be really good if you can show us how to train a sdxl 1.0 model (checkpoint/safetensors). I mean sdxl 1.0 fine-tuning, because no one made a video on youtube about it.@@abhishekkrthakur
Define : beginner friendly 🤣
But wait, that's a simple Lora. Not a dreambooth!
@abhishekkrthakur
Жыл бұрын
its not full dreambooth, yes
Wow you just confused me. Are you using Linux? I never had to write code once when using SD so far. I use auto1111 and comfyui and i have trained using a colab as well as my own auto1111 never even seen code.
hi i found your book for free, it is online pdf. i was going through popular github repo when i found ur repo and just for fun tried searching for your book for free. if you want the details please let me know. it is very interesting book or rather research material, i hope you dont blame me for reading it.
@abhishekkrthakur
Жыл бұрын
book is free. link in description 🙂 hope you liked it
@saihanbatbayarsaihan1138
Жыл бұрын
@@abhishekkrthakur oh i was reading your material and it said to notify you if i found it for free. i liked it a lot.
I have tried on Google Colab but I get this, even with --use-8bit-adam and 512 using a Nvidia v100, any clue? torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 26.00 MiB (GPU 0; 15.77 GiB total capacity; 13.58 GiB already allocated; 8.12 MiB free; 14.26 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF Steps: 100% 500/500 [20:20
@suhaaskatikaneni1925
Жыл бұрын
yeah I get same error. did you find fix for this?
@ivangu1446
Жыл бұрын
any solution?
@abhishekkrthakur
Жыл бұрын
set --checkpointing_steps=2000000 saving checkpoints is causing the issue in colab
@benjaminm.1053
Жыл бұрын
@@abhishekkrthakur I also get that error but not during the training, instead afterwards during inference. Any suggestion how to reduce memory consumption? Can I adjust something in your python script? Thx
@riccostapt
11 ай бұрын
@@benjaminm.1053 facing the same issue. Have you found a way to solve it?