Instructions to use vistralis/FLUX.2-klein-base-4b-INT8-transformer-quants with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use vistralis/FLUX.2-klein-base-4b-INT8-transformer-quants with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("vistralis/FLUX.2-klein-base-4b-INT8-transformer-quants", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Upload folder using huggingface_hub
Browse files- .gitattributes +10 -0
- README.md +168 -0
- assets/comparison_composition_1.png +3 -0
- assets/comparison_composition_2.png +3 -0
- assets/comparison_editing_1.png +3 -0
- assets/comparison_editing_2.png +3 -0
- assets/comparison_t2i_1.png +3 -0
- assets/comparison_t2i_2.png +3 -0
- assets/reference_composition_1.png +3 -0
- assets/reference_composition_2.png +3 -0
- assets/reference_editing_1.png +3 -0
- assets/reference_editing_2.png +3 -0
- flux-2-klein-base-4b-int8-per-row.safetensors +3 -0
- flux-2-klein-base-4b-int8-per-tensor.safetensors +3 -0
.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 |
+

|
| 91 |
+
|
| 92 |
+
> Stained glass window design depicting the four elements, lead came outlines, rich jewel tones of ruby, sapphire, emerald, and topaz
|
| 93 |
+
|
| 94 |
+

|
| 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 |
+

|
| 111 |
+
|
| 112 |
+

|
| 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 |
+

|
| 119 |
+
|
| 120 |
+

|
| 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 |
+

|
| 135 |
+
|
| 136 |
+

|
| 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 |
+

|
| 141 |
+
|
| 142 |
+

|
| 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
|
assets/comparison_composition_2.png
ADDED
|
Git LFS Details
|
assets/comparison_editing_1.png
ADDED
|
Git LFS Details
|
assets/comparison_editing_2.png
ADDED
|
Git LFS Details
|
assets/comparison_t2i_1.png
ADDED
|
Git LFS Details
|
assets/comparison_t2i_2.png
ADDED
|
Git LFS Details
|
assets/reference_composition_1.png
ADDED
|
Git LFS Details
|
assets/reference_composition_2.png
ADDED
|
Git LFS Details
|
assets/reference_editing_1.png
ADDED
|
Git LFS Details
|
assets/reference_editing_2.png
ADDED
|
Git LFS Details
|
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
|