Skip to content

[WIP] Refactor Attention Modules #11685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

[WIP] Refactor Attention Modules #11685

wants to merge 7 commits into from

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Jun 10, 2025

What does this PR do?

Draft PR to address some issues with the attention modules.

  1. Moves a number of transformer related blocks/objects in the attention module that would have a better home under models/transformers

  2. Moves the definition of the Attention module into attention.py, rather than have it live in attention_prcessors.py.

  3. We have a very large number of processors, but with Attention Dispatcher #11368 we should no longer need a good chunk of them and they can be deprecated. I think with these changes we would end up with ~3 processors per model (Attn, IPAdapter, PAG)

  4. Make it so that we can bump up our minimum supported Torch version to >=2.0 and use the F.sdpa API for all processors.

  5. There was some discussion around naming of the processors:
    https://huggingface.slack.com/archives/C065E480NN9/p1737130514639479
    We landed on calling the processors something like AttnProcessorsSDPA, but with Attention Dispatcher #11368 we no longer need to use a dedicated processor per backend, so I think it's okay to just have the class be named AttnProcessor.

  6. Move processor definitions into the model files, so we don't end up with very large files containing all processors.

  7. Introduce AttentionModuleMixin that contains all common methods related to attention operations. New attention modules would inherit from this class.

  8. Introduce an AttentionMixin for models so that methods like set_processor are not duplicated across models. Although we can probably just add the methods of this Mixin to ModelMixin

  9. Using Flux as an example here to show how we can define a single Processor to support both fused/unfused qkv projections.

Fixes # (issue)

Before submitting

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.

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.

1 participant