fix: do not leak set_attention_backend into process-wide registry#14250
Open
Solaris-star wants to merge 2 commits into
Open
fix: do not leak set_attention_backend into process-wide registry#14250Solaris-star wants to merge 2 commits into
Solaris-star wants to merge 2 commits into
Conversation
Model.set_attention_backend() already pins the backend on each of this model's attention processors. Flipping _AttentionBackendRegistry's active backend made other models with unset per-module backends pick up the same backend (e.g. FA3 + attn_mask on an unrelated model). Leave the global active backend alone; use attention_backend() when a temporary process-wide override is intended. Fixes huggingface#14249 Signed-off-by: Solaris-star <820622658@qq.com>
Regression coverage for huggingface#14249 / huggingface#14250. Signed-off-by: Solaris-star <820622658@qq.com>
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?
ModelMixin.set_attention_backend()already pins the backend on this model's attention processors. It also called_AttentionBackendRegistry.set_active_backend(), which is process-global.Any other model whose per-module backend is still
Nonethen falls through to that global backend indispatch_attention_fn. Example: model A sets FA3; model B later runs withattn_maskand unexpectedly hits FA3, which rejects the mask.This PR stops flipping the global registry from
set_attention_backend(). Per-module pins stay. Useattention_backend(...)when a temporary process-wide override is intentional.Fixes #14249
Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Self-review notes
set_attention_backendif maintainers want it.attention_backend()context manager is unchanged.Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.