Skip to content

[core] download hub kernel in AttentionModuleMixin.set_attention_backend - #15075

Open
deep1blue wants to merge 2 commits into
huggingface:mainfrom
deep1blue:fix-13284-attn-module-hub-kernel
Open

deep1blue wants to merge 2 commits into
huggingface:mainfrom
deep1blue:fix-13284-attn-module-hub-kernel

Conversation

@deep1blue

@deep1blue deep1blue commented Oct 19, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #13284

AttentionModuleMixin.set_attention_backend previously validated the backend name and set processor._attention_backend, but unlike ModelMixin.set_attention_backend, it never called _check_attention_backend_requirements(backend) or _maybe_download_kernel_for_backend(backend). As a result, calling attn_module.set_attention_backend("sage_hub") (or any other hub-backed attention kernel) on an individual attention module skipped requirement checks and left kernel_fn as None, causing a runtime failure on the first forward pass.

This PR adds _check_attention_backend_requirements(backend) and _maybe_download_kernel_for_backend(backend) to AttentionModuleMixin.set_attention_backend before assigning the backend on the processor, matching ModelMixin.set_attention_backend.

(Update 9424d9bf8b addressing @DN6's review comment #discussion_r4323301567: added _check_attention_backend_requirements(backend) and test_backend_requirements_are_checked; verified locally on CPU with pytest tests/models/test_attention_dispatch.py tests/models/test_attention_processor.py -> 4 passed, 14 GPU tests skipped, ruff clean.)

Before submitting

Credits & Acknowledgments

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>
raise ValueError(f"`{backend=}` must be one of the following: " + ", ".join(available_backends))

backend = AttentionBackendName(backend.lower())
_maybe_download_kernel_for_backend(backend)

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.

We would also need to check the backend requirements

_check_attention_backend_requirements(backend)

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttentionModuleMixin.set_attention_backend does not download hub kernels

3 participants