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

[docs] Improved inpaint docs #5210

Merged
merged 7 commits into from
Oct 6, 2023
Merged

Conversation

stevhliu
Copy link
Member

Part of #4758 to update the inpainting guide to be more extensive and in-depth

@stevhliu stevhliu marked this pull request as ready for review September 28, 2023 19:19
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.

Nice start, left some comments

docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
Comment on lines +593 to 601
Running diffusion models is computationally expensive and intensive, but with a few optimization tricks, it is entirely possible to run them on consumer and free-tier GPUs. For example, you can use a more memory-efficient form of attention such as PyTorch 2.0's [scaled-dot product attention](../optimization/torch2.0#scaled-dot-product-attention) or [xFormers](../optimization/xformers) (you can use one or the other, but there's no need to use both). You can also offload the model to the GPU while the other pipeline components wait on the CPU.

```diff
+ pipeline.enable_model_cpu_offload()
+ pipeline.enable_xformers_memory_efficient_attention()
```

With [`torch.compile`](optimization/torch2.0#torch.compile), you can boost your inference speed even more by wrapping your UNet with it:
With [`torch.compile`](../optimization/torch2.0#torch.compile), you can boost your inference speed even more by wrapping your UNet with it:

Copy link
Member

Choose a reason for hiding this comment

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

I feel like we're using this block of text across many guides now. How can we focus more on the objectives of the guides themselves and redirect users for the optimization related details, instead?

(Doesn't need to be addressed in this PR and I am open to brainstorming)

Comment on lines +549 to +579
## Optimize

It can be difficult and slow to run diffusion models if you're resource constrained, but it dosen't have to be with a few optimization tricks. One of the biggest (and easiest) optimizations you can enable is switching to memory-efficient attention. If you're using PyTorch 2.0, [scaled-dot product attention](../optimization/torch2.0#scaled-dot-product-attention) is automatically enabled and you don't need to do anything else. For non-PyTorch 2.0 users, you can install and use [xFormers](../optimization/xformers)'s implementation of memory-efficient attention. Both options reduce memory usage and accelerate inference.

You can also offload the model to the GPU to save even more memory:

```diff
+ pipeline.enable_xformers_memory_efficient_attention()
+ pipeline.enable_model_cpu_offload()
```

To speed-up your inference code even more, use [`torch_compile`](../optimization/torch2.0#torch.compile). You should wrap `torch.compile` around the most intensive component in the pipeline which is typically the UNet:

```py
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
```

Learn more in the [Reduce memory usage](../optimization/memory) and [Torch 2.0](../optimization/torch2.0) guides.
Copy link
Member

Choose a reason for hiding this comment

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

Yeah after this section, I definitely think we should think a bit more about how we can organize and distribute these components that are heavily reused across different docs.

(Doesn't have to be addressed in this PR).

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.

Thank you for the changes!

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.

awesome, thank you!

docs/source/en/using-diffusers/inpaint.md Outdated Show resolved Hide resolved
docs/source/en/using-diffusers/inpaint.md Show resolved Hide resolved
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 2, 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.

Nice that works for me - it would be great though to make sure that we only change .md files here :-)

@stevhliu stevhliu merged commit f0a2c63 into huggingface:main Oct 6, 2023
11 checks passed
@stevhliu stevhliu deleted the inpaint-docs branch October 6, 2023 16:44
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* start

* finish draft

* add section

* edits

* feedback

* make fix-copies

* rebase
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