Skip to content

[docs] Simplify loading guide #2694

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 6 commits into from
Apr 4, 2023
Merged

Conversation

stevhliu
Copy link
Member

This PR moves the high-level explanations in the loading guide into a separate Conceptual Guide so users can focus on executing the code more quickly. The explanatory guide is linked for users who are interested in learning more about what's happening.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 15, 2023

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

Copy link
Member Author

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

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

This is just a draft because I have some questions about variants :)

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Nice cleanup!

I really like the new "explained" doc. But I would request @patrickvonplaten to take a closer look in case I missed anything.

@patrickvonplaten
Copy link
Contributor

Hmm not too happy about the changes here. I see the benefit of simplifying the loading doc - however all the info that is deleted is very important for users. I don't think we should do a split (loading / conceptual guide here). I think we should leave everything on the loading page (which is visited a lot) and just split everything into "basic" and "advanced" use cases.

I don't think it makes sense to add a now "explanatory guide" here. IMO many users just want a quick look-up they can visit quickly to see how variants work instead of having to read through a guide/tutorial.

I see loading much closer to API doc string that is looked up a lot instead of something like a tutorial.

@stevhliu
Copy link
Member Author

Thanks for the feedback!

I've refactored to keep everything on one page (I'll delete the "explained" page once we're happy with this), and split it into practical stuff at the top and explanatory things at the bottom. I think the practical steps are important for the quick look-up without necessarily needing to know how the folder is structured and the details of the model_index.json file, for example.

But if they are interested, I added a <Tip> where they can skip to the end and get more context about how it works.

I think all the info should still be on the page, but feel free to let me know if I'm missing anything!

@patrickvonplaten
Copy link
Contributor

Ready for final review @stevhliu - should we move out of draft mode?

@stevhliu stevhliu marked this pull request as ready for review March 22, 2023 00:08
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.

Looks nice! Could we just add some more specification about the difference between variant and torch_dtype?

A checkpoint stored in [torch's half-precision / float16 format](https://pytorch.org/blog/accelerating-training-on-nvidia-gpus-with-pytorch-automatic-mixed-precision/) requires only half the bandwith and storage when downloading the checkpoint,
**but** cannot be used when continuing training or when running the checkpoint on CPU.
Similarly the *non-exponential-averaged* (or non-EMA) version of the checkpoint should be used when continuing fine-tuning of the model checkpoint, **but** should not be used when using the checkpoint for inference.
Load a variant by specifying the `variant` argument in [`DiffusionPipeline.from_pretrained`], and the `torch_dtype` if the variant is a different floating point type. 🧨 Diffusers won't download a variant unless it is explicitly specified, so you don't have to worry about downloading and caching more checkpoints than you need.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we need to be more precise I think.

variant -> this just defines what files should be loaded
torch_dtype -> this defines into what torch_dtype the weights should be converted to.

Can we maybe try to say something along the following:

Suggested change
Load a variant by specifying the `variant` argument in [`DiffusionPipeline.from_pretrained`], and the `torch_dtype` if the variant is a different floating point type. 🧨 Diffusers won't download a variant unless it is explicitly specified, so you don't have to worry about downloading and caching more checkpoints than you need.
Load a variant by specifying the `variant` argument in [`DiffusionPipeline.from_pretrained`]. 🧨 Diffusers won't download a variant unless it is explicitly specified, so you don't have to worry about unnecessarily downloading and caching more checkpoints than you need.
The `torch_dtype` argument is unrelated to the `variant` argument and decides which floating point precision the loaded checkpoints should have. If you want to save bandwidth by loading a `"fp16"` variant, you should also define `torch_dtype=torch.float16` as otherwise the fp16 weights will be converted to the default fp32 precision. Note that you can also load the original checkpoint without setting a variant and then converting it to float16 precision by passing `torch_dtype=torch.float16`. In this case you downloaded float32 weights and converted them to float16 after loading.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if the reader could understand the difference between torch_dtype and variant here (they are completely orthogonal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the explanation, this is super helpful!

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.

Looks good to me!

@stevhliu stevhliu merged commit 0d0fa2a into huggingface:main Apr 4, 2023
@stevhliu stevhliu deleted the update-loading branch April 4, 2023 21:08
w4ffl35 pushed a commit to w4ffl35/diffusers that referenced this pull request Apr 14, 2023
* simplify loading guide

* apply feedbacks

* clarify variants

* clarify torch_dtype and variant

* remove conceptual pipeline doc
dg845 pushed a commit to dg845/diffusers that referenced this pull request May 6, 2023
* simplify loading guide

* apply feedbacks

* clarify variants

* clarify torch_dtype and variant

* remove conceptual pipeline doc
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* simplify loading guide

* apply feedbacks

* clarify variants

* clarify torch_dtype and variant

* remove conceptual pipeline doc
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.

5 participants