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

feat: Automatic attention slicing when slice size is set to 0 #51

Merged

Conversation

sagar-a16z
Copy link
Contributor

Add support for automatic attention slicing based on the huggingface diffusers implementation https://github.com/huggingface/diffusers/blob/91925fbb761d944d54271660c4c3cffee55798fa/examples/community/stable_diffusion_mega.py#L96-L113

examples/stable-diffusion/main.rs Outdated Show resolved Hide resolved
src/models/unet_2d.rs Outdated Show resolved Hide resolved
@LaurentMazare
Copy link
Owner

Looks good, thanks! Could you just give a bit more details about the testing that you did? (typically if you can generate images with/without the features and check that they compare well, that's great)

@sagar-a16z
Copy link
Contributor Author

I tested it with the following command:

cargo run --target=aarch64-apple-darwin --example stable-diffusion --features clap -- --prompt "A very rusty robot holding a fire torch." --sliced-attention-size 0 --cpu unet --cpu clip

Here's the output:
image

Here's the outuput without sliced-attention-size 0

cargo run --target=aarch64-apple-darwin --example stable-diffusion --features clap -- --prompt "A very rusty robot holding a fire torch." --cpu unet --cpu clip

output:
image

The performance difference on my m1 mac is staggering...The first run finished in less then 2 minutes. Without attention slicing it takes over 10 minutes.

@LaurentMazare LaurentMazare merged commit 08d668b into LaurentMazare:main Mar 1, 2023
@LaurentMazare
Copy link
Owner

Neat, that's some impressive speedup! Thanks for the PR!

@sagar-a16z sagar-a16z deleted the automatic_attention_slicing branch March 1, 2023 17:06
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.

None yet

2 participants