Skip to content

[docs] Optimize and scale pt. 1 - #14867

Open
stevhliu wants to merge 5 commits into
huggingface:mainfrom
stevhliu:optimize-scale
Open

stevhliu wants to merge 5 commits into
huggingface:mainfrom
stevhliu:optimize-scale

Conversation

@stevhliu

Copy link
Copy Markdown
Member

Refreshes the Optimize and scale section:

  • add an Overview with a starter path (dtype + device → offload) and links to other optimization techniques such as kernels and quantization
  • more accurate doc titles like "Precision and compilation" that reflect what they actually teach vs a more vague promise like "Reduce memory usage"
  • adds a section to guide cache method selection and also adds TextKVCache (can remove if this is too niche, but good to document for completeness)
  • reduce noisy prose (tighter intros, fewer callouts, etc.) and more consistent navigation
  • make sure hardware/API claims (FA3/Hopper, kernels requirements) matches code

@github-actions github-actions Bot added documentation Improvements or additions to documentation size/L PR with diff > 200 LOC labels Sep 24, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@stevhliu
stevhliu requested a review from sayakpaul September 24, 2026 21:57

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Didn't review it fully but some changes are too intrusive, IMO. Hopefully, the existing comments will be helpful to get an idea of what I am talking about and help you make changes to the files I didn't review yet.


## Optimization

You can optimize the pipeline's runtime and memory consumption with torch.compile and feed-forward chunking. To learn about other optimization methods, check out the [Speed up inference](../../optimization/fp16) and [Reduce memory usage](../../optimization/memory) guides.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think precision and compilation as a title is less exciting as a reader in the sense that it doesn't tell me that it's related to speeding up of inference.

<hfoption id="memory">

Refer to the [Reduce memory usage](../../optimization/memory) guide for more details about the various memory saving techniques.
Refer to the [Memory and offloading](../../optimization/memory) guide for more details about the various memory saving techniques.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this change makes it less obvious to the reader the page is about something they would actually care about (i.e., reducing memory usage).

> The attention dispatcher is an experimental feature. Please open an issue if you have any feedback or encounter any problems.

Diffusers provides several optimized attention algorithms that are more memory and computationally efficient through it's *attention dispatcher*. The dispatcher acts as a router for managing and switching between different attention implementations and provides a unified interface for interacting with them.
Diffusers routes attention through an *attention dispatcher* so you can switch optimized backends behind one API. The dispatcher manages registered implementations and exposes a unified call path for them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some autoencoders don't use the dispatcher and its because of their internals. So, we cannot sufficiently claim that Diffusers always routes.

Diffusers routes attention through an *attention dispatcher* so you can switch optimized backends behind one API. The dispatcher manages registered implementations and exposes a unified call path for them.

Refer to the table below for an overview of the available attention families and to the [Available backends](#available-backends) section for a more complete list.
Refer to the table below for an overview of the available attention families and to the [Available backends](#available-backends) section for a more complete list. The fastest backend depends on the model, GPU, and dtype.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The input payload shape as well.

Comment on lines -29 to +30
This guide will show you how to set and use the different attention backends.
Install each backend’s own package before you enable it. The [Available backends](#available-backends) table lists package requirements Diffusers checks at enable time, plus hardware targets where they matter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We probably shouldn't say things like "install each package" because many attention backends are available through kernels and statements like this undermine that.

Comment on lines -37 to +38
> [!NOTE]
> FlashAttention-3 requires Ampere GPUs at a minimum.
The example below enables `_flash_3_hub` (FlashAttention-3 from the Hub) with `device_map="cuda"` only. FlashAttention-3 targets Hopper GPUs (for example H100 or H800). Prefer FlashAttention-2 backends such as `flash` or `flash_hub` on Ampere or Ada.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No. Flash3 is available on Amperes, too.

```

To restore the default attention backend, call [`~ModelMixin.reset_attention_backend`].
The non-Hub FlashAttention-3 backends (`_flash_3`, `_flash_varlen_3`) require building FlashAttention-3 from source. Prefer `_flash_3_hub` (or `_flash_3_varlen_hub`) when you want the Hub path with Kernels.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can also add a note that these will be deprecated soon.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/L PR with diff > 200 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants