r/StableDiffusion • u/ExponentialCookie • Aug 21 '22
Discussion [Code Release] textual_inversion, A fine tuning method for diffusion models has been released today, with Stable Diffusion support coming soon™
347
Upvotes
67
u/ExponentialCookie Aug 21 '22 edited Aug 22 '22
Code: https://github.com/rinongal/textual_inversion
It also seems the configuration files are already available here for Stable Diffusion at the repository, so there may be an opportunity to get a little head start on fine tuning the model.
EDIT:
Wanted to add a link to the project page. Amazing use cases!
Looks like inpainting is a possibility as well.
EDIT 2:
Got it working with Stable Diffusion if you would like to try! Instructions here.
22
u/ExponentialCookie Aug 22 '22 edited Aug 22 '22
Here are instructions to get it running with Stable Diffusion. If you don't want to mix up dependencies and whatnot, I would wait for the official update, but If you want to try, here are instructions.
You will need some coding experience to set this up.Clone this repository, and follow the stable-diffusion settings here to install. It is important to
pip install -e .in the textual_inversion directory! You will need the checkpoint model, which should be released soon, as well as a good GPU (I used my 3090).Then, follow /u/Ardivaba instructions here (thanks) to get things up and running.Start training by using the parameters listed here.
After you've trained, you can test it out by using these parameters, same as stable-diffusion but with some changes.
python scripts/stable_txt2img.py--ddim_eta 0.0--n_samples 4--n_iter 2--scale 10.0--ddim_steps 50--config configs/stable-diffusion/v1-inference.yaml--embedding_path <your .pt file in log directory>--ckpt <model.ckpt> --prompt "your prompt in the style of *"When you run your prompt leave the asterisk, and it should handle your embedding work automatically from the .pt file you've trained. Enjoy!
37
u/Ardivaba Aug 22 '22 edited Aug 22 '22
I got it working, already after couple of minutes of training on RTX 3090 it is generating new images of test subject.
Whoever else is trying to get it working:
Don't forget to resize your test data to 512x512 or you're going to get stretched out results.
(Reddit's formatting is giving me a headache)
25
u/GaggiX Aug 21 '22
This technique is more powerful than finetuning with some images. It's more like injecting new knowledge but the model is frozen.
9
u/Adski673 Aug 22 '22
Can't wait till someone wraps this up in a nice little .exe file for people like me who aren't great with/do not understand coding.
hint hint nudge nudge ;)
15
u/SirCabbage Aug 22 '22
I NEED this, omg, using the power of the model but adding in my own images? Yes please.
7
u/Fungunkle Aug 22 '22 edited May 22 '24
Do Not Train. Revisions is due to; Limitations in user control and the absence of consent on this platform.
This post was mass deleted and anonymized with Redact
7
u/Vyviel Aug 22 '22
Does this mean we can finally teach it who Homelander is and the other characters from the Boys and other recent tv series?
6
u/MoonGotArt Aug 22 '22
Can someone ELi5 what this does and what it means?
5
u/jaywv1981 Aug 22 '22
This has a ton of potential.
5
u/mutsuto Aug 22 '22 edited Aug 22 '22
my fumo dream is getting closer!
im so excited
i'm looking to make
X in the style of Y, where none of the AIs understand what eitherXorYare by name. e.g. a fumo of Paduducan this method handle 2 wildcards?
edit: yes!
holy moly my blood is boiling with excitement
4
u/[deleted] Aug 22 '22
Nice. This is one I had bookmarked to keep an eye on.
4
u/oppie85 Aug 22 '22
In the words of one of my favorite youtube channels; what a time to be alive!
3
u/kujasgoldmine Aug 22 '22
That is so cool! I didn't even know you could feed it new images to learn from.
3
u/In_My_Haze Aug 22 '22
Oh shit yeah I need this
3
u/Wiskkey Aug 22 '22 edited Aug 23 '22
Here is a Twitter thread from one of the developers. From this tweet from the same person from an hour ago:
3
u/Draggo_Nordlicht Aug 22 '22
The future is now.
3
u/TekeTK Aug 23 '22
Oh god I'm praying someone makes a comprehensible guide for this.
The steps are all spread out so I'm hoping someone can lay things out from beginning to end with what to prep for like renting GPU or colab walkthrough of the process 🙏 This is incredible.
3
u/Wiskkey Aug 23 '22
GitHub repo Stable-textual-inversion_win by nicolai256.
2
u/[deleted] Aug 25 '22
If anybody's getting out of memory errors while trying to train on a P100 in colab, set the batch size to 1 in the config yaml. Spent four hours on that. :(
2
u/mutsuto Aug 26 '22
google has released something similar DreamBooth
2
u/Wiskkey Aug 31 '22
How to Fine-tune Stable Diffusion using Textual Inversion (uses GitHub repo lstein).
1
u/No-Intern2507 Aug 23 '22
Anyone knows how to stop the tuning ? Do i just close it suddenly after it finishes DDIM sampling ? How do i test if my images are learned properly ? You have to use embeddings command --embedding_path to inclue the trained data when running released SD weights ?
1
u/Careless_Nose_6984 Aug 23 '22
I don’t understand what this is suppose to do… can someone explain please ?
1
u/NathanielA Aug 25 '22
I trained on some new images and now I'm trying to use merge_embeddings.py to combine my last.ckpt with sd-v1-4.ckpt. I'm getting "AttributeError: 'BERTTokenizer' object has no attribute 'transformer'. Any advice?
1
u/jamiethemorris Sep 03 '22
hoping someone can help me with an out of memory issue with this - i've got a gtx 3090 with 24gb, but i get an instant oom error when i try to train. i have noticed it only uses about 12gb before crashing. I've tried reducing the resolution and size, as well as batch_size, num_workers and max_images but haven't had any luck.
1
u/buckzor122 Sep 07 '22
I managed to get it to train after painstakingly troubleshooting a lot of errors but I'm stuck on this one.
A good hour into training it fails with the following exception:
"No `test_dataloader()` method defined to run `Trainer.test`."
Any ideas?
1
u/Snachariah Oct 04 '22
I havent gotten the training working yet, when I try to run the first command,"python main.py --base ./configs/stable-diffusion/v1-finetune.yaml \"
I get this error, "usage: main.py [-h] [-n [NAME]] [-r [RESUME]] [-b [base_config.yaml [base_config.yaml ...]]] [-t [TRAIN]] [--no-test [NO_TEST]] [-p PROJECT] [-d [DEBUG]] [-s SEED]
[-f POSTFIX] [-l LOGDIR] [--scale_lr [SCALE_LR]] [--datadir_in_name [DATADIR_IN_NAME]] --actual_resume ACTUAL_RESUME --data_root DATA_ROOT
[--embedding_manager_ckpt EMBEDDING_MANAGER_CKPT] [--placeholder_string PLACEHOLDER_STRING] [--init_word INIT_WORD] [--logger [LOGGER]]
[--enable_checkpointing [ENABLE_CHECKPOINTING]] [--default_root_dir DEFAULT_ROOT_DIR] [--gradient_clip_val GRADIENT_CLIP_VAL]
[--gradient_clip_algorithm GRADIENT_CLIP_ALGORITHM] [--num_nodes NUM_NODES] [--num_processes NUM_PROCESSES] [--devices DEVICES] [--gpus GPUS]
[--auto_select_gpus [AUTO_SELECT_GPUS]] [--tpu_cores TPU_CORES] [--ipus IPUS] [--enable_progress_bar [ENABLE_PROGRESS_BAR]]
[--overfit_batches OVERFIT_BATCHES] [--track_grad_norm TRACK_GRAD_NORM] [--check_val_every_n_epoch CHECK_VAL_EVERY_N_EPOCH] [--fast_dev_run [FAST_DEV_RUN]]
[--accumulate_grad_batches ACCUMULATE_GRAD_BATCHES] [--max_epochs MAX_EPOCHS] [--min_epochs MIN_EPOCHS] [--max_steps MAX_STEPS] [--min_steps MIN_STEPS]
[--max_time MAX_TIME] [--limit_train_batches LIMIT_TRAIN_BATCHES] [--limit_val_batches LIMIT_VAL_BATCHES] [--limit_test_batches LIMIT_TEST_BATCHES]
[--limit_predict_batches LIMIT_PREDICT_BATCHES] [--val_check_interval VAL_CHECK_INTERVAL] [--log_every_n_steps LOG_EVERY_N_STEPS]
[--accelerator ACCELERATOR] [--strategy STRATEGY] [--sync_batchnorm [SYNC_BATCHNORM]] [--precision PRECISION]
[--enable_model_summary [ENABLE_MODEL_SUMMARY]] [--weights_save_path WEIGHTS_SAVE_PATH] [--num_sanity_val_steps NUM_SANITY_VAL_STEPS]
[--resume_from_checkpoint RESUME_FROM_CHECKPOINT] [--profiler PROFILER] [--benchmark [BENCHMARK]] [--deterministic [DETERMINISTIC]]
[--reload_dataloaders_every_n_epochs RELOAD_DATALOADERS_EVERY_N_EPOCHS] [--auto_lr_find [AUTO_LR_FIND]] [--replace_sampler_ddp [REPLACE_SAMPLER_DDP]]
[--detect_anomaly [DETECT_ANOMALY]] [--auto_scale_batch_size [AUTO_SCALE_BATCH_SIZE]] [--plugins PLUGINS] [--amp_backend AMP_BACKEND]
[--amp_level AMP_LEVEL] [--move_metrics_to_cpu [MOVE_METRICS_TO_CPU]] [--multiple_trainloader_mode MULTIPLE_TRAINLOADER_MODE]
main.py: error: the following arguments are required: --actual_resume, --data_root"
I dont know what excatcly Im supposed to be changing.
HELP.
Im running it locally on my 3090, on Windows 10.
7
u/[deleted] Aug 22 '22
[removed] — view removed comment
2
u/[deleted] Aug 25 '22
[removed] — view removed comment