Skip to content

Add ResilPhase cache support for FLUX and HunyuanVideo - #14419

Open
zqc214 wants to merge 1 commit into
huggingface:mainfrom
zqc214:add-resilphase-cache
Open

Add ResilPhase cache support for FLUX and HunyuanVideo#14419
zqc214 wants to merge 1 commit into
huggingface:mainfrom
zqc214:add-resilphase-cache

Conversation

@zqc214

@zqc214 zqc214 commented Aug 8, 2026

Copy link
Copy Markdown

What does this PR do?

Adds native ResilPhase cache support through the existing Diffusers Hook and CacheMixin APIs. ResilPhase predicts the residual produced by a denoiser transformer block stack with barycentric Lagrange interpolation on a normalized phase axis, allowing intermediate denoising steps to skip the transformer blocks.

This PR:

  • adds ResilPhaseCacheConfig and apply_resilphase_cache;
  • exposes ResilPhase through transformer.enable_cache(...) and disable_cache();
  • supports balanced and Chebyshev phase mappings;
  • keeps cache state isolated through cache_context;
  • covers FLUX and HunyuanVideo two-stream transformer stacks;
  • falls back to full computation for FLUX ControlNet inputs because their residuals are injected between blocks;
  • adds public API and optimization documentation;
  • adds algorithm, Hook, model, and pipeline tests.

Closes #14378. The coordination issue was opened and relevant maintainers were tagged; this PR is being submitted directly at the contributor request before maintainer acknowledgement.

Usage

from diffusers import FluxPipeline, ResilPhaseCacheConfig

pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev")
pipe.transformer.enable_cache(
    ResilPhaseCacheConfig(
        cache_interval=6,
        warmup_steps=3,
        max_order=1,
        mapping_method="balanced",
    )
)

Tests

PYTHONPATH=src python -m pytest -q \
  tests/hooks/test_resilphase_cache.py \
  tests/models/transformers/test_models_transformer_flux.py::TestFluxTransformerResilPhaseCache \
  tests/models/transformers/test_models_transformer_hunyuan_video.py::TestHunyuanVideoTransformerResilPhaseCache \
  tests/pipelines/flux/test_pipeline_flux.py::TestFluxPipelineResilPhaseCache \
  tests/pipelines/hunyuan_video/test_hunyuan_video.py::HunyuanVideoPipelineFastTests::test_resilphase_cache_inference

26 passed

make quality
All checks passed; 2022 files already formatted.

make repo-consistency reaches the current upstream utils/check_repo.py and then fails because that script imports the nonexistent diffusers.models.auto; the failure is reproducible on the upstream base and is unrelated to this diff.

AI-assisted contribution and self-review

Codex was used to inspect the reference implementations, implement the Hook-based integration, add tests/docs, and run verification.

Final self-review:

  • Blocking issues: none.
  • Non-blocking: full-checkpoint FLUX/HunyuanVideo wall-clock and generation-quality benchmarks were not run; coverage uses numerical interpolation tests, real model classes with small configs, and small end-to-end pipeline tests.
  • Dead code: none found. Public config/apply APIs are wired through lazy imports and CacheMixin; all private Hooks/helpers and tester mixins are exercised.
  • Verdict: READY.

Before submitting

@github-actions github-actions Bot added fixes-issue documentation Improvements or additions to documentation models tests utils hooks size/L PR with diff > 200 LOC and removed fixes-issue labels Aug 8, 2026
@zqc214

zqc214 commented Aug 8, 2026

Copy link
Copy Markdown
Author

Hi maintainers, thanks for reviewing this PR.
Could you please approve the pending workflows when convenient?

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 hooks models size/L PR with diff > 200 LOC tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add native ResilPhase cache support for FLUX and HunyuanVideo

1 participant