File size: 13,768 Bytes
2ccf030
454cedd
2ccf030
 
 
 
01f34ca
e58f310
2ccf030
e58f310
2ccf030
e58f310
 
 
2ccf030
 
 
 
e58f310
2ccf030
 
66de2f3
e58f310
66de2f3
 
e58f310
66de2f3
 
e58f310
66de2f3
 
e58f310
66de2f3
 
 
d2ba892
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66de2f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ccf030
12d52dd
2ccf030
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12d52dd
 
9fb3555
 
12d52dd
 
2ccf030
 
 
 
12d52dd
2ccf030
12d52dd
 
 
01f34ca
 
 
 
2ccf030
 
 
 
 
 
 
 
 
 
 
 
 
128c0ce
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
---
base_model: black-forest-labs/FLUX.2-dev
language:
- en
license: other
license_name: flux-non-commercial-license
license_link: https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.md
extra_gated_prompt: By clicking "Agree", you agree to the [FLUX Non-Commercial License
  Agreement](https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.md)
  and acknowledge the [Acceptable Use Policy](https://bfl.ai/legal/usage-policy).
tags:
- fp8
- unsloth
- quantized
- image-generation
- image-editing
- flux
- diffusion-single-file
- image-to-image
pipeline_tag: image-to-image
library_name: diffusers
widget:
- text: cute sloth typing on a computer (INT8)
  output:
    url: samples/int8_1.png
- text: cute sloth typing on a computer (INT8)
  output:
    url: samples/int8_2.png
- text: cute sloth typing on a computer (FP8)
  output:
    url: samples/fp8_1.png
- text: cute sloth typing on a computer (FP8)
  output:
    url: samples/fp8_2.png
---
This is an FP8 / INT8 quantized version of [FLUX.2-dev](https://huggingface.co/black-forest-labs/FLUX.2-dev). <br>
- Optimized for efficient inference with reduced memory footprint. Same-seed LPIPS vs the bf16 model (lower is better): 0.078 INT8, 0.073 FP8.

<div>
  <div style="display: flex; gap: 5px; align-items: center; ">
    <a href="https://github.com/unslothai/unsloth/">
      <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
    </a>
    <a href="https://discord.gg/unsloth">
      <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
    </a>
    <a href="https://docs.unsloth.ai/">
      <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
    </a>
  </div>
</div>

---

### Samples

Prompt: "cute sloth typing on a computer"

<table>
  <tr>
    <td align="center"><b>INT8</b></td>
    <td align="center"><b>INT8</b></td>
  </tr>
  <tr>
    <td><img src="samples/int8_1.png" width="300"></td>
    <td><img src="samples/int8_2.png" width="300"></td>
  </tr>
  <tr>
    <td align="center"><b>FP8</b></td>
    <td align="center"><b>FP8</b></td>
  </tr>
  <tr>
    <td><img src="samples/fp8_1.png" width="300"></td>
    <td><img src="samples/fp8_2.png" width="300"></td>
  </tr>
</table>

---

![Teaser](./teaser_generation.png)
![Teaser](./teaser_editing.png)

`FLUX.2 [dev]` is a 32 billion parameter rectified flow transformer capable of generating, editing and combining images based on text instructions.
For more information, please read our [blog post](https://bfl.ai/blog/flux-2).

# Key Features
1. State of the art in open text-to-image generation, single-reference editing and multi-reference editing.
2. No need for finetuning: character, object and style reference without additional training in one model.
4. Trained using guidance distillation, making `FLUX.2 [dev]` more efficient.
5. Open weights to drive new scientific research, and empower artists to develop innovative workflows.
6. Generated outputs can be used for personal, scientific, and commercial purposes, as described in the [FLUX \[dev\] Non-Commercial License](https://github.com/black-forest-labs/flux/blob/main/model_licenses/LICENSE-FLUX1-dev).

# Usage
We provide a reference implementation of `FLUX.2 [dev]`, as well as sampling code, in a dedicated [github repository](https://github.com/black-forest-labs/flux2).
Developers and creatives looking to build on top of `FLUX.2 [dev]` are encouraged to use this as a starting point.

`FLUX.2 [dev]` is also available in both [ComfyUI](https://github.com/comfyanonymous/ComfyUI) and [Diffusers](https://github.com/huggingface/diffusers).

### Using with diffusers 🧨

For local deployment on a consumer type graphics card, like an RTX 4090 or an RTX 5090, please see the [diffusers docs](https://github.com/black-forest-labs/flux2/blob/main/docs/flux2_dev_hf.md) on our GitHub page.

As an example, here's a way to load a 4-bit quantized model with a remote text-encoder on an RTX 4090:

```python
import torch
from diffusers import Flux2Pipeline
from diffusers.utils import load_image
from huggingface_hub import get_token
import requests
import io

repo_id = "diffusers/FLUX.2-dev-bnb-4bit" #quantized text-encoder and DiT. VAE still in bf16
device = "cuda:0"
torch_dtype = torch.bfloat16

def remote_text_encoder(prompts):
    response = requests.post(
        "https://remote-text-encoder-flux-2.huggingface.co/predict",
        json={"prompt": prompts},
        headers={
            "Authorization": f"Bearer {get_token()}",
            "Content-Type": "application/json"
        }
    )
    prompt_embeds = torch.load(io.BytesIO(response.content))

    return prompt_embeds.to(device)

pipe = Flux2Pipeline.from_pretrained(
    repo_id, text_encoder=None, torch_dtype=torch_dtype
).to(device)

prompt = "Realistic macro photograph of a hermit crab using a soda can as its shell, partially emerging from the can, captured with sharp detail and natural colors, on a sunlit beach with soft shadows and a shallow depth of field, with blurred ocean waves in the background. The can has the text `BFL Diffusers` on it and it has a color gradient that start with #FF5733 at the top and transitions to #33FF57 at the bottom."

#cat_image = load_image("https://huggingface.co/spaces/zerogpu-aoti/FLUX.1-Kontext-Dev-fp8-dynamic/resolve/main/cat.png")
image = pipe(
    prompt_embeds=remote_text_encoder(prompt),
    #image=[cat_image] #optional multi-image input
    generator=torch.Generator(device=device).manual_seed(42),
    num_inference_steps=50, #28 steps can be a good trade-off
    guidance_scale=4,
).images[0]

image.save("flux2_output.png")
```


---

# Risks

Black Forest Labs is committed to the responsible development and deployment of our models. Prior to releasing the FLUX.2 family of models, we evaluated and mitigated a number of risks in our model checkpoints and hosted services, including the generation of unlawful content such as child sexual abuse material (CSAM) and nonconsensual intimate imagery (NCII). We implemented a series of pre-release mitigations to help prevent misuse by third parties, with additional post-release mitigations to help address residual risks:
1. Pre-training mitigation. We filtered pre-training data for multiple categories of “not safe for work” (NSFW) and known child sexual abuse material (CSAM) to help prevent a user generating unlawful content in response to text prompts or uploaded images. We have partnered with the Internet Watch Foundation, an independent nonprofit organization dedicated to preventing online abuse, to filter known CSAM from the training data.
2. Post-training mitigation. Subsequently, we undertook multiple rounds of targeted fine-tuning to provide additional mitigation against potential abuse, including both text-to-image (T2I) and image-to-image (I2I) attacks. By inhibiting certain behaviors and suppressing certain concepts in the trained model, these techniques can help to prevent a user generating synthetic CSAM or NCII from a text prompt, or transforming an uploaded image into synthetic CSAM or NCII.
3. Ongoing evaluation. Throughout this process, we conducted multiple internal and external third-party evaluations of model checkpoints to identify further opportunities for mitigation. External third-party evaluations focused on eliciting CSAM and NCII through adversarial testing with (i) text-only prompts, (ii) a single uploaded reference image with text prompts, and (iii) multiple uploaded reference images with text prompts. Based on this feedback, we conducted further safety fine-tuning to produce our open-weight model (FLUX.2 [dev]).
4. Release decision. After safety fine-tuning and prior to release, we conducted a final third-party evaluation of the proposed release checkpoint, focused on T2I and I2I generation of synthetic CSAM and NCII, including a comparison with other open-weight T2I and I2I models (total prompts n≈2,800). The final FLUX.2 [dev] checkpoint demonstrated high resilience against violative inputs in complex generation and editing tasks, and demonstrated higher resilience than leading open-weight models across these risk categories. Based on these findings, we approved the release of the FLUX.2 Pro model via API and the release of the open-weight FLUX.2 [dev] model under a non-commercial license to support third-party research and development.
5. Inference filters. The repository for the FLUX.2 [dev] model includes filters for NSFW and IP-infringing content at input and output. Filters or manual review must be used with the model under the terms of the FLUX.2 [dev] Non-Commercial License. We may approach known deployers of the FLUX.2 [dev] model at random to verify that filters or manual review processes are in place. Additionally, we apply multiple filters to intercept text prompts, uploaded images, and output images on the API for FLUX.2 [pro]. We utilize both in-house and third-party supplied filters to prevent CSAM and NCII outputs, including filters provided by Hive and Microsoft. We provide filters for other categories of potentially harmful content, including gore, which can be adjusted by developers based on their specific risk profile and legitimate use cases.
6. Content provenance. Content provenance features can help users and platforms better identify, label, and interpret AI-generated content online. The inference code for FLUX.2 [dev] implements an example of pixel-layer watermarking, and this repository includes links to the Coalition for Content Provenance and Authenticity (C2PA) standard for metadata. The API for FLUX.2 Pro applies cryptographically-signed C2PA metadata to output content to indicate that images were produced with our model.
7. Policies. Use of our models and access to our API are governed by our FLUX [dev] Non-Commercial License (for our non-commercial open-weight users); Developer Terms of Service, Self-Hosted Commercial License Terms, and Usage Policy (for our commercial open-weight model users); and Developer Terms of Service, FLUX API Service Terms, and Usage Policy (for our API users). These prohibit the generation of unlawful content or the use of generated content for unlawful, defamatory, or abusive purposes. Developers and users must consent to these conditions to access the FLUX.2 [dev] model on Hugging Face.
8. Monitoring. We are monitoring for patterns of violative use after release. We continue to issue and escalate takedown requests to websites, services, or businesses that misuse our models. Additionally, we may ban users or developers who we detect intentionally and repeatedly violate our policies via the FLUX API. Additionally, we provide a dedicated email address (safety@blackforestlabs.ai) to solicit feedback from the community. We maintain a reporting relationship with organizations such as the Internet Watch Foundation and the National Center for Missing and Exploited Children, and welcome ongoing engagement with authorities, developers, and researchers to share intelligence about emerging risks and develop effective mitigations.


# License
This model falls under the [FLUX Non-Commercial License](https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.md).

---

# Quantized transformer checkpoints (this repo)

This repo adds pre-quantized diffusion transformer checkpoints for black-forest-labs/FLUX.2-dev, built with torchao
dynamic activation quantization from the dense bf16 transformer. The official model card above
is unchanged from the source repo.

Files:
- FLUX.2-dev-INT8.pt (33.0 GB)
- FLUX.2-dev-FP8.pt (32.2 GB)

Details:
- int8: Int8DynamicActivationInt8WeightConfig (per-token activation, per-channel weight, torch._int_mm).
- fp8: Float8DynamicActivationFloat8WeightConfig with PerRow granularity (e4m3, torch._scaled_mm).
  The loader must floor the dynamic activation scale (activation_value_lb=1e-12 on torchao 0.13+)
  so all-zero activation token rows cannot produce a zero scale.
- Loading a checkpoint is bit-identical to quantizing the dense bf16 transformer on the fly;
  the checkpoint skips the dense load and quantize step.
- Validated against same-seed dense bf16 renders (SSIM, LPIPS-vgg, CLIP delta, non-finite and
  black-frame checks) on torch 2.12.1 and torchao 0.17.

Note: Derived from black-forest-labs/FLUX.2-dev and distributed under the
[FLUX Non-Commercial License](https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.md).
The weights are modified only by the quantization described above. Not an official Black Forest Labs
product and not endorsed by Black Forest Labs.

## Samples

Prompt: "cute sloth typing on a computer" (1024x1024, family default steps/guidance, seeds 0-2).

**int8**

<img src="samples/int8_1.png" width="260"> <img src="samples/int8_2.png" width="260"> <img src="samples/int8_3.png" width="260">

**fp8**

<img src="samples/fp8_1.png" width="260"> <img src="samples/fp8_2.png" width="260"> <img src="samples/fp8_3.png" width="260">

---

# Pre-cast fp8 text encoder (this repo)

FLUX.2-dev-text_encoder-FP8.pt (24.7 GB) is the pipeline's text encoder (Mistral3ForConditionalGeneration, the `text_encoder`
subfolder of black-forest-labs/FLUX.2-dev) with the layerwise fp8 storage cast Unsloth Studio applies at load
time, saved pre-cast:

- Loading it is bit-identical to downloading the dense encoder and casting on load
  (verified tensor for tensor: 585 tensors, 453 cast to fp8 storage).
- Cuts the text-encoder download from 48.0 GB to 24.7 GB.
- Plain-tensor state dict: loads with torch.load(weights_only=True). Metadata records
  scheme fp8, component text_encoder, base black-forest-labs/FLUX.2-dev.