Views
No views yet
diffusers library, ComfyUI, or any other model), although models that use architectures which are unfamiliar to me might be more difficult.diffusers1import torch
2from diffusers import ZImagePipeline, ZImageTransformer2DModel
3from dfloat11 import DFloat11Model
4from transformers.modeling_utils import no_init_weights
5text_encoder = DFloat11Model.from_pretrained("DFloat11/Qwen3-4B-DF11", device="cpu")
6with no_init_weights():
7 transformer = ZImageTransformer2DModel.from_config(
8 ZImageTransformer2DModel.load_config(
9 "Tongyi-MAI/Z-Image-Turbo", subfolder="transformer"
10 ),
11 torch_dtype=torch.bfloat16
12 ).to(torch.bfloat16)
13DFloat11Model.from_pretrained("mingyi456/Z-Image-Turbo-Art-DF11", device="cpu", bfloat16_model=transformer)
14pipe = ZImagePipeline.from_pretrained(
15 "Tongyi-MAI/Z-Image-Turbo",
16 text_encoder=text_encoder,
17 transformer=transformer,
18 torch_dtype=torch.bfloat16,
19 low_cpu_mem_usage=False,
20)
21pipe.to("cuda")
22prompt = "一张肖像照片,展示一位身着传统服饰的年轻亚裔女性站在木质室内空间(可能是寺庙或文化厅)中,她位于画面中央,面带微笑望向镜头,深色长发微微飘动。女子穿着奶油色绣金刺绣上衣,袖子蓬松,外搭一件透明刺绣衣物,左袖有星形图案。腰部系着一条红金相间的几何花纹腰带,右手胸前拿着一个红色鼓身、饰有多彩珠饰的小圆鼓。头上戴着金色叶子皇冠,点缀小珠子,佩戴彩色珠子垂坠耳环。背景左侧是雕刻精美的木质镶板,带有复杂格子设计;右侧是纹理清晰的素色木门。地面为深色木材,阳光投下斜向阴影。无可见文字。肖像摄影,温暖的黄金时刻光线,主体柔焦,浅景深,以奶油色、金色、红色和木色调为主的鲜艳色彩,高对比度,文化遗产主题,精细纺织品纹理,自然光,宁静表情,传统服饰,木质建筑,垂直构图。"
23
24image = pipe(
25 prompt=prompt,
26 height=1024,
27 width=1024,
28 num_inference_steps=11, # This actually results in 8 DiT forwards
29 guidance_scale=0.0, # Guidance should be 0 for the Turbo models
30 generator=torch.Generator("cuda").manual_seed(42),
31).images[0]
32image.save("example.png")pattern_dict for compression:1pattern_dict = {
2 r"noise_refiner\.\d+": (
3 "attention.to_q",
4 "attention.to_k",
5 "attention.to_v",
6 "attention.to_out.0",
7 "feed_forward.w1",
8 "feed_forward.w2",
9 "feed_forward.w3",
10 "adaLN_modulation.0"
11 ),
12 r"context_refiner\.\d+": (
13 "attention.to_q",
14 "attention.to_k",
15 "attention.to_v",
16 "attention.to_out.0",
17 "feed_forward.w1",
18 "feed_forward.w2",
19 "feed_forward.w3",
20 ),
21 r"layers\.\d+": (
22 "attention.to_q",
23 "attention.to_k",
24 "attention.to_v",
25 "attention.to_out.0",
26 "feed_forward.w1",
27 "feed_forward.w2",
28 "feed_forward.w3",
29 "adaLN_modulation.0"
30 ),
31 r"cap_embedder": (
32 "1",
33 )
34}