Skip to content

[Model Card] standardize dreambooth model card #6729

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

Merged
merged 14 commits into from
Feb 7, 2024

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Jan 27, 2024

What does this PR do?

An attempt to partially fix #5667 by starting to standardize the creation of model card in the train_dreambooth.py script. An immediate follow-up of #6678 as well. @linoytsaban FYI as well.

I have taken the liberty to fix some type annotations as well.

Generated model card: https://huggingface.co/sayakpaul/test-model-card-template-dreambooth

Notebook to test: https://huggingface.co/sayakpaul/test-model-card-template-dreambooth/blob/main/test_dreambooth_model_card.ipynb (hosted on Hub and I demand a gift for using the Hub to host the notebook :v)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@linoytsaban
Copy link
Collaborator

linoytsaban commented Jan 29, 2024

@sayakpaul thanks for the mention! Direct use will be used for a code example showing how to inference with diffusers?

@sayakpaul
Copy link
Member Author

No, those will have to be changed by the model developer. We don't automatically generate "direct use" for all model cards. I think it's okay not to and edit them manually. But I don't think it should be a strict requirement. This is because for ControlNet training it's different direct use, for DreamBooth training, it's different direct use. Hope that make sense.

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.

Thanks for following up with the updates that quickly! Would favor not adding kwargs here to the function signature - apart from this, the PR looks great to me!

Can we update the other example scripts as well?

@sayakpaul
Copy link
Member Author

@patrickvonplaten I am not a big fan of kwargs either, but if you see how we're creating the card from the script:

model_card = load_or_create_model_card(
    repo_id_or_path=repo_id,
    license="creativeml-openrail-m",
    base_model=base_model,
    instance_prompt=prompt,
    model_description=model_description,
    inference=True,
)

Should we make everything explicit in the signature? Do we really need to? Or maybe we could just validate with a decorator and keep the kwargs specific to the training script only. I think the second one is a more lenient and cleaner approach.

Once we settle on that, I will update the example scripts where we create model cards. For the ones, that don't, they can be done in a separate PR, preferably by the community.

@sayakpaul sayakpaul requested a review from yiyixuxu January 31, 2024 09:15
Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

the code looks good to me once @patrickvonplaten 's comments are addressed

Why did we decide to use the default model card template? this https://huggingface.co/sayakpaul/test-model-card-template-dreambooth doesn't look very nice with so many empty fields

@sayakpaul
Copy link
Member Author

the code looks good to me once @patrickvonplaten 's comments are addressed

Well my questions need to be addressed first :D #6729 (comment)

Why did we decide to use the default model card template? this https://huggingface.co/sayakpaul/test-model-card-template-dreambooth doesn't look very nice with so many empty fields

It’s the standard one I followed following trainers from other libraries. I think we can iterate on the template in future PRs. Ccing @younesbelkada to check if he has anything to suggest from the TRL world.

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Feb 1, 2024

@sayakpaul

Well my questions need to be addressed first :D #6729 (comment)

ahhh you're absolutely right!! sorry I misread your code🙈
I'm in favor of making the signature explicit and only adding arguments that are needed. I'm also in favor of a template that only has the minimum number of fields that we need:)

I think we should decide on a template in this PR, though. The goal here is to standardize model cards, and the template is a super important part of it, no?

@sayakpaul
Copy link
Member Author

You are right. I will get to the changes.

@younesbelkada
Copy link
Contributor

It’s the standard one I followed following trainers from other libraries. I think we can iterate on the template in future PRs. Ccing @younesbelkada to check if he has anything to suggest from the TRL world.

Indeed that's what we use by default in transformers too ! If you prefer you could also set an empty model card instead of using a template

@sayakpaul
Copy link
Member Author

If you prefer you could also set an empty model card instead of using a template

Do you have a reference?

@sayakpaul
Copy link
Member Author

@yiyixuxu WDYT about the recent changes? :)

Example: https://huggingface.co/sayakpaul/test-model-card-template-dreambooth.

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Feb 5, 2024

@sayakpaul
I like that:)

@sayakpaul
Copy link
Member Author

I am now going to propagate the changes to the rest of the scripts and will ask for a review once done. Thanks!

@sayakpaul
Copy link
Member Author

Comment on lines -78 to +82
base_model=str,
base_model: str = None,
train_text_encoder=False,
instance_prompt=str,
validation_prompt=str,
instance_prompt=None,
validation_prompt=None,
Copy link
Member Author

Choose a reason for hiding this comment

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

Was having compulsion disorder :3 So, decided to fix these.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would even update to this 😄

    base_model: Optional[str] = None,
    train_text_encoder: bool = False,
    instance_prompt: Optional[str] = None,
    validation_prompt: Optional[str] = None,

@sayakpaul
Copy link
Member Author

sayakpaul commented Feb 5, 2024

@yiyixuxu this is up for another review. I decided to standardize the DreamBooth scripts and the Custom Diffusion script.

Will open the rest for the community. WDYT?

Copy link
Collaborator

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Thanks for working on that @sayakpaul! Looks good to me :) Added a few nit comments + suggestion to add the <Gallery/> component to nicely display examples in the model card.

Comment on lines -78 to +82
base_model=str,
base_model: str = None,
train_text_encoder=False,
instance_prompt=str,
validation_prompt=str,
instance_prompt=None,
validation_prompt=None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would even update to this 😄

    base_model: Optional[str] = None,
    train_text_encoder: bool = False,
    instance_prompt: Optional[str] = None,
    validation_prompt: Optional[str] = None,

widget=widget_str,
),
template_path=MODEL_CARD_TEMPLATE_PATH,
model_description=model_description,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If widget is populated, I would automatically add a </Gallery> tag to the model card description like done in https://huggingface.co/Pclanglais/Mickey-1928/blob/main/README.md?code=true. It will nicely render example images in a gallery (see here) and you wouldn't have to manually build a img_str in your notebook example. What do you think? :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

(maybe only if widget is not none and "<gallery>/" not in model_description)

Copy link
Member Author

Choose a reason for hiding this comment

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

That means the existing save_model_card will have to be rewritten a bit to support compatibility with </Gallery>. I propose not to do that in this PR as it differs in scope.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine for me!

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thank you:)

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Feb 6, 2024

SDXL looks like so: https://huggingface.co/sayakpaul/test-sdxl-lora-dreambooth-model-card.

these [to-do] fields are intended to be filled manually by users, right?

Copy link
Collaborator

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Thanks @sayakpaul! Looks good 🔥

@sayakpaul sayakpaul merged commit 76696dc into main Feb 7, 2024
@sayakpaul sayakpaul deleted the standarize-mcard-dreambooth branch February 7, 2024 09:37
@bamps53 bamps53 mentioned this pull request Feb 7, 2024
6 tasks
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* feat: standarize model card creation for dreambooth training.

* correct 'inference

* remove comments.

* take component out of kwargs

* style

* add: card template to have a leaner description.

* widget support.

* propagate changes to train_dreambooth_lora

* propagate changes to custom diffusion

* make widget properly type-annotated
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.

[Hub + Examples] Standardize model cards in the training scripts
7 participants