Repository navigation
Conversation
AttentionModuleMixin.set_attention_backend only stored the backend on the processor and never fetched the hub kernel, unlike ModelMixin.set_attention_backend. For hub backends (e.g. sage_hub) the kernel stayed unloaded and the call failed at the first forward pass. Call _maybe_download_kernel_for_backend before setting the backend and add a regression test using a stubbed kernels.get_kernel. Fixes huggingface#13284 Signed-off-by: Parth Vadera <parthvadera@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
DN6
reviewed
Oct 20, 2026
| raise ValueError(f"`{backend=}` must be one of the following: " + ", ".join(available_backends)) | ||
|
|
||
| backend = AttentionBackendName(backend.lower()) | ||
| _maybe_download_kernel_for_backend(backend) |
Collaborator
There was a problem hiding this comment.
We would also need to check the backend requirements
Call _check_attention_backend_requirements(backend) before downloading the hub kernel in AttentionModuleMixin.set_attention_backend to match ModelMixin.set_attention_backend, and add a unit test covering missing backend requirements. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Parth Vadera <parthvadera@gmail.com>
|
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. |
This branch has not been deployed
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_backendpreviously validated the backend name and setprocessor._attention_backend, but unlikeModelMixin.set_attention_backend, it never called_check_attention_backend_requirements(backend)or_maybe_download_kernel_for_backend(backend). As a result, callingattn_module.set_attention_backend("sage_hub")(or any other hub-backed attention kernel) on an individual attention module skipped requirement checks and leftkernel_fnasNone, causing a runtime failure on the first forward pass.This PR adds
_check_attention_backend_requirements(backend)and_maybe_download_kernel_for_backend(backend)toAttentionModuleMixin.set_attention_backendbefore assigning the backend on the processor, matchingModelMixin.set_attention_backend.(Update
9424d9bf8baddressing @DN6's review comment #discussion_r4323301567: added_check_attention_backend_requirements(backend)andtest_backend_requirements_are_checked; verified locally on CPU withpytest tests/models/test_attention_dispatch.py tests/models/test_attention_processor.py-> 4 passed, 14 GPU tests skipped,ruffclean.)Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
tests/models/test_attention_dispatch.py::TestAttentionModuleSetAttentionBackend)Credits & Acknowledgments
AttentionModuleMixin.set_attention_backendomitting_maybe_download_kernel_for_backend(backend)unlikeModelMixin.set_attention_backend), @DN6 for pointing out_check_attention_backend_requirements(backend), as well as @adityasingh2400 (Fix AttentionModuleMixin.set_attention_backend skipping hub kernel download聽#13783) and @Whning0513 (Fix set_attention_backend skipping hub kernel download聽#13995) for their earlier PRs addressing this issue.