-
Notifications
You must be signed in to change notification settings - Fork 6.6k
z-image-turbo controlnet correct device placement #12886
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
base: main
Are you sure you want to change the base?
Conversation
|
@vladmandic Thanks, I didn't test with offloading, but it seems unusual for this to happen, the ControlNet layers are created in the normal way and I don't recall this being needed in other ControlNet models which do work with offloading afaik. Do you have code for a reproduction? |
|
not easy reproduction as behavior differs in different environments, torch version, etc. |
|
@vladmandic I've tracked this to an issue with Code
import torch
from diffusers import ZImageControlNetPipeline, ZImagePipeline
from diffusers import ZImageControlNetModel
from diffusers.utils import load_image
from huggingface_hub import hf_hub_download
controlnet = ZImageControlNetModel.from_single_file(
hf_hub_download(
"alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union",
filename="Z-Image-Turbo-Fun-Controlnet-Union.safetensors",
),
torch_dtype=torch.bfloat16,
)
pipe = ZImageControlNetPipeline.from_pretrained(
"Tongyi-MAI/Z-Image-Turbo", controlnet=controlnet, torch_dtype=torch.bfloat16, variant="bf16",
revision="refs/pr/102",
)
pipe.enable_model_cpu_offload()
control_image = load_image(
"https://huggingface.co/alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union/resolve/main/asset/pose.jpg?download=true"
)
prompt = "一位年轻女子站在阳光明媚的海岸线上,白裙在轻拂的海风中微微飘动。她拥有一头鲜艳的紫色长发,在风中轻盈舞动,发间系着一个精致的黑色蝴蝶结,与身后柔和的蔚蓝天空形成鲜明对比。她面容清秀,眉目精致,透着一股甜美的青春气息;神情柔和,略带羞涩,目光静静地凝望着远方的地平线,双手自然交叠于身前,仿佛沉浸在思绪之中。在她身后,是辽阔无垠、波光粼粼的大海,阳光洒在海面上,映出温暖的金色光晕。"
image = pipe(
prompt,
control_image=control_image,
controlnet_conditioning_scale=0.75,
height=1728,
width=992,
num_inference_steps=9,
guidance_scale=0.0,
generator=torch.Generator("cuda").manual_seed(43),
).images[0]Interestingly in my tests (on Traceback
So I'm not sure this PR would help in that case. After reviewing accelerate changelog in 1.10.0 I've tracked it further to this specific commit huggingface/accelerate#3695 which was also discussed on diffusers #11872 - Given that it provided a negligible benefit and has seemingly broken offloading I think it should be raised with accelerate team and reverted. I'm surprised this issue has not been noticed before, and I wonder if other controlnet models are affected. Have your users reported any issues with other models? In the meantime I would suggest your users install cc @SunMarc |
z-image-turbo controlnet implementation in #12792 includes some manually created torch modules and dicts which by default are created on
cpuwhile context used in the controlnet loop is ongpudepending on offloading strategy and/or use of accelerate, this this results in typical error:
i've traced device placement to couple of critical execution paths which when corrected allow execution of z-image-turbo controlnet without issues.
cc: @hlky @yiyixuxu @DN6 @sayakpaul