Views
No views yet
[!IMPORTANT] Duplicate Weight Stripping (OOM Prevention)This repository is an optimized repackaging ofblack-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 intransformer/. This caused standarddiffusersloading 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 |
| 🎨 Text-to-Image Generation | 🪄 Image Editing & Fusion |
![]() | ![]() |
[!NOTE] For local deployment on consumer GPUs (e.g., RTX 4090 or RTX 5090), refer to the Diffusers Hardware Docs.
1import torch
2from diffusers import Flux2Pipeline
3from diffusers.utils import load_image
4from huggingface_hub import get_token
5import requests
6import io
7
8# Quantized text-encoder and DiT. VAE remains in bf16
9repo_id = "diffusers/FLUX.2-dev-bnb-4bit"
10device = "cuda:0"
11torch_dtype = torch.bfloat16
12
13def remote_text_encoder(prompts):
14 response = requests.post(
15 "https://remote-text-encoder-flux-2.huggingface.co/predict",
16 json={"prompt": prompts},
17 headers={
18 "Authorization": f"Bearer {get_token()}",
19 "Content-Type": "application/json"
20 }
21 )
22 prompt_embeds = torch.load(io.BytesIO(response.content))
23 return prompt_embeds.to(device)
24
25pipe = Flux2Pipeline.from_pretrained(
26 repo_id, text_encoder=None, torch_dtype=torch_dtype
27).to(device)
28
29prompt = "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."
30
31# cat_image = load_image("https://huggingface.co/spaces/zerogpu-aoti/FLUX.1-Kontext-Dev-fp8-dynamic/resolve/main/cat.png")
32
33image = pipe(
34 prompt_embeds=remote_text_encoder(prompt),
35 # image=[cat_image], # optional multi-image input
36 generator=torch.Generator(device=device).manual_seed(42),
37 num_inference_steps=50, # 28 steps can be a good trade-off
38 guidance_scale=4,
39).images[0]
40
41image.save("flux2_output.png")1import torch
2from diffusers.pipelines.flux2.pipeline_flux2 import Flux2Pipeline
3from transformers import Mistral3ForConditionalGeneration
4from diffusers.models.transformers.transformer_flux2 import Flux2Transformer2DModel
5from diffusers.models.autoencoders.autoencoder_kl_flux2 import AutoencoderKLFlux2
6
7MODEL_ID = "Aquiles-ai/FLUX.2-dev"
8
9text_encoder = Mistral3ForConditionalGeneration.from_pretrained(
10 MODEL_ID, subfolder="text_encoder", torch_dtype=torch.bfloat16, device_map="cuda"
11)
12
13dit = Flux2Transformer2DModel.from_pretrained(
14 MODEL_ID, subfolder="transformer", torch_dtype=torch.bfloat16, device_map="cuda"
15)
16
17vae = AutoencoderKLFlux2.from_pretrained(
18 MODEL_ID,
19 subfolder="vae",
20 torch_dtype=torch.bfloat16.to("cuda")
21)
22
23pipeline = Flux2Pipeline.from_pretrained(
24 MODEL_ID, text_encoder=text_encoder, transformer=dit, vae=vae, dtype=torch.bfloat16
25).to(device="cuda")
26
27prompt = "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."
28
29output = pipeline(
30 prompt=prompt,
31 num_inference_steps=50,
32 generator=torch.Generator(device="cuda").manual_seed(42),
33 guidance_scale=4,
34).images[0]
35
36output.save("flux2_output.png")[!WARNING] 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.
1import torch
2from diffusers.pipelines.flux2.pipeline_flux2 import Flux2Pipeline
3from transformers import Mistral3ForConditionalGeneration
4from diffusers.models.transformers.transformer_flux2 import Flux2Transformer2DModel
5from diffusers.models.autoencoders.autoencoder_kl_flux2 import AutoencoderKLFlux2
6
7MODEL_ID = "Aquiles-ai/FLUX.2-dev"
8MODEL_4BIT = "diffusers/FLUX.2-dev-bnb-4bit"
9
10text_encoder = Mistral3ForConditionalGeneration.from_pretrained(
11 MODEL_4BIT, subfolder="text_encoder", torch_dtype=torch.bfloat16, device_map="cuda"
12)
13
14dit = Flux2Transformer2DModel.from_pretrained(
15 MODEL_ID, subfolder="transformer", torch_dtype=torch.bfloat16, device_map="cuda"
16)
17
18vae = AutoencoderKLFlux2.from_pretrained(
19 MODEL_ID,
20 subfolder="vae",
21 torch_dtype=torch.bfloat16.to("cuda")
22)
23
24pipeline = Flux2Pipeline.from_pretrained(
25 MODEL_ID, text_encoder=text_encoder, transformer=dit, vae=vae, dtype=torch.bfloat16
26).to(device="cuda")
27
28prompt = "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."
29
30output = pipeline(
31 prompt=prompt,
32 num_inference_steps=50,
33 generator=torch.Generator(device="cuda").manual_seed(42),
34 guidance_scale=4,
35).images[0]
36
37output.save("flux2_output.png")FLUX.2 [dev]).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.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.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.FLUX.2 [dev] model on Hugging Face.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.