InvokeAI icon indicating copy to clipboard operation
InvokeAI copied to clipboard

Backport MemoryEfficientCrossAttention from Stability-AI/stablediffusion

Open knoopx opened this issue 3 years ago • 6 comments

this is just a copy and paste from original https://github.com/Stability-AI/stablediffusion codebase. it effectively enables cross attention optimizations via https://github.com/facebookresearch/xformers on invokeai (my 3090 ti goes from 10it/s to 18it/s. still the time from interaction to result is slightly slower than https://github.com/AUTOMATIC1111/stable-diffusion-webui, there's probably more room for optimizations.

knoopx avatar Dec 02 '22 17:12 knoopx

xformers is also supported by the attention models in diffusers, so this is something we get with #1583.

Or more accurately: that diffusers PR uses xformers if it is installed. Installing it is still a piece of work that will need to be added to the release packages.

keturn avatar Dec 02 '22 17:12 keturn

@keturn installing xformers is as easy as conda install xformers -c xformers/label/dev, at least on linux (pre-compiled binaries!).

knoopx avatar Dec 02 '22 17:12 knoopx

@keturn installing xformers is as easy as conda install xformers -c xformers/label/dev, at least on linux (pre-compiled binaries!).

It's quite the headache on Mac and Windows where most of the user base is. So gotta work through it.

blessedcoolant avatar Dec 02 '22 17:12 blessedcoolant

ok reworked the PR to only include MemoryEfficientCrossAttention and is only activated if xformers is present. tested with and without on my linux machine and works, can't test on other platforms however. btw totally supporting switching to diffusers (honestly ldm codebase is not the greatest) but i think some will appreciate this patch meanwhile diffusers work is ready.

knoopx avatar Dec 02 '22 18:12 knoopx

@knoopx;

installing xformers is as easy as conda install xformers -c xformers/label/dev, at least on linux (pre-compiled binaries!).

Not everyone uses Conda

tildebyte avatar Dec 03 '22 19:12 tildebyte

thanks for the contribution, but i think we should hold off on this until diffusers gets merged.

damian0815 avatar Dec 03 '22 22:12 damian0815

The following part of the code must be changed before this can be merged: https://github.com/invoke-ai/InvokeAI/blob/ce17051b28c7d08560c4f0f102888633933ae83d/ldm/models/diffusion/cross_attention_control.py#L344 Also, regarding xFormers installation, check this https://github.com/invoke-ai/InvokeAI/pull/2360#issuecomment-1396178695

snake-4 avatar Jan 18 '23 23:01 snake-4

I believe this PR has been superseded. OK to close?

lstein avatar Feb 02 '23 19:02 lstein

closed

damian0815 avatar Feb 02 '23 19:02 damian0815