Manusagents commited on
Commit
18f5c6b
·
verified ·
1 Parent(s): 93a12d5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +187 -34
README.md CHANGED
@@ -1,47 +1,200 @@
1
- --- language: - en license: other license_name: flux-dev-non-commercial-license license_link: https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.txt extra_gated_prompt: >- By clicking "Agree", you agree to the [FLUX [dev] Non-Commercial License Agreement](https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.txt) and acknowledge the [Acceptable Use Policy](https://bfl.ai/legal/usage-policy). tags: - image-generation - image-editing - flux pipeline_tag: image-to-image library_name: diffusers --- <div align="center"> # ⚡ FLUX.2 [dev] — Optimized & Repackaged [![License: Non-Commercial](https://img.shields.io/badge/License-FLUX_Non--Commercial-red.svg?style=for-the-badge)](https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.txt) [![Parameters](https://img.shields.io/badge/Parameters-32B_Rectified_Flow-blue.svg?style=for-the-badge)](https://bfl.ai/blog/flux-2) [![VRAM Reduced](https://img.shields.io/badge/VRAM_Usage-110_GB_(Was_178_GB)-brightgreen.svg?style=for-the-badge)](#-vram-optimization-breakthrough) [![Library](https://img.shields.io/badge/Library-Diffusers_🧨-orange.svg?style=for-the-badge)](https://github.com/huggingface/diffusers) [![Pipeline](https://img.shields.io/badge/Pipeline-Image--to--Image-purple.svg?style=for-the-badge)](#) --- ### 🚀 **Next-Gen Open Text-to-Image & Multi-Reference Editing Engine** *Capable of generating, editing, and combining high-fidelity images with single & multi-reference consistency — zero finetuning required.* [📖 Read Official Blog](https://bfl.ai/blog/flux-2) • [💻 GitHub Repository](https://github.com/black-forest-labs/flux2) • [🤗 Base Model HuggingFace](https://huggingface.co/black-forest-labs/FLUX.2-dev) --- </div> ## 💡 Key Architectural Fix & VRAM Optimization > [!IMPORTANT] > **Duplicate Weight Stripping (OOM Prevention)** > > This repository is an **optimized repackaging** of [`black-forest-labs/FLUX.2-dev`](https://huggingface.co/black-forest-labs/FLUX.2-dev). > - **🚨 The Issue:** The original repository contained a duplicate weight file (`flux2-dev.safetensors`) in the root directory alongside the identical weights in `transformer/`. This caused standard `diffusers` loading routines to initialize the 32B model **twice in VRAM**. > - **🛠️ The Fix:** The redundant root file was safely removed. > - **📈 Performance Gain:** Memory consumption during inference dropped dramatically from **~178 GB** down to **~110 GB**, eliminating out-of-memory (OOM) crashes and enabling stable execution on target hardware. | Metric | Original Repo | Repackaged Repo | Impact | | :--- | :---: | :---: | :---: | | **Root Transformer Duplicate** | Included (`flux2-dev.safetensors`) | ❌ Removed | Zero Redundant Weights | | **Diffusers Loading** | Dual Load (Bugged) | Single Load (Clean) | No Memory Leak / Spikes | | **Peak VRAM Usage** | ~178 GB | **~110 GB** | **38% VRAM Saved (OOM Fixed)** | | **Inference Stability** | Crashing / OOM | **Stable Execution** | ⚡ Ready for Production | --- ## 🎨 Model Teaser & Showcases <div align="center"> <table> <tr> <td align="center"><b>🎨 Text-to-Image Generation</b></td> <td align="center"><b>🪄 Image Editing & Fusion</b></td> </tr> <tr> <td><img src="./teaser_generation.png" alt="Teaser Generation" width="100%"/></td> <td><img src="./teaser_editing.png" alt="Teaser Editing" width="100%"/></td> </tr> </table> </div> --- ## 🔥 Key Features - **🏆 State of the Art Performance:** Superior open-weights benchmarks across text-to-image, single-reference editing, and complex multi-reference image composition. - **✨ Zero-Finetuning In-Context Consistency:** Seamlessly transfer character identity, physical objects, and artistic styles without any additional model training or LoRA fine-tuning. - **⚡ Guidance Distillation:** Optimized training architecture using guidance distillation, delivering faster generation steps and higher efficiency. - **🔬 Open Weights for Innovation:** Full model weights accessible to empower scientific research, custom artistic pipelines, and community development. - **📜 Flexible License Rights:** Generated outputs can be used freely for personal, scientific, and commercial purposes in compliance with the [FLUX [dev] Non-Commercial License](https://github.com/black-forest-labs/flux/blob/main/model_licenses/LICENSE-FLUX1-dev). --- ## 💻 Usage & Deployment We provide a reference implementation, sampling code, and ecosystem integration across **Diffusers** and **ComfyUI**. For complete setup guides, check out the official [GitHub Repository](https://github.com/black-forest-labs/flux2). > [!NOTE] > For local deployment on consumer GPUs (e.g., **RTX 4090** or **RTX 5090**), refer to the [Diffusers Hardware Docs](https://github.com/black-forest-labs/flux2/blob/main/docs/flux2_dev_hf.md). <details open> <summary><b>1️⃣ Option A: RTX 4090 Deployment (4-bit Quantized + Remote Text Encoder)</b></summary> ```python import torch from diffusers import Flux2Pipeline from diffusers.utils import load_image from huggingface_hub import get_token import requests import io # Quantized text-encoder and DiT. VAE remains in bf16 repo_id = "diffusers/FLUX.2-dev-bnb-4bit" device = "cuda:0" torch_dtype = torch.bfloat16 def remote_text_encoder(prompts): response = requests.post( "[https://remote-text-encoder-flux-2.huggingface.co/predict](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](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") `
2
- Python
3
- `import torch from diffusers.pipelines.flux2.pipeline_flux2 import Flux2Pipeline from transformers import Mistral3ForConditionalGeneration from diffusers.models.transformers.transformer_flux2 import Flux2Transformer2DModel from diffusers.models.autoencoders.autoencoder_kl_flux2 import AutoencoderKLFlux2 MODEL_ID = "Aquiles-ai/FLUX.2-dev" text_encoder = Mistral3ForConditionalGeneration.from_pretrained( MODEL_ID, subfolder="text_encoder", torch_dtype=torch.bfloat16, device_map="cuda" ) dit = Flux2Transformer2DModel.from_pretrained( MODEL_ID, subfolder="transformer", torch_dtype=torch.bfloat16, device_map="cuda" ) vae = AutoencoderKLFlux2.from_pretrained( MODEL_ID, subfolder="vae", torch_dtype=torch.bfloat16.to("cuda") ) pipeline = Flux2Pipeline.from_pretrained( MODEL_ID, text_encoder=text_encoder, transformer=dit, vae=vae, dtype=torch.bfloat16 ).to(device="cuda") 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." output = pipeline( prompt=prompt, num_inference_steps=50, generator=torch.Generator(device="cuda").manual_seed(42), guidance_scale=4, ).images[0] output.save("flux2_output.png") `
4
- [!WARNING]
5
- Even with a quantized text encoder, high memory requirements remain. Execution on an **H100** may be tight on VRAM. **>85 GB VRAM** GPUs are strongly recommended for stability and to avoid OOM issues.
6
- Python
7
- `import torch from diffusers.pipelines.flux2.pipeline_flux2 import Flux2Pipeline from transformers import Mistral3ForConditionalGeneration from diffusers.models.transformers.transformer_flux2 import Flux2Transformer2DModel from diffusers.models.autoencoders.autoencoder_kl_flux2 import AutoencoderKLFlux2 MODEL_ID = "Aquiles-ai/FLUX.2-dev" MODEL_4BIT = "diffusers/FLUX.2-dev-bnb-4bit" text_encoder = Mistral3ForConditionalGeneration.from_pretrained( MODEL_4BIT, subfolder="text_encoder", torch_dtype=torch.bfloat16, device_map="cuda" ) dit = Flux2Transformer2DModel.from_pretrained( MODEL_ID, subfolder="transformer", torch_dtype=torch.bfloat16, device_map="cuda" ) vae = AutoencoderKLFlux2.from_pretrained( MODEL_ID, subfolder="vae", torch_dtype=torch.bfloat16.to("cuda") ) pipeline = Flux2Pipeline.from_pretrained( MODEL_ID, text_encoder=text_encoder, transformer=dit, vae=vae, dtype=torch.bfloat16 ).to(device="cuda") 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." output = pipeline( prompt=prompt, num_inference_steps=50, generator=torch.Generator(device="cuda").manual_seed(42), guidance_scale=4, ).images[0] output.save("flux2_output.png") `
8
- ## 🛡️ Safety & Risk Mitigation Framework
9
- 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:
10
- 1.
11
- **🛡️ 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.
12
 
13
- 2.
14
- **🎯 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.
15
 
16
- 3.
17
- **🔍 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:
18
- -
19
- *(i)* text-only prompts
20
 
21
- -
22
- *(ii)* a single uploaded reference image with text prompts
23
 
24
- -
25
- *(iii)* multiple uploaded reference images with text prompts.
26
 
 
27
 
28
- Based on this feedback, we conducted further safety fine-tuning to produce our open-weight model (`FLUX.2 [dev]`).
29
 
30
- 4.
31
- **📋 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 \approx 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.
32
 
33
- 5.
34
- **⚙️ 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.
35
 
36
- 6.
37
- **🏷️ 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.
 
 
 
 
 
38
 
39
- 7.
40
- **📄 Policies:** Use of our models and access to our API are governed by our [FLUX [dev] Non-Commercial License](https://www.google.com/url?sa=E&source=gmail&q=https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.txt) (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.
41
 
42
- 8.
43
- **👁️ 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.
44
 
 
 
 
45
 
46
- ## 📜 License
47
- This model falls under the [FLUX [dev] Non-Commercial License](https://www.google.com/url?sa=E&source=gmail&q=https://huggingface.co/black-forest-labs/FLUX.2-dev/blob/main/LICENSE.txt).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
3
+ # Doc / guide: https://huggingface.co/docs/hub/model-cards
4
+ {}
5
+ ---
 
 
 
 
 
 
6
 
7
+ # Model Card for Model ID
 
8
 
9
+ <!-- Provide a quick summary of what the model is/does. -->
 
 
 
10
 
11
+ This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
 
12
 
13
+ ## Model Details
 
14
 
15
+ ### Model Description
16
 
17
+ <!-- Provide a longer summary of what this model is. -->
18
 
 
 
19
 
 
 
20
 
21
+ - **Developed by:** [More Information Needed]
22
+ - **Funded by [optional]:** [More Information Needed]
23
+ - **Shared by [optional]:** [More Information Needed]
24
+ - **Model type:** [More Information Needed]
25
+ - **Language(s) (NLP):** [More Information Needed]
26
+ - **License:** [More Information Needed]
27
+ - **Finetuned from model [optional]:** [More Information Needed]
28
 
29
+ ### Model Sources [optional]
 
30
 
31
+ <!-- Provide the basic links for the model. -->
 
32
 
33
+ - **Repository:** [More Information Needed]
34
+ - **Paper [optional]:** [More Information Needed]
35
+ - **Demo [optional]:** [More Information Needed]
36
 
37
+ ## Uses
38
+
39
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
40
+
41
+ ### Direct Use
42
+
43
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
44
+
45
+ [More Information Needed]
46
+
47
+ ### Downstream Use [optional]
48
+
49
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
50
+
51
+ [More Information Needed]
52
+
53
+ ### Out-of-Scope Use
54
+
55
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
56
+
57
+ [More Information Needed]
58
+
59
+ ## Bias, Risks, and Limitations
60
+
61
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
62
+
63
+ [More Information Needed]
64
+
65
+ ### Recommendations
66
+
67
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
68
+
69
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
70
+
71
+ ## How to Get Started with the Model
72
+
73
+ Use the code below to get started with the model.
74
+
75
+ [More Information Needed]
76
+
77
+ ## Training Details
78
+
79
+ ### Training Data
80
+
81
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
82
+
83
+ [More Information Needed]
84
+
85
+ ### Training Procedure
86
+
87
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
88
+
89
+ #### Preprocessing [optional]
90
+
91
+ [More Information Needed]
92
+
93
+
94
+ #### Training Hyperparameters
95
+
96
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
97
+
98
+ #### Speeds, Sizes, Times [optional]
99
+
100
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
101
+
102
+ [More Information Needed]
103
+
104
+ ## Evaluation
105
+
106
+ <!-- This section describes the evaluation protocols and provides the results. -->
107
+
108
+ ### Testing Data, Factors & Metrics
109
+
110
+ #### Testing Data
111
+
112
+ <!-- This should link to a Dataset Card if possible. -->
113
+
114
+ [More Information Needed]
115
+
116
+ #### Factors
117
+
118
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
119
+
120
+ [More Information Needed]
121
+
122
+ #### Metrics
123
+
124
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
125
+
126
+ [More Information Needed]
127
+
128
+ ### Results
129
+
130
+ [More Information Needed]
131
+
132
+ #### Summary
133
+
134
+
135
+
136
+ ## Model Examination [optional]
137
+
138
+ <!-- Relevant interpretability work for the model goes here -->
139
+
140
+ [More Information Needed]
141
+
142
+ ## Environmental Impact
143
+
144
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
145
+
146
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
147
+
148
+ - **Hardware Type:** [More Information Needed]
149
+ - **Hours used:** [More Information Needed]
150
+ - **Cloud Provider:** [More Information Needed]
151
+ - **Compute Region:** [More Information Needed]
152
+ - **Carbon Emitted:** [More Information Needed]
153
+
154
+ ## Technical Specifications [optional]
155
+
156
+ ### Model Architecture and Objective
157
+
158
+ [More Information Needed]
159
+
160
+ ### Compute Infrastructure
161
+
162
+ [More Information Needed]
163
+
164
+ #### Hardware
165
+
166
+ [More Information Needed]
167
+
168
+ #### Software
169
+
170
+ [More Information Needed]
171
+
172
+ ## Citation [optional]
173
+
174
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
175
+
176
+ **BibTeX:**
177
+
178
+ [More Information Needed]
179
+
180
+ **APA:**
181
+
182
+ [More Information Needed]
183
+
184
+ ## Glossary [optional]
185
+
186
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
187
+
188
+ [More Information Needed]
189
+
190
+ ## More Information [optional]
191
+
192
+ [More Information Needed]
193
+
194
+ ## Model Card Authors [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Contact
199
+
200
+ [More Information Needed]