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

VAE unnecessary VRAM consumption #4

Open
axel-havard opened this issue Jul 21, 2023 · 2 comments
Open

VAE unnecessary VRAM consumption #4

axel-havard opened this issue Jul 21, 2023 · 2 comments

Comments

@axel-havard
Copy link

Hi,

I was looking at the current implementation, and was noticing that before every generation you pass all reference images through the VAE as one batch. After a certain amount of references images, that would result in huge amount of VRAM needed I believe.
Wouldn't it be better to get the latents for each selected image beforehand, store them either in the RAM or on the drive temporarly, then load them on generation?
That way you avoid big batch in the VAE, and you compute the latents only once for a given reference image instead of for each generation.

What do you think ?

https://github.com/sd-fabric/fabric/blob/caaa5831bacefb060d46168372b45e3bac84a3ae/fabric/generator.py#L357C1-L373C14

@matrix4767
Copy link

Moving it to RAM sounds good.

@dvruette
Copy link
Contributor

That sounds like a reasonable tradeoff, feel free to open a PR!

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

No branches or pull requests

3 participants