ChrisGoringe
commited on
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: black-forest-labs/FLUX.1-dev
|
3 |
+
---
|
4 |
+
|
5 |
+
*Note that all these models are derivatives of black-forest-labs/FLUX.1-dev and therefore covered by the
|
6 |
+
[FLUX.1 [dev] Non-Commercial License](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md) license.*
|
7 |
+
|
8 |
+
*Some models are derivatives of finetunes, and are included with the permission of the finetuner*
|
9 |
+
|
10 |
+
# Optimised Flux GGUF models
|
11 |
+
|
12 |
+
A collection of GGUF models using mixed quantization (different layers quantized to different precision to optimise fidelity v. memory).
|
13 |
+
|
14 |
+
They can be loaded in ComfyUI using the [ComfyUI GGUF Nodes](https://github.com/city96/ComfyUI-GGUF). Put the gguf files in your
|
15 |
+
model/unet directory.
|
16 |
+
|
17 |
+
## Naming convention (mx for 'mixed')
|
18 |
+
|
19 |
+
[original_model_name]_mxNN_N.gguf
|
20 |
+
|
21 |
+
where NN_N is the approximate reduction in VRAM usage compared the full 16 bit version.
|
22 |
+
|
23 |
+
- 9_0 might just fit on a 16GB card
|
24 |
+
- 10_6 is a good balance for 16GB cards,
|
25 |
+
- 12_0 is roughly the size of an 8 bit model,
|
26 |
+
- 14_1 should work for 12 GB cards
|
27 |
+
- 15_2 is fully quantised to Q4_1
|
28 |
+
|
29 |
+
## How is this optimised?
|
30 |
+
|
31 |
+
The process for optimisation is as follows:
|
32 |
+
|
33 |
+
- 240 prompts used for flux images popular at civit.ai were run through the full Flux.1-dev model
|
34 |
+
- The hidden states before the start of the double_layer_blocks and after the end of the single_layer_blocks were captured
|
35 |
+
- The layer stack was then modified by quantizing one layer to one of Q8_0, Q5_1 or Q4_1
|
36 |
+
- The initial hidden states were then processed by the modified layer stack, and the error (MSE) in the final hidden state calculated
|
37 |
+
- This gives a 'cost' of each possible layer quantization
|
38 |
+
- An optimised quantization is one that gives the desired reduction in size for the smallest total cost
|
39 |
+
- A series of recipies for optimization have been created from the calculated costs
|
40 |
+
- the various 'in' blocks, the final layer blocks, and all normalization scale parameters are stored in float32
|
41 |
+
|
42 |
+
## Also note
|
43 |
+
|
44 |
+
- Tests on using bitsandbytes quantizations showed they did not perform as well as the equivalent sized GGUF quants
|
45 |
+
- Different quantizations of different parts of a layer gave significantly worse results
|
46 |
+
- Leaving bias in 16 bit made no relevant difference
|
47 |
+
- Costs were evaluated for the original Flux.1-dev model. They are assumed to be essentially the same for finetunes
|
48 |
+
|
49 |
+
## Details
|
50 |
+
|
51 |
+
The optimisation recipes are as follows (layers 0-18 are the double_block_layers, 19-56 are the single_block_layers)
|
52 |
+
|
53 |
+
```python
|
54 |
+
|
55 |
+
CONFIGURATIONS = {
|
56 |
+
"9_0" : {
|
57 |
+
'casts': [
|
58 |
+
{'layers': '0-10', 'castto': 'BF16'},
|
59 |
+
{'layers': '11-14, 54', 'castto': 'Q8_0'},
|
60 |
+
{'layers': '15-36, 39-53, 55', 'castto': 'Q5_1'},
|
61 |
+
{'layers': '37-38, 56', 'castto': 'Q4_1'},
|
62 |
+
]
|
63 |
+
},
|
64 |
+
"10_6" : {
|
65 |
+
'casts': [
|
66 |
+
{'layers': '0-4, 10', 'castto': 'BF16'},
|
67 |
+
{'layers': '5-9, 11-14', 'castto': 'Q8_0'},
|
68 |
+
{'layers': '15-35, 41-55', 'castto': 'Q5_1'},
|
69 |
+
{'layers': '36-40, 56', 'castto': 'Q4_1'},
|
70 |
+
]
|
71 |
+
},
|
72 |
+
"12_0" : {
|
73 |
+
'casts': [
|
74 |
+
{'layers': '0-2', 'castto': 'BF16'},
|
75 |
+
{'layers': '5, 7-12', 'castto': 'Q8_0'},
|
76 |
+
{'layers': '3-4, 6, 13-33, 42-55', 'castto': 'Q5_1'},
|
77 |
+
{'layers': '34-41, 56', 'castto': 'Q4_1'},
|
78 |
+
]
|
79 |
+
},
|
80 |
+
"14_1" : {
|
81 |
+
'casts': [
|
82 |
+
{'layers': '0-25, 27-28, 44-54', 'castto': 'Q5_1'},
|
83 |
+
{'layers': '26, 29-43, 55-56', 'castto': 'Q4_1'},
|
84 |
+
]
|
85 |
+
},
|
86 |
+
"15_2" : {
|
87 |
+
'casts': [
|
88 |
+
{'layers': '0-56', 'castto': 'Q4_1'},
|
89 |
+
]
|
90 |
+
},
|
91 |
+
}
|
92 |
+
```
|