fix(attention): download hub kernel in AttentionModuleMixin.set_attention_backend#13302
Open
s-zx wants to merge 1 commit intohuggingface:mainfrom
Open
fix(attention): download hub kernel in AttentionModuleMixin.set_attention_backend#13302s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx wants to merge 1 commit intohuggingface:mainfrom
Conversation
…tion_backend ModelMixin.set_attention_backend() calls both _check_attention_backend_requirements() and _maybe_download_kernel_for_backend() before setting the backend, but AttentionModuleMixin.set_attention_backend() — used when the method is called directly on an individual attention submodule — skipped both calls. This meant that hub-based backends (e.g. "sage_hub") silently failed to download the required kernel when targeting a submodule, even though the same call worked fine on the top-level model. Add the two missing helper calls to AttentionModuleMixin.set_attention_backend(). 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.
Summary
When
set_attention_backend()is called directly on an individual attention submodule(e.g.
pipe.transformer.attn1.set_attention_backend("sage_hub")), hub-based kernelsare never downloaded and the backend silently falls back to the default.
Root Cause
AttentionModuleMixin.set_attention_backend()inattention.pyvalidates the backendname but does not call
_check_attention_backend_requirements()or_maybe_download_kernel_for_backend(). The top-levelModelMixin.set_attention_backend()in
modeling_utils.pyalready calls both helpers correctly — the submodule path was simplymissing them.
Fix
Add the two missing calls to
AttentionModuleMixin.set_attention_backend():def set_attention_backend(self, backend: str): from .attention_dispatch import ( AttentionBackendName, + _check_attention_backend_requirements, + _maybe_download_kernel_for_backend, ) ... backend = AttentionBackendName(backend.lower()) + _check_attention_backend_requirements(backend) + _maybe_download_kernel_for_backend(backend) self.processor._attention_backend = backendFixes #13284