vistralis-lab commited on
Commit
c1fcacb
Β·
verified Β·
1 Parent(s): 1a40aa3

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-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-4b-INT8-transformer-quants
17
+
18
+ INT8 (W8A8) quantization variants for [FLUX.2-klein-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-4B) (step-distilled 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-4b-int8-per-row.safetensors` |
28
+ | int8-per-tensor | static | per-tensor | βœ… Available | `flux-2-klein-4b-int8-per-tensor.safetensors` |
29
+ | int8-smoothquant-per-row | smoothquant | per-row | πŸ”œ Pending | `flux-2-klein-4b-int8-smoothquant-per-row.safetensors` |
30
+ | int8-smoothquant-per-tensor | smoothquant | per-tensor | πŸ”œ Pending | `flux-2-klein-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), 4 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.6518 | β€” | β€” | β€” | β€” |
72
+ | FP8 (reference) | 0.6522 | 0.0356 | 27.60 | 210.14 | 22.94 |
73
+ | int8-per-row | 0.6526 | 0.0253 | 29.23 | 142.27 | 15.76 |
74
+ | int8-per-tensor | 0.6517 | 0.0447 | 26.25 | 254.55 | 24.83 |
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.0480 | 24.43 |
83
+ | int8-per-row | 0.6458 | 0.0343 | 25.89 |
84
+ | int8-per-tensor | 0.6466 | 0.0621 | 23.23 |
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.6467 | 0.0178 | 32.28 |
101
+ | int8-per-row | 0.6465 | 0.0150 | 33.69 |
102
+ | int8-per-tensor | 0.6447 | 0.0256 | 30.21 |
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.6649 | 0.0410 | 26.08 |
127
+ | int8-per-row | 0.6654 | 0.0267 | 28.10 |
128
+ | int8-per-tensor | 0.6638 | 0.0465 | 25.32 |
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-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-4B) |
158
+ | Parameters | 4B |
159
+ | Quantization | INT8 (W8A8) via NVIDIA ModelOpt |
160
+ | Calibration | 768 prompts (256 per task), 4 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 | 4 |
164
+ | Guidance Scale | 1.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: 1c8da10773df4c8169e54697bb83e5a0378fd3fec56f9ce5062e23a6eab51099
  • Pointer size: 132 Bytes
  • Size of remote file: 6.26 MB
assets/comparison_composition_2.png ADDED

Git LFS Details

  • SHA256: a419307b9548be37019529e5f50e7e2d997365f86cf40f0b317ce451ba3a4a54
  • Pointer size: 132 Bytes
  • Size of remote file: 5.24 MB
assets/comparison_editing_1.png ADDED

Git LFS Details

  • SHA256: f8640494391425f6c6ef364af44f7b244239568fadf73b38b1692a93d99208fd
  • Pointer size: 132 Bytes
  • Size of remote file: 7.14 MB
assets/comparison_editing_2.png ADDED

Git LFS Details

  • SHA256: e06bc13fc8d5e1e7bcc78326d3300a802f8ac9c31dcb2f7ed8c0b074e16eceaa
  • Pointer size: 132 Bytes
  • Size of remote file: 6.71 MB
assets/comparison_t2i_1.png ADDED

Git LFS Details

  • SHA256: aaa1d9e19f954d943536e4ff22d81356cd8a6a23891ef6502a42d171f668aa95
  • Pointer size: 132 Bytes
  • Size of remote file: 4.94 MB
assets/comparison_t2i_2.png ADDED

Git LFS Details

  • SHA256: d74055da874d9cece5ba3e8739fef1e96e5ce6fbce6d06167bc12b2fe5c53683
  • Pointer size: 132 Bytes
  • Size of remote file: 6.84 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-4b-int8-per-row.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:992b62763f59fb41626ca6a8de3ede910c0216d155d447a2dcb0f5334325f936
3
+ size 4074429688
flux-2-klein-4b-int8-per-tensor.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fbd6cbc80f66af842d7cfe64eb10d55a1322c12bee5bf2d2e089666c5784d68a
3
+ size 4070618904