Fix AttentionModuleMixin.set_attention_backend skipping hub kernel download#13783
Open
adityasingh2400 wants to merge 1 commit into
Open
Conversation
…wnload The per-submodule set_attention_backend on AttentionModuleMixin only validated the backend name and updated self.processor._attention_backend, but skipped the _check_attention_backend_requirements and _maybe_download_kernel_for_backend calls that ModelMixin.set_attention_backend performs. As a result, hub-based backends like sage_hub were silently set without the kernel ever being downloaded, and inference failed later with TypeError: 'NoneType' object is not callable inside dispatch_attention_fn. This mirrors the requirement-check and kernel-download path from ModelMixin into the submodule-level setter so per-block backend overrides work for hub kernels. Fixes huggingface#13284
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #13284.
AttentionModuleMixin.set_attention_backend(src/diffusers/models/attention.py) validated the backend name and setself.processor._attention_backend, but skipped the_check_attention_backend_requirements(...)and_maybe_download_kernel_for_backend(...)calls thatModelMixin.set_attention_backend(src/diffusers/models/modeling_utils.py) performs. As a result, applying a hub backend likesage_hubonly to individual attention submodules silently left the kernel registry uninitialized and inference crashed later withTypeError: 'NoneType' object is not callableinsidedispatch_attention_fn.The fix mirrors the requirement-check and kernel-download steps into the submodule setter so per-block backend overrides work for hub kernels too.
Reproduction
The repro from the issue (
Wan-AI/Wan2.1-T2V-1.3B-Diffusers+ per-submodulesage_hub) now runs through inference without theNoneTypecrash, and the underlying_HUB_KERNELS_REGISTRYentry forsage_hubis populated as expected.Tests
Added a regression test in
tests/models/test_attention_processor.py::AttentionModuleMixinSetBackendTeststhat:set_attention_backend("sage_hub")on a minimalAttentionModuleMixininstance and asserts both_check_attention_backend_requirementsand_maybe_download_kernel_for_backendare invoked with the resolved backend (usingunittest.mock.patchso no kernel download or GPU is required), and thatprocessor._attention_backendis updated;ValueError.Both tests pass on the fix and fail on
main(verified by temporarily reverting the source change).Before submitting
Who can review?
@yiyixuxu @DN6 @sayakpaul