Skip to content

Support pass kwargs to cogvideox custom attention processor - #10456

Merged
yiyixuxu merged 3 commits into
huggingface:mainfrom
huanngzh:main
Jan 9, 2025
Merged

Support pass kwargs to cogvideox custom attention processor#10456
yiyixuxu merged 3 commits into
huggingface:mainfrom
huanngzh:main

Conversation

@huanngzh

@huanngzhhuanngzh commented Jan 5, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Pass kwargs to custom attention processor is preferable when implementing layout control, attention replacing or introducing side effect to attention computation. Now this feature is supported by sd, sdxl, FLUX, sd3 series, but not CogVideoX. This PR fix the problem, and may support future training-free experiments in CogVideoX series models.

Example code:

classCustomCogVideoXAttnProcessor2_0:
def__init__(self, **custom_args):
super().__init__()
# some initializationdef__call__(self, ..., added_argu=None) ->torch.FloatTensor:
# custom attention forward passcustom_processor=CustomCogVideoXAttnProcessor2_0(**custom_args)
pipe.transformer.set_attn_processor(custom_processor) # cogvideox pipelineattention_kwargs= {"added_argu": 100} # prepare passing added_argu to attention processorpipe.transformer(..., attention_kwargs=attention_kwargs) # custom transformer forward pass

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.

Hello @yiyixuxu@sayakpaul, I just want to do the same to CogVideoX as to FLUX in #9517 and to SD3 in #9818

Comment threadsrc/diffusers/models/attention_processor.py Outdated
@huanngzh
huanngzh requested a review from yiyixuxuJanuary 7, 2025 12:12

@a-r-r-o-wa-r-r-o-w left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/diffusers/models/attention_processor.py Outdated
@huanngzh
huanngzh requested a review from yiyixuxuJanuary 9, 2025 04:14

@yiyixuxuyiyixuxu 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!

@yiyixuxu
yiyixuxu merged commit 7116fd2 into huggingface:mainJan 9, 2025
Sign up for freeto 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.

4 participants

@huanngzh@HuggingFaceDocBuilderDev@yiyixuxu@a-r-r-o-w