Skip to content

Add DuCa dual feature caching as a CacheMixin.enable_cache option - #34

Open
remyx-ai[bot] wants to merge 2 commits into
mainfrom
accelerating-diffusion-transformers-with-dual-feature-cachin-v2
Open

remyx-ai[bot] wants to merge 2 commits into
mainfrom
accelerating-diffusion-transformers-with-dual-feature-cachin-v2

Conversation

@remyx-ai

@remyx-ai remyx-ai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

What does this PR do?

Adds DuCa's training-free dual feature-caching schedule to diffusers as a new DualCacheConfig + apply_dual_cache hook, wired into the production CacheMixin.enable_cache/disable_cache dispatch (src/diffusers/models/cache_utils.py) so any DiT with a CacheMixin can skip block recomputation across denoising steps. enable_cache dispatches to apply_dual_cache on a DualCacheConfig; disable_cache removes the hooks.

What changed:

  • Implements the paper's namesake two-phase reuse: a deterministic DualCachePolicy classifies each step into compute / aggressive (reuse cached residual verbatim) / conservative (reuse with damping), with a leading full-compute step per cycle refreshing the cached full-stack residual.
  • Caches the head-to-tail block residual (output − input) after each fresh compute and re-adds it on reuse steps, with layout handling for Flux/SD3-style text+image concatenated sequences, matching the I/O contract of the sibling MagCache/FirstBlockCache hooks.
  • Adds a warmup retention_ratio (caching disabled for initial steps) and per-cycle cache invalidation, plus dummy-object stubs and __init__.py exports for the no-torch path. DualCacheConfig and apply_dual_cache are exported from the package __init__.py and reachable via pipe.transformer.enable_cache(config).

Intentionally out of scope (not needed for this contribution):

  • DuCa's ToCa selective token-wise recomputation (the core of the paper's per-token cache-error control) — replaced by a scalar conservative_scale damping proxy because the block-level hook architecture operates on whole-block residuals and cannot selectively recompute individual tokens.
  • Any learned or attention-score-driven decision of WHICH tokens/features to refresh; the schedule here is a fixed deterministic cycle rather than content-adaptive.
  • Empirical benchmark reproduction (FID/speedup tables from the paper) — no benchmark harness added, only the mechanism and unit tests.
  • Per-block (as opposed to whole-transformer-stack) residual granularity from ToCa's cache map — the implementation caches a single full-stack residual between the head and tail blocks.

Validation

Tests could not run in CI — the runner lacks this repo's dependencies (a collection/import error, not a code failure). Run the suite locally to validate.

examples/test_examples_utils.py:23: in <module>
    from accelerate.utils import write_basic_config
E   ModuleNotFoundError: No module named 'accelerate'
=========================== short test summary info ============================
ERROR examples/advanced_diffusion_training/test_dreambooth_lora_flux_advanced.py
ERROR examples/consistency_distillation/test_lcm_lora.py
ERROR examples/controlnet/test_controlnet.py
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 3 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
3 errors in 0.10s

Before submitting

  • Did you read the contributor guideline?
  • Did you write any new necessary tests?

Who can review?

@yiyixuxu @sayakpaul

Drafted by Outrider — paper: arXiv:2412.18911.

Discovery context

Implements Accelerating Diffusion Transformers with Dual Feature Caching.

Reference: https://github.com/Shenyi-Z/DuCa

License: GPL-3.0 (class: copyleft, compat: 0.50, source: github) — 🟡 review compatibility against this repo's license before merging.

Drafted by an autonomous discovery loop — Remyx ranks recent arXiv papers against this team's research interest and shipping history; Claude Code selects the candidate most directly implementable against this repo from the lookback window and drafts it.

Research interest: [crossrepo-eval] huggingface/diffusers

Why this paper for this team: Surfaced by Outrider deep-search refine query quantization diffusion transformer int8 fp8 inference acceleration against /search/assets. The engine's normal ranking did not place this paper in the interest's broad pool — it's here because the audit pass identified an under-represented theme this paper covers.

Why this candidate (selected from the lookback pool): DuCa is a training-free DiT feature-caching method (cache block features at previous timesteps, reuse at next) whose I/O contract is identical to the repo's existing MagCache/TaylorSeer/FirstBlockCache hooks; it drops in as a new DualCacheConfig + apply_dual_cache branch in the already-in-production CacheMixin.enable_cache dispatch, with no new data shape or trainer required. It carries a reference implementation (GPL-3.0), lowering porting risk versus the otherwise-equivalent no-code SpeCa [12] at the same call site.

Suggested experiment: (none)

Co-Authored-By: remyx-ai[bot] <289541483+remyx-ai[bot]@users.noreply.github.com>

@remyx-ai remyx-ai Bot added outrider:needs-judgment Outrider refinement chain stage label outrider:fidelity-done Outrider refinement chain stage label labels Sep 20, 2026
Convention-shape patches extracted from huggingface/diffusers's recent merged PRs. Algorithm logic is left untouched. Ruff auto-fixed lint-trivial issues on patched files.
@remyx-ai
remyx-ai Bot force-pushed the accelerating-diffusion-transformers-with-dual-feature-cachin-v2 branch from ff2634f to e7dbfd4 Compare September 20, 2026 14:27
@remyx-ai remyx-ai Bot removed the outrider:fidelity-done Outrider refinement chain stage label label Sep 20, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 20, 2026
@remyx-ai
remyx-ai Bot marked this pull request as ready for review September 20, 2026 14:27
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 outrider:needs-judgment Outrider refinement chain stage label tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants