Views
No views yet
torch.nn.Conv2D tensors, even though they compress just fine, so I chose to skip compressing them, in order to avoid the need for users to manually patch the DFloat11 codebase. This makes the final compressed model ~200 MB larger than the expected size, but that is the price to pay for compatibility. Nevertheless, the reduction in VRAM footprint is still rather significant, from 5.14 GB to 3.66 GB, which should make the unet fit in 6 GB GPUs (assuming it has BF16 support).diffusers library, ComfyUI, or any other model), although models that use architectures which are unfamiliar to me might be more difficult.diffusers1pip install dfloat11[cuda12]
2# or if you have CUDA version 11:
3# pip install dfloat11[cuda11]1from diffusers import StableDiffusionXLPipeline
2from dfloat11 import DFloat11Model
3import torch
4
5pipe = StableDiffusionXLPipeline.from_single_file("https://huggingface.co/Laxhar/noobai-XL-1.1/resolve/main/NoobAI-XL-v1.1.safetensors", torch_dtype=torch.bfloat16)
6
7DFloat11Model.from_pretrained("mingyi456/noobai-XL-1.1-DF11", device = "cpu", bfloat16_model = pipe.unet)
8
9pipe.to("cuda")
10
11
12prompt = "masterpiece, best quality, newest, absurdres, highres, 1girl"
13
14negative_prompt = "worst quality, old, early, low quality, lowres, signature, username, logo, bad hands, mutated hands, mammal, anthro, furry, ambiguous form, feral, semi-anthro"
15
16image = pipe(
17 prompt=prompt,
18 negative_prompt=negative_prompt,
19 guidance_scale=5.0,
20 num_inference_steps=35,
21 width=832,
22 height=1216,
23 generator=torch.Generator("cpu").manual_seed(0)
24).images[0]
25
26image.save(r"NoobAI-XL-v1.1.png")pattern_dict for compression:1pattern_dict = {
2 r"time_embedding" : (
3 "linear_1",
4 "linear_2"
5 ),
6 r"add_embedding" : (
7 "linear_1",
8 "linear_2"
9 ),
10
11
12 r"down_blocks\.0\.resnets\.\d+" : (
13 "time_emb_proj",
14 ),
15
16 r"down_blocks\.1\.attentions\.\d+\.transformer_blocks\.\d+" : (
17 "attn1.to_q",
18 "attn1.to_k",
19 "attn1.to_v",
20 "attn1.to_out.0",
21 "attn2.to_q",
22 "attn2.to_k",
23 "attn2.to_v",
24 "attn2.to_out.0",
25 "ff.net.0.proj",
26 "ff.net.2"
27 ),
28 r"down_blocks\.1\.resnets\.0" : (
29 "time_emb_proj",
30 ),
31 r"down_blocks\.1\.resnets\.1" : (
32 "time_emb_proj",
33 ),
34 r"down_blocks\.2\.attentions\.\d+\.transformer_blocks\.\d+" : (
35 "attn1.to_q",
36 "attn1.to_k",
37 "attn1.to_v",
38 "attn1.to_out.0",
39 "attn2.to_q",
40 "attn2.to_k",
41 "attn2.to_v",
42 "attn2.to_out.0",
43 "ff.net.0.proj",
44 "ff.net.2"
45 ),
46 r"down_blocks\.2\.resnets\.0" : (
47 "time_emb_proj",
48 ),
49 r"down_blocks\.2\.resnets\.1" : (
50 "time_emb_proj",
51 ),
52
53
54 r"up_blocks\.0\.attentions\.\d+\.transformer_blocks\.\d+" : (
55 "attn1.to_q",
56 "attn1.to_k",
57 "attn1.to_v",
58 "attn1.to_out.0",
59 "attn2.to_q",
60 "attn2.to_k",
61 "attn2.to_v",
62 "attn2.to_out.0",
63 "ff.net.0.proj",
64 "ff.net.2"
65 ),
66 r"up_blocks\.0\.resnets\.\d+" : (
67 "time_emb_proj",
68 ),
69 r"up_blocks\.1\.attentions\.\d+\.transformer_blocks\.\d+" : (
70 "attn1.to_q",
71 "attn1.to_k",
72 "attn1.to_v",
73 "attn1.to_out.0",
74 "attn2.to_q",
75 "attn2.to_k",
76 "attn2.to_v",
77 "attn2.to_out.0",
78 "ff.net.0.proj",
79 "ff.net.2"
80 ),
81 r"up_blocks\.1\.resnets\.\d+" : (
82 "time_emb_proj",
83 ),
84 r"up_blocks\.2\.resnets\.\d+" : (
85 "time_emb_proj",
86 ),
87
88
89 r"mid_block\.attentions\.0\.transformer_blocks\.\d+" : (
90 "attn1.to_q",
91 "attn1.to_k",
92 "attn1.to_v",
93 "attn1.to_out.0",
94 "attn2.to_q",
95 "attn2.to_k",
96 "attn2.to_v",
97 "attn2.to_out.0",
98 "ff.net.0.proj",
99 "ff.net.2"
100 ),
101 r"mid_block\.resnets\.\d+" : (
102 "time_emb_proj",
103 )
104}