Skip to content

ZImageControlNet cfg#13080

Open
hlky wants to merge 1 commit intohuggingface:mainfrom
hlky:z-image-controlnet-cfg
Open

ZImageControlNet cfg#13080
hlky wants to merge 1 commit intohuggingface:mainfrom
hlky:z-image-controlnet-cfg

Conversation

@hlky
Copy link
Contributor

@hlky hlky commented Feb 4, 2026

What does this PR do?

Code

import torch
from diffusers import ZImageControlNetPipeline
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.to("cuda")

control_image = load_image(
    "https://huggingface.co/alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union/resolve/main/asset/pose.jpg?download=true"
)
prompt = "一位年轻女子站在阳光明媚的海岸线上,白裙在轻拂的海风中微微飘动。她拥有一头鲜艳的紫色长发,在风中轻盈舞动,发间系着一个精致的黑色蝴蝶结,与身后柔和的蔚蓝天空形成鲜明对比。她面容清秀,眉目精致,透着一股甜美的青春气息;神情柔和,略带羞涩,目光静静地凝望着远方的地平线,双手自然交叠于身前,仿佛沉浸在思绪之中。在她身后,是辽阔无垠、波光粼粼的大海,阳光洒在海面上,映出温暖的金色光晕。"
negative_prompt = " "
image = pipe(
    prompt,
    negative_prompt=negative_prompt,
    control_image=control_image,
    controlnet_conditioning_scale=0.75,
    height=1728,
    width=992,
    num_inference_steps=9,
    guidance_scale=2.0,
    generator=torch.Generator("cuda").manual_seed(43),
).images[0]
image.save("zimage.png")

Output

Note: Optimal guidance_scale values and negative prompt are unknown

zimage

Notes

Fix is from original code

Fixes #13073

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@sayakpaul @christopher5106

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@christopher5106
Copy link

I confirm that there is no more error, thanks

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.

ZImageControlNetPipeline does not support guidance_scale>1

4 participants