Instructions to use moonbox-dev/FLUX.2-klein-4B-TensorRT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TensorRT
How to use moonbox-dev/FLUX.2-klein-4B-TensorRT with TensorRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
FLUX.2 Klein 4B TensorRT
TensorRT engines of FLUX.2 Klein 4B, made by Moonbox for NVIDIA RTX GPUs. Each precision is one folder holding the
engine, trt_runner.py (a small numpy runner: TensorRT plus Polygraphy, no PyTorch) and a script that does the rest
of the pipeline. What the engine takes and returns is under How to run.
Compatibility. The engines are built hardware compatible (Ampere and newer: RTX 30, 40 and 50 series) and
version compatible (any TensorRT 10.x from 10.13 on, through its lean runtime). That costs a little speed against an
engine built for one GPU, but no rebuild is needed. Install the runtime with
pip install "tensorrt-cu12>=10.13,<11" "tensorrt-lean-cu12>=10.13,<11" polygraphy numpy.
Files
The last column is the benchmark (details under How to run).
| Precision | File | Size | sha256 | Benchmark |
|---|---|---|---|---|
| fp16 | fp16/pipeline_trt.py |
9.4 kB | 3bd8db89b318 |
pictures vs the ONNX fp16 build: PSNR 41.0 dB mean, 35.8 dB worst (5 cases, 512-768 px, one edit); 1024 px checked by eye; transformer 0.93 s / step at 512 px (ONNX Runtime 0.95), 1.33 at 768 px (1.84) |
| fp16 | fp16/text_encoder_0.engine |
822.3 MB | d6b35e7a4c2c |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_1.engine |
713.6 MB | 9c0052aa0441 |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_2.engine |
809.3 MB | 300a22147568 |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_3.engine |
713.6 MB | d3723efafc73 |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_4.engine |
809.5 MB | 35ce6202cb9a |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_5.engine |
713.6 MB | 23a07909eda1 |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_6.engine |
808.7 MB | b86accdee36c |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_7.engine |
713.6 MB | fc5aa4c731ac |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_8.engine |
605.0 MB | 85ef5465788b |
(the same build: numbers in its first row) |
| fp16 | fp16/text_encoder_split.json |
1.3 kB | 0cad34e9bfcb |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_0.engine |
723.0 MB | ab4002e4e55a |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_1.engine |
711.4 MB | b5736217c5fb |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_10.engine |
617.9 MB | 256ec0342d8c |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_11.engine |
712.9 MB | f1fc3521a40e |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_12.engine |
408.9 MB | c4613a116e16 |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_2.engine |
542.3 MB | 851bfee725e1 |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_3.engine |
697.2 MB | 691aaf960f3b |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_4.engine |
635.8 MB | 959ef6748b3b |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_5.engine |
712.9 MB | ef28b264b178 |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_6.engine |
617.8 MB | de17fad7669d |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_7.engine |
712.9 MB | a4838e76526c |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_8.engine |
617.9 MB | 5f8de0b4971b |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_9.engine |
712.9 MB | b642ca31066a |
(the same build: numbers in its first row) |
| fp16 | fp16/transformer_split.json |
4.3 kB | eb10c3ffdd17 |
(the same build: numbers in its first row) |
| fp16 | fp16/trt_runner.py |
4.4 kB | cbc9abb1f59c |
(the same build: numbers in its first row) |
| fp16 | fp16/vae_decoder.engine |
187.0 MB | 709cc6b39b4e |
(the same build: numbers in its first row) |
| fp16 | fp16/vae_encoder.engine |
147.8 MB | eba7d499bf85 |
(the same build: numbers in its first row) |
How to run
FLUX.2 [klein] 4B (text-to-image and image editing, 4 steps) as TensorRT engines built from this model's fp16 ONNX
graphs, with pipeline_trt.py. That file is diffusers' Flux2KleinPipeline with its text encoder, transformer and VAE
running on the engines. The tokenizer, the scheduler settings and the VAE's latent statistics come from
black-forest-labs/FLUX.2-klein-4B (its configs and small
files only, not its text encoder or transformer weights).
import sys
from PIL import Image
sys.path.insert(0, "fp16")
from pipeline_trt import FluxTrt
flux = FluxTrt("fp16") # FluxTrt("fp16", resident=False) on GPUs with less than ~12 GB free
flux("a red fox in fresh snow at sunrise, photo", height=1024, width=1024, steps=4, seed=0).save("fox.png")
flux("make it night, with the moon in the sky", image=[Image.open("fox.png")], height=1024, width=1024).save("night.png")
Or python fp16/pipeline_trt.py "a red fox in fresh snow" fox.png [--image in.png] [--size 1024] [--low-memory]. It
needs torch, diffusers (tested with 0.42.1), transformers, numpy, Pillow, TensorRT 10.13 (tensorrt-cu12 or
tensorrt-lean-cu12) and Polygraphy. The engines run on any RTX 30-series or newer GPU (hardware compatibility
AMPERE_PLUS) and load in any later TensorRT 10.x (version compatible).
The engines. Together they compute the ONNX fp16/ graphs. TensorRT's builder needs about twice a graph's weights
in memory, so the text encoder (6.2 GB) and the transformer (7.75 GB) are cut into consecutive pieces of at most
0.7-0.8 GB, run one after another:
text_encoder_0..8.engine: Qwen3's first 27 layers.input_ids,attention_mask[B, 512] ->prompt_embeds[B, 512, 7680], with B = 1-2.transformer_0..12.engine:hidden_states[1, N, 128],encoder_hidden_states[1, S, 7680],timestep,img_ids,txt_ids->noise_pred[1, N, 128]. Batch 1, up to 512 text tokens, and N from 256 to 8192 image tokens. That covers 256 x 256 to 1024 x 1024 px pictures, or a 1024 x 1024 px picture edited with one 1024 x 1024 px reference image.vae_encoder.engine/vae_decoder.engine: 256 x 256 to 1024 x 1024 px.text_encoder_split.json/transformer_split.json: the order of the pieces and the tensors passed between them.
Memory. By default the transformer's and the VAE's engines stay on the GPU: about 11 GB with the VAE decoder's
workspace. The text encoder's engines load once per prompt, one at a time. With resident=False (--low-memory)
every engine loads only for its own call. That keeps the GPU to about 3.5 GB beyond torch's CUDA context, but every
denoising step then reads the transformer's 7.8 GB of engines from disk again.
Precisions. fp16/ is strongly typed: every tensor keeps the precision the fp16 ONNX graph gives it, including
the softmax and SiLU that the graph runs in fp32. Not built:
- bf16: the bf16 ONNX build is further from the original than fp16 (24.8 vs 31.7 dB).
- int8 / int4: TensorRT's int8 needs calibrated activations, and the ONNX int8 / int4 builds are weight-only
MatMulNBits, which TensorRT doesn't take.
Benchmark.
- Setup: whole pictures through the same pipeline, prompts, seed (7) and 4 steps, on an RTX 3080 Laptop GPU (16 GB).
- Reference: the ONNX
fp16/build in ONNX Runtime 1.30 (CUDA), run as the same pieces. That build is 31.7 dB from the original pipeline in fp32. The original in bf16, the usual way to run it, is 27.3 dB. - Cases: three prompts at 512 x 512 px, one at 768 x 768 px, and one 512 x 512 px edit of the reference build's first picture ("make it night, with the moon in the sky").
- Pass mark: mean PSNR >= 30 dB and every picture >= 27 dB against the reference.
- Not compared at 1024 x 1024 px: in ONNX Runtime the graph's unfused attention needs ~6 GB more than this laptop could give. TensorRT fuses it. The engines' 1024 x 1024 px picture was checked by eye and timed.
| Case | PSNR vs ONNX fp16 | transformer s / step: TensorRT | ONNX Runtime |
|---|---|---|---|
| fox, 512 px | 38.3 dB | 0.93 | 1.01 |
| lighthouse, 512 px | 35.8 dB | 0.94 | 0.90 |
| ramen, 512 px | 37.9 dB | 0.95 | 0.95 |
| fox, 768 px | 39.8 dB | 1.33 | 1.84 |
| edit, 512 px (+ 512 px reference) | 53.3 dB | 1.24 | 1.61 |
| fox, 1024 px | (picture checked) | 1.92 | (didn't fit) |
| mean / worst | 41.0 / 35.8 dB |
The step times count only running the 13 transformer pieces, with each piece's inputs and outputs copied through host memory. Engine loading is excluded. The laptop could only run the low-memory mode: there, loading took ~11 s per step and a whole 4-step picture ~65-70 s. The resident mode's speed is the step time above.
How these were made
From FLUX.2 Klein 4B at revision e7b7dc27f9: each engine was built with TensorRT's builder from Moonbox's published
ONNX graph of the same model and precision. The network is strongly typed: every tensor keeps the precision the
ONNX graph gives it, so an fp16 engine computes what the fp16 ONNX build computes. Built on an RTX 3080 Laptop GPU,
it was benchmarked against the original before upload, and the sha256 column above is what the files must hash to.
License
Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.
Original model card
The FLUX.2 [klein] model family are our fastest image models to date. FLUX.2 [klein] unifies generation and editing in a single compact architecture, delivering state-of-the-art quality with end-to-end inference in as low as under a second. Built for applications that require real-time image generation without sacrificing quality, and runs on consumer hardware, with as little as 13GB VRAM.
FLUX.2 [klein] 4B is a 4 billion parameter rectified flow transformer capable of generating images from text descriptions and supports multi-reference editing capabilities.
Fully open under Apache 2.0. Our most accessible model runs on consumer GPUs like the RTX 3090/4070. Compact but capable: supports text-to-image, image editing, and multi-reference at quality that punches above its size. Built for local development, edge deployment, and production use.
For more information, please read our blog post.
Key Features
- Our fastest distilled model for sub-second image generation.
- Best suited for interactive workflows, production deployments, and latency-critical applications.
- Text-to-image and image-to-image multi-reference editing in a single unified model.
- Runs on consumer GPUs (~13GB VRAM).
- Open weights available for commercial use under the Apache 2.0 license.
Usage
We provide a reference implementation of FLUX.2 [klein] 4B, as well as sampling code, in a dedicated GitHub repository. Developers and creatives looking to build on top of FLUX.2 [klein] 4B are encouraged to use this as a starting point.
API Endpoints
The FLUX.2 [klein] 4B model is available via the BFL API:
FLUX.2 [klein] 4B is also available in both ComfyUI and Diffusers.
Using with Diffusers ๐งจ
To use FLUX.2 [klein] 4B with the ๐งจ Diffusers python library, first install or upgrade diffusers:
pip install git+https://github.com/huggingface/diffusers.git
Then you can use Flux2KleinPipeline to run the model:
import torch
from diffusers import Flux2KleinPipeline
device = "cuda"
dtype = torch.bfloat16
pipe = Flux2KleinPipeline.from_pretrained("black-forest-labs/FLUX.2-klein-4B", torch_dtype=dtype)
pipe.enable_model_cpu_offload() # save some VRAM by offloading the model to CPU
prompt = "A cat holding a sign that says hello world"
image = pipe(
prompt=prompt,
height=1024,
width=1024,
guidance_scale=1.0,
num_inference_steps=4,
generator=torch.Generator(device=device).manual_seed(0)
).images[0]
image.save("flux-klein.png")
Limitations
- This model is not intended or able to provide factual information.
- While the model can output text, text rendered may be inaccurate or subject to distortion.
- As a statistical model, this checkpoint may represent or amplify biases observed in the training data.
- The model may fail to generate output that matches the prompts.
- Prompt following is heavily influenced by the prompting style.
Out-of-Scope Use
The model and its derivatives may not be used:
- In any way that violates applicable law.
- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way; including but not limited to the solicitation, creation, acquisition, or dissemination of child exploitative content.
- To generate or disseminate deceptive, fraudulent, misleading or otherwise harmful content.
- To generate or disseminate personal identifiable information that can be used to harm an individual.
- To harass, abuse, threaten, stalk, or bully individuals or groups of individuals.
- To create non-consensual intimate imagery or illegal pornographic content.
- For fully automated decision making or high risk applications that adversely impact an individual's legal rights or otherwise create or modify a binding, enforceable obligation.
Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
Hardware
The FLUX.2 [klein] 4B model fits in ~13GB VRAM and is accessible on NVIDIA RTX 3090/4070 and above.
Responsible AI Development
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, including 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:
- 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 https://www.iwf.org.uk/, an independent nonprofit organization dedicated to preventing online abuse, to filter known CSAM from the training data.
- 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.
- 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 FLUX.2 [klein] models.
- Release decision. After safety fine-tuning and prior to release, we conducted a final third-party evaluation of the proposed release checkpoints, focused on T2I and I2I generation of synthetic CSAM and NCII, including a comparison with other open-weight T2I and I2I models. The final FLUX.2 [klein] checkpoints 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 open-weight FLUX.2 [klein] 4B models under an Apache 2.0 license and the release of the FLUX.2 [klein] 9B models under a non-commercial license to support third-party research and development.
- Inference filters. The repository for the FLUX.2 [klein] models includes filters for NSFW and protected content in inputs and outputs. Filters or manual review must be used with the FLUX.2 [klein] 9B models under the terms of the FLUX Non-Commercial License, and we encourage deployers to implement these mitigations when using the FLUX.2 [klein] 4B models. Where we implement these features on our own hosted services, we may apply multiple filters to intercept text prompts, uploaded images, and output images. We utilize both in-house and third-party filters to mitigate against harmful outputs, such as CSAM and NCII outputs, including filters provided by https://thehive.ai/ and https://www.microsoft.com/.
- 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 [klein] implements an example of pixel-layer watermarking. Additionally, this repository includes links to the https://c2pa.org/ standard for metadata. The API for FLUX.2 [klein] applies cryptographically-signed C2PA metadata to downloaded output content to indicate that images were produced with our model.
- Policies. Acceptable use of our models and access to our API are governed by policies set out in applicable documentation, including FLUX 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.
- Safety. Black Forest Labs takes model safety seriously. 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 https://www.iwf.org.uk/ and the https://www.missingkids.org/, and welcome ongoing engagement with authorities, developers, and researchers to share intelligence about emerging risks and develop effective mitigations.
License
This model is licensed under the https://www.apache.org/licenses/LICENSE-2.0.
Trademarks & IP
This project may contain trademarks or logos for projects, products, or services. Use of Black Forest Labs and FLUX trademarks or logos in modified versions of this project must not cause confusion or imply sponsorship or endorsement. Any use of third-party trademarks, intellectual property or logos are subject to those third-party's policies.
- Downloads last month
- -
Model tree for moonbox-dev/FLUX.2-klein-4B-TensorRT
Base model
black-forest-labs/FLUX.2-klein-4B

