Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/en/api/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Cache methods speedup diffusion transformers by storing and reusing intermediate

[[autodoc]] apply_taylorseer_cache

## ResilPhaseCacheConfig

[[autodoc]] ResilPhaseCacheConfig

[[autodoc]] apply_resilphase_cache

## MagCacheConfig

[[autodoc]] MagCacheConfig
Expand Down
37 changes: 37 additions & 0 deletions docs/source/en/optimization/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,43 @@ config = TaylorSeerCacheConfig(
pipe.transformer.enable_cache(config)
```

## ResilPhase Cache

[ResilPhase](https://github.com/zqc214/ResilPhase) accelerates diffusion inference by mapping denoising steps to a
normalized phase axis and interpolating the residual produced by the transformer's block stack. On intermediate
steps, the predicted residual is added to the stack input while the transformer blocks are skipped. The method is
supported for FLUX and HunyuanVideo transformers.

FLUX ControlNet inference automatically falls back to full transformer block computation because ControlNet residuals
are injected between individual blocks.

Create a [`ResilPhaseCacheConfig`] and pass it to the pipeline transformer. `cache_interval` controls the interval
between full block-stack computations, `warmup_steps` initializes the interpolation history, and `max_order` controls
the number of historical residuals used by the interpolation.

```python
import torch

from diffusers import FluxPipeline, ResilPhaseCacheConfig


pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
dtype=torch.bfloat16,
).to("cuda")

config = ResilPhaseCacheConfig(
cache_interval=6,
warmup_steps=3,
max_order=1,
mapping_method="balanced",
balance_alpha=0.55,
)
pipe.transformer.enable_cache(config)

image = pipe("A cat playing chess", num_inference_steps=50).images[0]
```

## MagCache

[MagCache](https://github.com/Zehong-Ma/MagCache) accelerates inference by skipping transformer blocks based on the magnitude of the residual update. It observes that the magnitude of updates (Output - Input) decays predictably over the diffusion process. By accumulating an "error budget" based on pre-computed magnitude ratios, it dynamically decides when to skip computation and reuse the previous residual.
Expand Down
4 changes: 4 additions & 0 deletions src/diffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"LayerSkipConfig",
"MagCacheConfig",
"PyramidAttentionBroadcastConfig",
"ResilPhaseCacheConfig",
"SmoothedEnergyGuidanceConfig",
"TaylorSeerCacheConfig",
"TextKVCacheConfig",
Expand All @@ -211,6 +212,7 @@
"apply_layer_skip",
"apply_mag_cache",
"apply_pyramid_attention_broadcast",
"apply_resilphase_cache",
"apply_taylorseer_cache",
"apply_text_kv_cache",
]
Expand Down Expand Up @@ -1052,6 +1054,7 @@
LayerSkipConfig,
MagCacheConfig,
PyramidAttentionBroadcastConfig,
ResilPhaseCacheConfig,
SmoothedEnergyGuidanceConfig,
TaylorSeerCacheConfig,
TextKVCacheConfig,
Expand All @@ -1060,6 +1063,7 @@
apply_layer_skip,
apply_mag_cache,
apply_pyramid_attention_broadcast,
apply_resilphase_cache,
apply_taylorseer_cache,
apply_text_kv_cache,
)
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .layerwise_casting import apply_layerwise_casting, apply_layerwise_casting_hook
from .mag_cache import MagCacheConfig, apply_mag_cache
from .pyramid_attention_broadcast import PyramidAttentionBroadcastConfig, apply_pyramid_attention_broadcast
from .resilphase_cache import ResilPhaseCacheConfig, apply_resilphase_cache
from .smoothed_energy_guidance_utils import SmoothedEnergyGuidanceConfig
from .taylorseer_cache import TaylorSeerCacheConfig, apply_taylorseer_cache
from .text_kv_cache import TextKVCacheConfig, apply_text_kv_cache
Loading
Loading