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
5
6pattern_dict = {
7 r"noise_refiner\.\d+": (
8 "attention.to_q",
9 "attention.to_k",
10 "attention.to_v",
11 "attention.to_out.0",
12 "feed_forward.w1",
13 "feed_forward.w2",
14 "feed_forward.w3",
15 "adaLN_modulation.0"
16 ),
17 r"context_refiner\.\d+": (
18 "attention.to_q",
19 "attention.to_k",
20 "attention.to_v",
21 "attention.to_out.0",
22 "feed_forward.w1",
23 "feed_forward.w2",
24 "feed_forward.w3",
25 ),
26 r"layers\.\d+": (
27 "attention.to_q",
28 "attention.to_k",
29 "attention.to_v",
30 "attention.to_out.0",
31 "feed_forward.w1",
32 "feed_forward.w2",
33 "feed_forward.w3",
34 "adaLN_modulation.0"
35 ),
36 r"cap_embedder": (
37 "1",
38 )
39}
40
41text_encoder = DFloat11Model.from_pretrained("DFloat11/Qwen3-4B-DF11", device="cpu")
42
43with no_init_weights():
44 transformer = ZImageTransformer2DModel.from_config(
45 ZImageTransformer2DModel.load_config(
46 "Tongyi-MAI/Z-Image-Turbo", subfolder="transformer"
47 ),
48 torch_dtype=torch.bfloat16
49 ).to(torch.bfloat16)
50
51
52DFloat11Model.from_single_file(
53 r".\BEYOND REALITY SUPER Z IMAGE 2.0 淡妆浓抹总相宜 BF16-DF11.safetensors", # Make sure to download the file first, and edit the filepath accordingly
54 device='cpu',
55 bfloat16_model=transformer,
56 pattern_dict=pattern_dict
57)
58
59pipe = ZImagePipeline.from_pretrained(
60 "Tongyi-MAI/Z-Image-Turbo",
61 text_encoder=text_encoder,
62 transformer=transformer,
63 torch_dtype=torch.bfloat16,
64 low_cpu_mem_usage=False,
65)
66pipe.to("cuda")
67
68
69pattern_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}