Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controlnet training #2545

Merged
merged 66 commits into from
Mar 15, 2023
Merged

Controlnet training #2545

merged 66 commits into from
Mar 15, 2023

Conversation

Ttl
Copy link
Contributor

@Ttl Ttl commented Mar 3, 2023

Adds controlnet training code, script for adding controlnet to an existing model and short readme.

I trained successfully a circle filling controlnet with this code using GPU with 8 GB VRAM.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 3, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow super cool job @Ttl !

Think we can merge this very soon - @williamberman would you like to take a look as well and test the script a bit? :-)

It would also be nice if:

  • We only save the controlnet to avoid that every training run copies all the SDv1-5 weights again. We should then maybe also automatically create a READEM that marks SDv1-5 as the base model. See here and here
  • It would be great to only have one training script that does everything in once - we usually don't add auxiliary scripts
  • Could we maybe also some image logging to the script and run the pipeline in the end? Could we show some examples of the model in the README?

Super excited about this!

  • Could we maybe add a bit more data to the

@Ttl
Copy link
Contributor Author

Ttl commented Mar 3, 2023

I'm not sure how useful the automatic upload to hub is in this case. Training a controlnet requires much more work than Dreambooth or textual inversion. It requires making a new dataset and the amount of required training is much higher. I haven't used it myself and just copied it from existing training scripts. In my opinion it could be removed entirely.

@isamu-isozaki
Copy link
Contributor

Thanks for this pr!

@williamberman
Copy link
Contributor

"During the training, we randomly replace 50% text prompts ct with empty strings"

Maybe I'm missing it, but I don't see text prompts being dropped?

@williamberman
Copy link
Contributor

I see a few cli args that aren't used such as sample_batch_size and prior_loss_weight. Can we make sure that the config only applies to this training script?

@Ttl
Copy link
Contributor Author

Ttl commented Mar 7, 2023

Text prompts are not dropped. I didn't see it used in the original training code with this dataset.

I looked into image logging but I don't have enough VRAM to make it work. It should be possible to free enough VRAM to run the pipeline but it doesn't seem to work automatically.

Automatic readme generation for upload isn't maybe too useful for controlnet since they require preprocessor for the control image and it isn't possible to automatically document it.

@patrickvonplaten
Copy link
Contributor

Amazing job @Ttl and @williamberman - thanks a lot for putting this together - this will be very useful!

@williamberman could you maybe upload the images to a dataset on the Hub and load from there? We don't want to make the github heavy by adding images (this would otherwise be in the git history forever)

Apart from this good to merge for me!

@williamberman williamberman merged commit 79eb3d0 into huggingface:main Mar 15, 2023
@giorgio130
Copy link

Thanks a lot for this example! I noticed that when using xformers==0.0.17, the training for the circle filling example does not seem to get anywhere, according to https://github.com/lllyasviel/ControlNet/blob/main/docs/train.md with a batch size of 4 it should already give sensible results after 4000 steps, but in my case I'm at 8000 and still it fumbles with circles of random sizes and positions. Has anyone tried this combination successfully?

@patrickvonplaten
Copy link
Contributor

cc @yiyixuxu here

w4ffl35 pushed a commit to w4ffl35/diffusers that referenced this pull request Apr 14, 2023
* Controlnet training code initial commit

Works with circle dataset: https://github.com/lllyasviel/ControlNet/blob/main/docs/train.md

* Script for adding a controlnet to existing model

* Fix control image transform

Control image should be in 0..1 range.

* Add license header and remove more unused configs

* controlnet training readme

* Allow nonlocal model in add_controlnet.py

* Formatting

* Remove unused code

* Code quality

* Initialize controlnet in training script

* Formatting

* Address review comments

* doc style

* explicit constructor args and submodule names

* hub dataset

NOTE -  not tested

* empty prompts

* add conditioning image

* rename

* remove instance data dir

* image_transforms -> -1,1 . conditioning_image_transformers -> 0, 1

* nits

* remove local rank config

I think this isn't necessary in any of our training scripts

* validation images

* proportion_empty_prompts typo

* weight copying to controlnet bug

* call log validation fix

* fix

* gitignore wandb

