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

Dynamic Resolution Compilation #94

Closed
chavinlo opened this issue Feb 9, 2023 · 6 comments
Closed

Dynamic Resolution Compilation #94

chavinlo opened this issue Feb 9, 2023 · 6 comments

Comments

@chavinlo
Copy link

chavinlo commented Feb 9, 2023

Hello, is it possible to compile the model for dynamic resolution generation rather than static? Similar to TensorRT's?
I see in the code that the compilation call is made either if the model hasn't been compiled already OR the request is for a different resolution than the already compilated one.

@strint
Copy link
Collaborator

strint commented Feb 10, 2023

Compiling a dynamic shape graph is not supported right now. We use some optimization skills which are related to static input shape:

  • memory static allocation;
  • constant folding;

Have you met some problems with static shapes?

@chavinlo
Copy link
Author

Have you met some problems with static shapes?

No, but we are building a service that plans to offer dynamic resolutions.
I was thinking of compiling it for multiple resolutions, but that would take up vram space

@chavinlo
Copy link
Author

Please let me know if this feature is ever implemented. Thanks

@strint
Copy link
Collaborator

strint commented Feb 13, 2023

Please let me know if this feature is ever implemented. Thanks

We provide an offline-compile mode to reduce online-compile time for scenarios where the input shapes of online inference is limited. Hope this will help: https://github.com/Oneflow-Inc/diffusers/wiki/How-to-Run-OneFlow-Stable-Diffusion#optimization-for-multi-resolution-picture

@chavinlo

@chavinlo
Copy link
Author

Please let me know if this feature is ever implemented. Thanks

We provide an offline-compile mode to reduce online-compile time for scenarios where the input shapes of online inference is limited. Hope this will help: https://github.com/Oneflow-Inc/diffusers/wiki/How-to-Run-OneFlow-Stable-Diffusion#optimization-for-multi-resolution-picture

@chavinlo

Thanks. First I call pipe.enable_graph_share_mem(), then run inference on the resolutions I want, and the graph should be ready for those resolutions right?

pipe.enable_graph_share_mem()

prompt = "a photo of an astronaut riding a horse on mars, red sky, (green sky:1.5)"
with torch.autocast("cuda"):
    images = pipe(prompt, height=1024).images
    images = pipe(prompt, height=768).images
    images = pipe(prompt, height=512).images
    images = pipe(prompt, height=256).images

sorting the input shape from large to small to trigger graph compilation

I see that it takes 1 second to load when it changes resolution:

    images = pipe(prompt, height=256).images
    images = pipe(prompt, height=256).images
    images = pipe(prompt, height=512).images
    images = pipe(prompt, height=512).images
    images = pipe(prompt, height=768).images
    images = pipe(prompt, height=768).images
    images = pipe(prompt, height=1024).images
    images = pipe(prompt, height=1024).images
    images = pipe(prompt, height=768).images
    images = pipe(prompt, height=768).images
    images = pipe(prompt, height=512).images
    images = pipe(prompt, height=512).images
    images = pipe(prompt, height=256).images
    images = pipe(prompt, height=256).images

Is there anyway to speed this up? or maybe mantain all of them active? I don't mind having to use more vram.

@strint
Copy link
Collaborator

strint commented Feb 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants