Skip to content

feat: implement cache_context for pab and fastercache. - #14900

Open
sayakpaul wants to merge 7 commits into
mainfrom
refactor-pab-fastercache
Open

sayakpaul wants to merge 7 commits into
mainfrom
refactor-pab-fastercache

Conversation

@sayakpaul

@sayakpaul sayakpaul commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

In #14663, we decided to move away from using pipeline states in caching (through callbacks). This PR propagates the same for PAB and FasterCache.

As a result of the changes, the changeset looks bigger. But the core changes are in:

  • src/diffusers/hooks/faster_cache.py
  • src/diffusers/hooks/pyramid_attention_broadcast.py
  • tests/models/testing_utils/cache.py
  • tests/pipelines/testing_utils/cache.py

We also deprecate current_timestep_callback argument on both FasterCache and PAB.

@github-actions github-actions Bot added documentation Improvements or additions to documentation models tests modular-pipelines pipelines hooks size/L PR with diff > 200 LOC labels Sep 29, 2026
@sayakpaul

Copy link
Copy Markdown
Member Author

/diffusers-bot pytest tests/models -k "cache"

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ pytest tests/models -k "cache" passed on GPU — view logs.

@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.

Comment thread tests/pipelines/test_pipelines_common.py Outdated
Comment thread src/diffusers/hooks/faster_cache.py
@sayakpaul sayakpaul added this to the Release 0.42.0 milestone Oct 5, 2026
@sayakpaul

Copy link
Copy Markdown
Member Author

/diffusers-bot pytest tests/models -k "cache"

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

✅ pytest tests/models -k "cache" passed on GPU — view logs.

self.tensor_format = tensor_format
self.is_guidance_distilled = is_guidance_distilled

self.current_timestep_callback = current_timestep_callback

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ohh I think since we are deprecate on 0.45.0, I think we need to make sure the current code (using callback etc) still works until then, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Resolved for PAB, too. Added a simple test as well.



@pytest.mark.parametrize("context_name", [None, "cond"])
def test_timestep_is_required_without_callback(model, config_kwargs, inputs, context_name):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is for the case when a pipeline doesn't implement the context and a user doesn't pass the callback either.

callback = Mock(side_effect=AssertionError)
with pytest.warns(FutureWarning, match="current_timestep_callback"):
config = config_class(**kwargs, current_timestep_callback=callback)
model.enable_cache(config)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When a user configures a timestep callback in the cache config class, they will already get the deprecation notice. If the model has the cache context configured with timestep, then we fall back to it.

Otherwise, we use the deprecated behaviour. If neither of them is configured, we raise (tested in test_timestep_is_required_without_callback).

Should we also log a warning when both are configured (the callback and the caching context with timestep)? I don't think it's necessary.

@sayakpaul
sayakpaul requested a review from yiyixuxu October 7, 2026 03:30

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants