Skip to content

fix(attention): download hub kernel in AttentionModuleMixin.set_attention_backend#13302

Open
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/13284-attention-module-mixin-hub-download
Open

fix(attention): download hub kernel in AttentionModuleMixin.set_attention_backend#13302
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/13284-attention-module-mixin-hub-download

Conversation

@s-zx
Copy link

@s-zx s-zx commented Mar 21, 2026

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 kernels
are never downloaded and the backend silently falls back to the default.

Root Cause

AttentionModuleMixin.set_attention_backend() in attention.py validates the backend
name but does not call _check_attention_backend_requirements() or
_maybe_download_kernel_for_backend(). The top-level ModelMixin.set_attention_backend()
in modeling_utils.py already calls both helpers correctly — the submodule path was simply
missing 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 = backend

Fixes #13284

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttentionModuleMixin.set_attention_backend does not download hub kernels

2 participants