Skip to content

Fix attention backend leaking across models - #14335

Open
raghulchandramouli wants to merge 1 commit into
huggingface:mainfrom
raghulchandramouli:fix/attention-backend-global-leak
Open

Fix attention backend leaking across models#14335
raghulchandramouli wants to merge 1 commit into
huggingface:mainfrom
raghulchandramouli:fix/attention-backend-global-leak

Conversation

@raghulchandramouli

@raghulchandramouli raghulchandramouli commented Jul 30, 2026

Copy link
Copy Markdown

What does this PR do?

In a nutshell, It Prevents ModelMixin.set_attention_backend() from changing the process-global active attention backend. The method now only configures attention processors belonging to the target model.

Self-review:

Ran self-review and these are the validation I got from it:

  • Blocking issues: None
  • Non-blocking issues: None
  • Dead code: None
  • Documentation changes required: None

Test I Ran:

  • Regression tests for Flux and QwenImage: all passed
  • make style: passed
  • make fix-copies: passed
  • git diff --check: passed

Test I wrote:

  • Added a regression test in tests/attention.py to make sure that ModelMixin.set_attention_backend() does not modify the registry.

discussion

This appears as an issue raised by sayak Paul - #14249

Fixes #14249

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?
  • Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?

It would be great if @qgallouedec or @sayakpaul can you take a quick review of this PR??

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.

set_attention_backend on one model leaks globally to other models via the active-backend registry

1 participant