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

ControlNets for Multi-GPU #11116

Open
ishan-modi opened this issue Mar 19, 2025 · 0 comments
Open

ControlNets for Multi-GPU #11116

ishan-modi opened this issue Mar 19, 2025 · 0 comments

Comments

@ishan-modi
Copy link
Contributor

ishan-modi commented Mar 19, 2025

Currently most of our documentation has the following way of using ControlNets

from diffusers import SanaControlNetModel, SanaControlNetPipeline
import torch

controlnet = SanaControlNetModel.from_pretrained(
    "ishan24/Sana_600M_1024px_ControlNet_diffusers",
    torch_dtype=torch.float16
)

pipe = SanaControlNetPipeline.from_pretrained(
    "Efficient-Large-Model/Sana_600M_1024px_diffusers",
    variant="fp16",
    controlnet=controlnet,
    torch_dtype=torch.float16,
)

pipe.to('cuda')
pipe.vae.to(torch.bfloat16)
pipe.text_encoder.to(torch.bfloat16)

This does work for a single GPU use case, but it is not appropriate for multi gpu, because controlnet and pipe both will have a separate device map, which causes issue related to device alignment during forward pass.

Following is how it should be documented

Single GPU

from diffusers import SanaControlNetModel, SanaControlNetPipeline
import torch

pipe = SanaControlNetPipeline.from_pretrained(
    "ishan24/Sana_600M_1024px_ControlNetPlus_diffusers",
    variant="fp16",
    torch_dtype=torch.float16
).to('cuda')

pipe.vae.to(torch.bfloat16)
pipe.text_encoder.to(torch.bfloat16)

Multi GPU

from diffusers import SanaControlNetModel, SanaControlNetPipeline
import torch

pipe = SanaControlNetPipeline.from_pretrained(
    "ishan24/Sana_600M_1024px_ControlNetPlus_diffusers",
    variant="fp16",
    torch_dtype=torch.float16,
    device_map="balanced"
)

pipe.vae.to(torch.bfloat16)
pipe.text_encoder.to(torch.bfloat16)

Let me know if my thinking is correct on this one and if we need to change Docstring
cc - @a-r-r-o-w

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

1 participant