* fix progress bar and resume from checkpoint iteration

* initial step fix

* log multiple images

* fix

* fixes

* tracker project name configurable

* misc

* add controlnet requirements.txt

* update docs

* image labels

* small fixes

* log validation using existing models for pipeline

* fix for deepspeed saving

* memory usage docs

* Update examples/controlnet/train_controlnet.py

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/train_controlnet.py

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* remove extra is main process check

* link to dataset in intro paragraph

* remove unnecessary paragraph

* note on deepspeed

* Update examples/controlnet/README.md

Co-authored-by: Patrick von Platen <[email protected]>

* assert -> value error

* weights and biases note

* move images out of git

* remove .gitignore

---------

Co-authored-by: William Berman <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* Controlnet training code initial commit

Works with circle dataset: https://github.com/lllyasviel/ControlNet/blob/main/docs/train.md

* Script for adding a controlnet to existing model

* Fix control image transform

Control image should be in 0..1 range.

* Add license header and remove more unused configs

* controlnet training readme

* Allow nonlocal model in add_controlnet.py

* Formatting

* Remove unused code

* Code quality

* Initialize controlnet in training script

* Formatting

* Address review comments

* doc style

* explicit constructor args and submodule names

* hub dataset

NOTE -  not tested

* empty prompts

* add conditioning image

* rename

* remove instance data dir

* image_transforms -> -1,1 . conditioning_image_transformers -> 0, 1

* nits

* remove local rank config

I think this isn't necessary in any of our training scripts

* validation images

* proportion_empty_prompts typo

* weight copying to controlnet bug

* call log validation fix

* fix

* gitignore wandb

* fix progress bar and resume from checkpoint iteration

* initial step fix

* log multiple images

* fix

* fixes

* tracker project name configurable

* misc

* add controlnet requirements.txt

* update docs

* image labels

* small fixes

* log validation using existing models for pipeline

* fix for deepspeed saving

* memory usage docs

* Update examples/controlnet/train_controlnet.py

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/train_controlnet.py

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* remove extra is main process check

* link to dataset in intro paragraph

* remove unnecessary paragraph

* note on deepspeed

* Update examples/controlnet/README.md

Co-authored-by: Patrick von Platen <[email protected]>

* assert -> value error

* weights and biases note

* move images out of git

* remove .gitignore

---------

Co-authored-by: William Berman <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* Controlnet training code initial commit

Works with circle dataset: https://github.com/lllyasviel/ControlNet/blob/main/docs/train.md

* Script for adding a controlnet to existing model

* Fix control image transform

Control image should be in 0..1 range.

* Add license header and remove more unused configs

* controlnet training readme

* Allow nonlocal model in add_controlnet.py

* Formatting

* Remove unused code

* Code quality

* Initialize controlnet in training script

* Formatting

* Address review comments

* doc style

* explicit constructor args and submodule names

* hub dataset

NOTE -  not tested

* empty prompts

* add conditioning image

* rename

* remove instance data dir

* image_transforms -> -1,1 . conditioning_image_transformers -> 0, 1

* nits

* remove local rank config

I think this isn't necessary in any of our training scripts

* validation images

* proportion_empty_prompts typo

* weight copying to controlnet bug

* call log validation fix

* fix

* gitignore wandb

* fix progress bar and resume from checkpoint iteration

* initial step fix

* log multiple images

* fix

* fixes

* tracker project name configurable

* misc

* add controlnet requirements.txt

* update docs

* image labels

* small fixes

* log validation using existing models for pipeline

* fix for deepspeed saving

* memory usage docs

* Update examples/controlnet/train_controlnet.py

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/train_controlnet.py

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* Update examples/controlnet/README.md

Co-authored-by: Sayak Paul <[email protected]>

* remove extra is main process check

* link to dataset in intro paragraph

* remove unnecessary paragraph

* note on deepspeed

* Update examples/controlnet/README.md

Co-authored-by: Patrick von Platen <[email protected]>

* assert -> value error

* weights and biases note

* move images out of git

* remove .gitignore

---------

Co-authored-by: William Berman <[email protected]>
Co-authored-by: Sayak Paul <[email protected]>
Co-authored-by: Patrick von Platen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants