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

Best way to work around xformers backwards K limit on sm80/86/89 devices #1829

Closed
hafriedlander opened this issue Dec 26, 2022 · 7 comments
Closed
Labels
stale Issues that haven't received updates

Comments

@hafriedlander
Copy link
Contributor

XFormers currently can't run backwards on many Sm80/86/89 devices. It runs fine at any size on A100s, but on other devices in the class (including common ones like 3080, 3090, 4090) it only works backwards when dim_heads <= 64.

This is a pretty narrow use case (most people don't run backwards as standard inference doesn't need it, and SD2 and greater have dim_heads <= 64 for all layers), and kind of working around a bug in xformers, so I'm not sure if there should be a specific API to support working around this issue.

If this is appropriate to include in DIffusers, any preference on an API? (My naive though is to add a max_dim_head argument to set_use_memory_efficient_attention_xformers). I'm happy to do a PR if an API is agreed.

@hafriedlander
Copy link
Contributor Author

Here's some logic I wrote that detects the issue (for Diffusers 0.10.x) - https://github.com/cloneofsimo/lora/blob/bc497114969a629c0cf909c0a5837d1dacb6909f/lora_diffusion/xformers_utils.py

It's similar to the test in https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py#L120 but deliberately runs backwards, and checks per dimhead.

Any opinion on whether this should be in Diffusers @patil-suraj or @patrickvonplaten ?

@patil-suraj
Copy link
Contributor

As you said, it's a narrow use case, so I'm not sure if we should handle this in diffusers. I think it's okay to let it fail explicitly during backward if it not working. Maybe open an issue in xformers to see if they have any plans for this.

@hafriedlander
Copy link
Contributor Author

There is already an issue facebookresearch/xformers#563 - TLDR; they aren't planning on fixing it any time soon.

The downside is that Dreambooth and other training will fail on SD1.5 based models with xformers on, in a way that isn't well documented or communicated.

It's relatively easy to detect the error, and you already have a "does xformers work reliably" test in unet. My personal vote would be that the training scripts at least should have a test & warning if user tries to enable xformers when it won't work.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Jan 29, 2023
@qslug
Copy link

qslug commented Feb 3, 2023

This is (at least partly) fixed now as part of facebookresearch/xformers@615175f.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot closed this as completed Mar 7, 2023
@litaotju
Copy link

litaotju commented Mar 8, 2023

It's a known issue of xformers library on 30x GPUs, try install the dev version of the xformers.
This works on my 3060.

pip install xformers==0.0.17.dev466

See facebookresearch/xformers#631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that haven't received updates
Projects
None yet
Development

No branches or pull requests

4 participants