mingyi456 commited on
Commit
69c6c80
·
verified ·
1 Parent(s): f2263a3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +86 -3
README.md CHANGED
@@ -1,3 +1,86 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - lodestones/Chroma
5
+ base_model_relation: quantized
6
+ language:
7
+ - en
8
+ pipeline_tag: text-to-image
9
+ library_name: diffusers
10
+ ---
11
+ For more information (including how to compress models yourself), check out https://huggingface.co/DFloat11 and https://github.com/LeanModels/DFloat11
12
+
13
+ This is my first time using DF11 to compress a model outside the Flux architecture. The process for compressing Flux-based models is much more straightforward as compared to other architectures because the compression code requires a `pattern_dict` as input, but the original [example code](https://github.com/LeanModels/DFloat11/tree/master/examples/compress_flux1) only provides it for Flux, which meant I had to learn the notation myself and modify it to fit other models. At least Chroma is just a pruned version of Flux, so it was relatively simple to derive the correct `pattern_dict` this time. Do let me know if you run into any problems.
14
+
15
+ This is the `pattern_dict` I used for compression:
16
+ ```python
17
+ pattern_dict = {
18
+ "transformer_blocks\.\d+": (
19
+ "attn.to_q",
20
+ "attn.to_k",
21
+ "attn.to_v",
22
+ "attn.add_k_proj",
23
+ "attn.add_v_proj",
24
+ "attn.add_q_proj",
25
+ "attn.to_out.0",
26
+ "attn.to_add_out",
27
+ "ff.net.0.proj",
28
+ "ff.net.2",
29
+ "ff_context.net.0.proj",
30
+ "ff_context.net.2",
31
+ ),
32
+ "single_transformer_blocks\.\d+": (
33
+ "proj_mlp",
34
+ "proj_out",
35
+ "attn.to_q",
36
+ "attn.to_k",
37
+ "attn.to_v",
38
+ ),
39
+ }
40
+ ```
41
+
42
+ ### How to Use
43
+
44
+ #### `diffusers`
45
+
46
+ 1. Install the DFloat11 pip package *(installs the CUDA kernel automatically; requires a CUDA-compatible GPU and PyTorch installed)*:
47
+
48
+ ```bash
49
+ pip install dfloat11[cuda12]
50
+ # or if you have CUDA version 11:
51
+ # pip install dfloat11[cuda11]
52
+ ```
53
+ 2. To use the DFloat11 model, run the following example code in Python:
54
+ ```python
55
+ import torch
56
+ from diffusers import ChromaPipeline, ChromaTransformer2DModel
57
+ from dfloat11 import DFloat11Model
58
+ from transformers.modeling_utils import no_init_weights
59
+ with no_init_weights():
60
+ transformer = ChromaTransformer2DModel.from_config(
61
+ ChromaTransformer2DModel.load_config(
62
+ "lodestones/Chroma",
63
+ subfolder="transformer"
64
+ ),
65
+ torch_dtype=torch.bfloat16
66
+ ).to(torch.bfloat16)
67
+
68
+ pipe = Cosmos2TextToImagePipeline.from_pretrained(
69
+ "lodestones/Chroma",
70
+ transformer=transformer,
71
+ torch_dtype=torch.bfloat16
72
+ )
73
+ DFloat11Model.from_pretrained("mingyi456/chroma-unlocked-v48-detail-calibrated-DF11", device='cpu', bfloat16_model=pipe.transformer)
74
+ pipe.enable_model_cpu_offload()
75
+ prompt = "A high-fashion close-up portrait of a blonde woman in clear sunglasses. The image uses a bold teal and red color split for dramatic lighting. The background is a simple teal-green. The photo is sharp and well-composed, and is designed for viewing with anaglyph 3D glasses for optimal effect. It looks professionally done."
76
+ negative_prompt = "low quality, ugly, unfinished, out of focus, deformed, disfigure, blurry, smudged, restricted palette, flat colors"
77
+ image = pipe(
78
+ prompt,
79
+ negative_prompt=negative_prompt,
80
+ generator=torch.Generator("cpu").manual_seed(0)
81
+ ).images[0]
82
+ image.save("chroma-unlocked-v48-detail-calibrated.png")
83
+ ```
84
+ #### ComfyUI
85
+ ~~Follow the instructions (have not tested myself) here: https://github.com/LeanModels/ComfyUI-DFloat11~~
86
+ Currently, this model will not work with ComfyUI out of the box, because the custom node currently only supports Flux models. It should be possible to modify the code to successfully load this model as well, but it requires another `pattern_dict` that is of a completely different form compared to the one used to compress the model. If you are interested in running this model in ComfyUI, please try to contact the developer to request support.