Skip to content

Fix attention backend leaking across models - #14335

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

Fix attention backend leaking across models#14335
raghulchandramouli wants to merge 2 commits 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??

@DN6 DN6 left a comment

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.

Thanks 馃憤馃徑

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

@raghulchandramouli

Copy link
Copy Markdown
Author

hello @DN6 both of these issues being raised are not becuz of me, its an Anima mismatch error which was never touched by me

@raghulchandramouli
raghulchandramouli requested a review from DN6 August 10, 2026 14:13
@raghulchandramouli

Copy link
Copy Markdown
Author

Hi @DN6, I updated this PR to the latest main, but two unrelated CI jobs
remain failing:

  • Fast PyTorch Modular Pipeline CPU tests: only
    TestQwenImageEditModularPipelineFast::test_num_images_per_prompt timed out
    after 60 seconds; 648 tests passed.
  • Torch CUDA Tests (models): 22 MiniMax-H3 tests failed. These failures
    are being addressed separately in [tests] fix minimax h3 test failures聽#14421.

This PR does not modify MiniMax-H3 or modular pipeline code. GitHub does not
allow me to rerun the jobs because rerunning requires repository admin
access.

Could you please rerun the failed jobs, or advise whether the MiniMax-H3
failure can be ignored until #14421 is merged? Thanks!

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

3 participants