vistralis-lab commited on
Commit
339f4bc
Β·
verified Β·
1 Parent(s): d9839d0

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,13 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/comparison_composition_1.png filter=lfs diff=lfs merge=lfs -text
37
+ assets/comparison_composition_2.png filter=lfs diff=lfs merge=lfs -text
38
+ assets/comparison_editing_1.png filter=lfs diff=lfs merge=lfs -text
39
+ assets/comparison_editing_2.png filter=lfs diff=lfs merge=lfs -text
40
+ assets/comparison_t2i_1.png filter=lfs diff=lfs merge=lfs -text
41
+ assets/comparison_t2i_2.png filter=lfs diff=lfs merge=lfs -text
42
+ assets/reference_composition_1.png filter=lfs diff=lfs merge=lfs -text
43
+ assets/reference_composition_2.png filter=lfs diff=lfs merge=lfs -text
44
+ assets/reference_editing_1.png filter=lfs diff=lfs merge=lfs -text
45
+ assets/reference_editing_2.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: diffusers
3
+ license: apache-2.0
4
+ base_model: black-forest-labs/FLUX.2-klein-base-4B
5
+ base_model_relation: quantized
6
+ tags:
7
+ - flux
8
+ - flux2
9
+ - quantized
10
+ - int8
11
+ - transformer
12
+ - nvidia-modelopt
13
+ pipeline_tag: text-to-image
14
+ ---
15
+
16
+ # FLUX.2-klein-base-4b-INT8-transformer-quants
17
+
18
+ INT8 (W8A8) quantization variants for [FLUX.2-klein-base-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-4B) (4B parameters).
19
+
20
+ This repository contains multiple INT8 quantization variants for experimentation and comparison.
21
+
22
+ > **Status**: Static/Max variants (`int8-per-row`, `int8-per-tensor`) are available now.
23
+ > SmoothQuant variants are pending and will be added when ready.
24
+
25
+ | Variant | Algorithm | Scale Mode | Status | Checkpoint |
26
+ |---------|-----------|------------|--------|------------|
27
+ | int8-per-row | static | per-row | βœ… Available | `flux-2-klein-base-4b-int8-per-row.safetensors` |
28
+ | int8-per-tensor | static | per-tensor | βœ… Available | `flux-2-klein-base-4b-int8-per-tensor.safetensors` |
29
+ | int8-smoothquant-per-row | smoothquant | per-row | πŸ”œ Pending | `flux-2-klein-base-4b-int8-smoothquant-per-row.safetensors` |
30
+ | int8-smoothquant-per-tensor | smoothquant | per-tensor | πŸ”œ Pending | `flux-2-klein-base-4b-int8-smoothquant-per-tensor.safetensors` |
31
+
32
+ ## Quantization Details
33
+
34
+ All variants use [NVIDIA TensorRT Model Optimizer (ModelOpt)](https://github.com/NVIDIA/TensorRT-Model-Optimizer)
35
+ INT8 (W8A8) quantization:
36
+
37
+ | Property | Value |
38
+ |----------|-------|
39
+ | Framework | NVIDIA ModelOpt |
40
+ | Calibration | 768 prompts (256 T2I, 256 editing, 256 composition), 50 steps each |
41
+ | Weight Quantization | INT8 symmetric β€” per-row or per-tensor depending on variant |
42
+ | Activation Quantization | Dynamic per-row (quantized on-the-fly at inference, one scale per token) |
43
+ | Preserved Layers | Embedder layers (time_embed, context_embedder, x_embedder) and output projection kept in BF16 |
44
+
45
+ ### Algorithm Γ— Scale Mode
46
+
47
+ | | **Per-Row** | **Per-Tensor** |
48
+ |---|---|---|
49
+ | **Static (Max)** | `int8-per-row` βœ… | `int8-per-tensor` βœ… |
50
+ | **SmoothQuant** | `int8-smoothquant-per-row` πŸ”œ | `int8-smoothquant-per-tensor` πŸ”œ |
51
+
52
+ **Algorithm:**
53
+ - **Static (Max)**: Standard INT8 quantization with calibrated min/max ranges
54
+ - **SmoothQuant** *(pending)*: Migrates quantization difficulty from activations to weights for better accuracy
55
+
56
+ **Scale Mode:**
57
+ - **Per-Row**: Independent scale per output channel (finer granularity, higher accuracy)
58
+ - **Per-Tensor**: Single scale per tensor (faster, lower memory, slightly reduced accuracy)
59
+
60
+ > **Note**: In all variants, input activations are always quantized **dynamically per-row** at inference time
61
+ > (one scale per token). The scale mode above refers to the **weight** quantization granularity.
62
+
63
+ ## Evaluation Results
64
+
65
+ Compared against BF16 baseline using identical prompts, seeds, and resolution.
66
+
67
+ ### Overall Metrics
68
+
69
+ | Variant | CLIP ↑ | LPIPS ↓ | PSNR ↑ | MSE ↓ | FID ↓ |
70
+ |---------|--------|---------|--------|-------|-------|
71
+ | BF16 (baseline) | 0.6491 | β€” | β€” | β€” | β€” |
72
+ | FP8 (reference) | 0.6487 | 0.0645 | 24.21 | 477.33 | 34.52 |
73
+ | int8-per-row | 0.6486 | 0.0560 | 26.03 | 445.43 | 28.03 |
74
+ | int8-per-tensor | 0.6495 | 0.1025 | 22.02 | 743.48 | 45.29 |
75
+ | int8-smoothquant-per-row | β€” | β€” | β€” | β€” | β€” |
76
+ | int8-smoothquant-per-tensor | β€” | β€” | β€” | β€” | β€” |
77
+
78
+ ### Text-to-Image
79
+
80
+ | Variant | CLIP ↑ | LPIPS ↓ | PSNR ↑ |
81
+ |---------|--------|---------|--------|
82
+ | FP8 (reference) | 0.6452 | 0.0804 | 22.51 |
83
+ | int8-per-row | 0.6450 | 0.0649 | 24.35 |
84
+ | int8-per-tensor | 0.6457 | 0.1364 | 20.17 |
85
+ | int8-smoothquant-per-row | β€” | β€” | β€” |
86
+ | int8-smoothquant-per-tensor | β€” | β€” | β€” |
87
+
88
+ > Dramatic chiaroscuro portrait of a cellist mid-performance, single spotlight from above, instrument bow caught in motion blur, concert hall darkness
89
+
90
+ ![Text-to-Image 1 β€” BF16 vs FP8 vs INT8](assets/comparison_t2i_1.png)
91
+
92
+ > Stained glass window design depicting the four elements, lead came outlines, rich jewel tones of ruby, sapphire, emerald, and topaz
93
+
94
+ ![Text-to-Image 2 β€” BF16 vs FP8 vs INT8](assets/comparison_t2i_2.png)
95
+
96
+ ### Editing
97
+
98
+ | Variant | CLIP ↑ | LPIPS ↓ | PSNR ↑ |
99
+ |---------|--------|---------|--------|
100
+ | FP8 (reference) | 0.6420 | 0.0309 | 28.49 |
101
+ | int8-per-row | 0.6418 | 0.0215 | 31.25 |
102
+ | int8-per-tensor | 0.6424 | 0.0588 | 25.71 |
103
+ | int8-smoothquant-per-row | β€” | β€” | β€” |
104
+ | int8-smoothquant-per-tensor | β€” | β€” | β€” |
105
+
106
+ > **Base:** A bicycle leaning against a stone wall in a village
107
+ >
108
+ > **Edit:** Transform the village into an underwater coral reef scene, the bicycle covered in barnacles and sea anemones, fish swimming around
109
+
110
+ ![Editing 1 β€” reference](assets/reference_editing_1.png)
111
+
112
+ ![Editing 1 β€” BF16 vs FP8 vs INT8](assets/comparison_editing_1.png)
113
+
114
+ > **Base:** A food truck parked on a city street at noon
115
+ >
116
+ > **Edit:** Change the street to a Venice canal with the food truck floating on a gondola platform, evening golden hour lighting
117
+
118
+ ![Editing 2 β€” reference](assets/reference_editing_2.png)
119
+
120
+ ![Editing 2 β€” BF16 vs FP8 vs INT8](assets/comparison_editing_2.png)
121
+
122
+ ### Composition
123
+
124
+ | Variant | CLIP ↑ | LPIPS ↓ | PSNR ↑ |
125
+ |---------|--------|---------|--------|
126
+ | FP8 (reference) | 0.6591 | 0.0824 | 21.63 |
127
+ | int8-per-row | 0.6591 | 0.0817 | 22.48 |
128
+ | int8-per-tensor | 0.6603 | 0.1123 | 20.19 |
129
+ | int8-smoothquant-per-row | β€” | β€” | β€” |
130
+ | int8-smoothquant-per-tensor | β€” | β€” | β€” |
131
+
132
+ > Create a zen garden where the raked sand patterns flow into and around a giant ramen bowl as the central stone
133
+
134
+ ![Composition 1 β€” reference](assets/reference_composition_1.png)
135
+
136
+ ![Composition 1 β€” BF16 vs FP8 vs INT8](assets/comparison_composition_1.png)
137
+
138
+ > A clockwork mechanical wolf made of brass gears howling at the full moon on the snowy ridge, steam rising from its joints
139
+
140
+ ![Composition 2 β€” reference](assets/reference_composition_2.png)
141
+
142
+ ![Composition 2 β€” BF16 vs FP8 vs INT8](assets/comparison_composition_2.png)
143
+
144
+ ## Usage
145
+
146
+ > **🚧 Code release coming soon.** A pip-installable loader library is in preparation.
147
+
148
+ In the meantime, these checkpoints can be tested with ComfyUI using the
149
+ [ComfyUI-Flux2-INT8](https://github.com/BobJohnson24/ComfyUI-Flux2-INT8) custom node.
150
+ Per-row quantization support is available via
151
+ [PR #24](https://github.com/BobJohnson24/ComfyUI-Flux2-INT8/pull/24).
152
+
153
+ ## Technical Details
154
+
155
+ | Property | Value |
156
+ |----------|-------|
157
+ | Base Model | [FLUX.2-klein-base-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-4B) |
158
+ | Parameters | 4B |
159
+ | Quantization | INT8 (W8A8) via NVIDIA ModelOpt |
160
+ | Calibration | 768 prompts (256 per task), 50 steps each |
161
+ | Activation Quantization | Dynamic per-row (quantized on-the-fly at inference) |
162
+ | Preserved Layers | Embedder layers and output projection kept in BF16 |
163
+ | Inference Steps | 50 |
164
+ | Guidance Scale | 4.0 |
165
+
166
+ ## License
167
+
168
+ This model inherits the license from the base model: **[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)**.
assets/comparison_composition_1.png ADDED

Git LFS Details

  • SHA256: 082e5bb75f136056628a0da53bd622f30a3e175bc1f0b2dc504e77adb1585c1e
  • Pointer size: 132 Bytes
  • Size of remote file: 6.35 MB
assets/comparison_composition_2.png ADDED

Git LFS Details

  • SHA256: 520753a0f64d26bc37442cc14a3c3f7de009fe0529eb5056164571cc7549b2aa
  • Pointer size: 132 Bytes
  • Size of remote file: 6.34 MB
assets/comparison_editing_1.png ADDED

Git LFS Details

  • SHA256: 26bccf4916c731e6e809748596ca197b13ced22193c0bf937e740177e05bb7a9
  • Pointer size: 132 Bytes
  • Size of remote file: 7.79 MB
assets/comparison_editing_2.png ADDED

Git LFS Details

  • SHA256: 0a15d0367a0df1432e567b8264e5fff61aa3b718441f182ec6ac92301b5e8bb7
  • Pointer size: 132 Bytes
  • Size of remote file: 7.16 MB
assets/comparison_t2i_1.png ADDED

Git LFS Details

  • SHA256: 6edbe3dbcfad556031f96fc20031da7590147699169c22ab04aacd2469f07938
  • Pointer size: 132 Bytes
  • Size of remote file: 4.84 MB
assets/comparison_t2i_2.png ADDED

Git LFS Details

  • SHA256: 11f3f3d381968f240879f1eeee0e4e89521e8b16dbbc28b972c21aa53db40f07
  • Pointer size: 132 Bytes
  • Size of remote file: 6.3 MB
assets/reference_composition_1.png ADDED

Git LFS Details

  • SHA256: 82bd4546129c98132a5f69964170a2923876224d71ccc788e3ec2f0042e94c75
  • Pointer size: 132 Bytes
  • Size of remote file: 3.09 MB
assets/reference_composition_2.png ADDED

Git LFS Details

  • SHA256: d4c460b345d6918faa3224915b250b65334d1be7c8ca32e134c75ac449c55bbb
  • Pointer size: 132 Bytes
  • Size of remote file: 3.41 MB
assets/reference_editing_1.png ADDED

Git LFS Details

  • SHA256: 32ab623c156193f6aba85098db1af1e9aeec1942b946073a30e4087638413c7a
  • Pointer size: 132 Bytes
  • Size of remote file: 1.73 MB
assets/reference_editing_2.png ADDED

Git LFS Details

  • SHA256: 77e0ca80aeb7e01b534cdf92ba38cb914de927e81b0f40a25bb8c4b8f78de425
  • Pointer size: 132 Bytes
  • Size of remote file: 1.35 MB
flux-2-klein-base-4b-int8-per-row.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44683f38cb3c04b8e3b98e18f433d9d656050e2dfbb7e77f0fad754fb79c4f2a
3
+ size 4074429688
flux-2-klein-base-4b-int8-per-tensor.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:78504b43028b756faf9c239208955387ce3a494c9f96a636730023cc5fa29440
3
+ size 4070618904