mingyi456 commited on
Commit
0b3ecbf
·
verified ·
1 Parent(s): a32b1f5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -1
README.md CHANGED
@@ -9,4 +9,80 @@ pipeline_tag: text-to-image
9
  library_name: diffusers
10
  tags:
11
  - diffusion-single-file
12
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  library_name: diffusers
10
  tags:
11
  - diffusion-single-file
12
+ ---
13
+ ### Note: Despite the "FP16" in the filename, the original weights [in this repo](https://huggingface.co/cyberdelia/CyberRealisticFlux) are actually in BF16 instead, which makes them safe for DF11 compression.
14
+ For more information (including how to compress models yourself), check out https://huggingface.co/DFloat11 and https://github.com/LeanModels/DFloat11
15
+
16
+ Feel free to request for other models for compression as well, although models whose architecture I am unfamiliar with might be slightly tricky for me.
17
+
18
+ ### How to Use
19
+
20
+ #### `diffusers`
21
+
22
+ 1. Install the DFloat11 pip package *(installs the CUDA kernel automatically; requires a CUDA-compatible GPU and PyTorch installed)*:
23
+
24
+ ```bash
25
+ pip install dfloat11[cuda12]
26
+ # or if you have CUDA version 11:
27
+ # pip install dfloat11[cuda11]
28
+ ```
29
+ 2. Download the [CyberRealistic_Flux_V2.5_FP16-DF11.safetensors](https://huggingface.co/mingyi456/CyberRealisticFlux-DF11/resolve/main/CyberRealistic_Flux_V2.5_FP16-DF11.safetensors) file and place it in a local directory of your choice.
30
+ 3. To use the DFloat11 model, run the following example code in Python:
31
+ ```python
32
+ import torch
33
+ from diffusers import FluxPipeline, FluxTransformer2DModel
34
+ from dfloat11 import DFloat11Model
35
+ pattern_dict = {
36
+ "transformer_blocks\.\d+" : (
37
+ "norm1.linear",
38
+ "norm1_context.linear",
39
+ "attn.to_q",
40
+ "attn.to_k",
41
+ "attn.to_v",
42
+ "attn.add_k_proj",
43
+ "attn.add_v_proj",
44
+ "attn.add_q_proj",
45
+ "attn.to_out.0",
46
+ "attn.to_add_out",
47
+ "ff.net.0.proj",
48
+ "ff.net.2",
49
+ "ff_context.net.0.proj",
50
+ "ff_context.net.2",
51
+ ),
52
+ "single_transformer_blocks\.\d+" : (
53
+ "norm.linear",
54
+ "proj_mlp",
55
+ "proj_out",
56
+ "attn.to_q",
57
+ "attn.to_k",
58
+ "attn.to_v",
59
+ )
60
+ }
61
+ with no_init_weights():
62
+ transformer = FluxTransformer2DModel.from_config(
63
+ FluxTransformer2DModel.load_config(
64
+ "black-forest-labs/FLUX.1-dev",
65
+ subfolder="transformer"
66
+ ),
67
+ torch_dtype=torch.bfloat16
68
+ ).to(torch.bfloat16)
69
+
70
+ pipe = FluxPipeline.from_pretrained(
71
+ "black-forest-labs/FLUX.1-dev",
72
+ transformer=transformer,
73
+ torch_dtype=torch.bfloat16
74
+ )
75
+ DFloat11Model.from_single_file('CyberRealisticFlux-DF11/CyberRealistic_Flux_V2.5_FP16-DF11.safetensors', device='cpu', bfloat16_model=pipe.transformer, pattern_dict=pattern_dict) # Make sure to download the file first, and edit the filepath accordingly
76
+ pipe.enable_model_cpu_offload()
77
+ prompt = "A beautiful woman with fair skin and long, messy blonde hair styled in a high ponytail with dramatic, face-framing bangs, her green eyes glinting under a cheeky, smirking expression, subtle head tilt adds playful confidence, she wears a translucent, form-fitting dress that clings tastefully to her silhouette, heavy yet refined makeup accentuating her eyes and lips, captured in a blend of long shot and medium close-up for cinematic focus, bathed in warm sunset glow casting soft golden highlights on her skin and hair, rich depth of field, high-detail realism with sensual elegance and atmospheric lighting"
78
+ image = pipe(
79
+ prompt,
80
+ guidance_scale=3.5,
81
+ num_inference_steps=30,
82
+ max_sequence_length=256,
83
+ generator=torch.Generator("cpu").manual_seed(0)
84
+ ).images[0]
85
+ image.save("CyberRealistic_Flux_V2.5_FP16-DF11.png")
86
+ ```
87
+ #### ComfyUI
88
+ Refer to this [model](https://huggingface.co/mingyi456/CyberRealisticFlux-DF11-ComfyUI) instead.