Skip to content
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

Support pass kwargs to cogvideox custom attention processor #10456

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

huanngzh
Copy link
Contributor

@huanngzh huanngzh commented Jan 5, 2025

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:

class CustomCogVideoXAttnProcessor2_0:
    def __init__(self, **custom_args):
        super().__init__()
        # some initialization
    
    def __call__(self, ..., added_argu=None) -> torch.FloatTensor:
        # custom attention forward pass

custom_processor = CustomCogVideoXAttnProcessor2_0(**custom_args)
pipe.transformer.set_attn_processor(custom_processor) # cogvideox pipeline
attention_kwargs = {"added_argu": 100} # prepare passing added_argu to attention processor
pipe.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

@sayakpaul sayakpaul requested a review from a-r-r-o-w January 5, 2025 12:07
@huanngzh huanngzh requested a review from yiyixuxu January 7, 2025 12:12
Copy link
Member

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@HuggingFaceDocBuilderDev

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.

@huanngzh huanngzh requested a review from yiyixuxu January 9, 2025 04:14
Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

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:main Jan 9, 2025
12 checks passed
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.

4 participants