FLUX.2 klein
FLUX.2 klein 4B is a text-to-image model by Black Forest Labs: a 4-billion-parameter rectified-flow transformer, step-distilled to sample in four steps. LibreYOLO runs it through its diffusers pipeline behind the LibreGen factory, where it is the default model.
- Tasks
- image generation
- Sizes
- 4b at 1024 px
- Install
pip install "libreyolo[gen]"- Support tier
- Sibling tier, since v1.7.0. A separate product surface with its own factory and contract.
- Licenses
- Code MIT, weights Apache-2.0. Commercial use
Install
pip install "libreyolo[gen]"The gen extra installs diffusers, transformers and accelerate.
FLUX.2 klein loads as the diffusers Flux2KleinPipeline, which needs
diffusers 0.38.0 or later. Importing LibreGen imports none of them; they
load on first use.
Generation runs on a CUDA GPU or on Apple silicon through MPS.
device="auto" picks CUDA, then MPS, then the CPU, where the pipeline loads
in fp32 and image generation is not practical.
Predict
from libreyolo import LibreGen # Needs a CUDA GPU or Apple silicon (MPS); generation is not practical on CPU.model = LibreGen("flux2-klein-4b") # weights download on first useresult = model("a red fox sleeping in fresh snow", seed=0) result.save("fox.png") # the PNG also records prompt, seed and settingsprint(result.generated.array.shape) # (1024, 1024, 3)# Saves the image as .png under runs/generate/predict.libreyolo generate prompt="a red fox sleeping in fresh snow" model=flux2-klein-4b seed=0from libreyolo import LibreGen model = LibreGen("flux2-klein-4b") result = model("a red fox sleeping in fresh snow", imgsz=(768, 1024)) # height, widthresult = model("a red fox sleeping in fresh snow", steps=8) # more sampling steps # Two prompts, two images each (seeds 0 and 1), written to runs/generate/predict.results = model( ["a red fox sleeping in fresh snow", "a lighthouse on a rocky coast"], seed=0, n=2, save=True,)from libreyolo import LibreGen model = LibreGen("flux2-klein-4b")result = model("a red fox sleeping in fresh snow", seed=0) g = result.generatedprint(g.array.shape, g.array.dtype) # (1024, 1024, 3) uint8, RGBprint(g.prompt, g.seed) # what to pass to make it againprint(g.params) # model, imgsz, steps, guidance g.image.save("fox.jpg") # a PIL imageprint(result.summary()) # one JSON-ready rowOne prompt with n=1 returns a Results; a list of prompts or n > 1
returns a flat list in prompt order, and stream=True a generator. A string
is always a prompt, never a path. result.generated is a GeneratedImage:
array is the (H, W, 3) uint8 RGB image and image the same image as a
PIL.Image, prompt the text, seed the integer that reproduces it, and
params the model, imgsz and every setting in effect, defaults included.
result.save(path) writes the image, and a PNG also stores prompt, seed and
params as JSON in a libreyolo text chunk. result.plot() returns the image.
save=True writes each image to a new runs/generate/predict folder per
call, the file named after its index, prompt and seed; output_path names the
file instead, for one prompt with n=1.
The first call downloads about 16 GB at a pinned revision, with nothing gated
and no Hugging Face login, from Black Forest Labs' repository
black-forest-labs/FLUX.2-klein-4B
into weights/LibreFlux2Klein4b/. Only the pipeline's component folders are
fetched, not the repository's single-file checkpoint. LibreGen(path) loads a
local directory that holds a Flux2KleinPipeline in the diffusers layout
instead, such as an offline copy or a fine-tune made with upstream tooling.
flux2-klein, flux.2-klein and flux.2-klein-4b are aliases of
flux2-klein-4b, and LibreGen() with no argument loads it.
A seed, with the same model and settings, gives the same image. Image i of a
prompt uses seed + i, and every prompt in a list starts from the same seed.
Without a seed, a fresh one is drawn for each prompt and recorded in
result.generated.seed. The seed drives a random generator on the CPU, so the
starting noise is the same on every device; the image can still differ across
devices and precisions by numerical error.
Image-conditioned generation, which FLUX.2 klein supports upstream, is not
available yet: source= raises NotImplementedError.
Settings
Every setting has a default, so all are optional. A name the model does not
have raises TypeError and lists the supported ones.
| Setting | Default | Meaning |
|---|---|---|
imgsz | 1024 | Output size: an int for a square image, or (height, width). Each side is rounded up to a multiple of 16, with a warning. |
steps | 4 | Sampling steps. The distilled checkpoint is trained for 4. |
guidance | 1.0 | Fixed. The checkpoint is step-distilled and runs without guidance, so any other value raises ValueError. |
The constructor takes device, dtype and offload. dtype="auto" is bf16
on CUDA (fp16 on a GPU without bf16), bf16 on MPS from macOS 14, and fp32 on
the CPU and on older macOS; "bf16", "fp16" and "fp32" force one.
offload=True keeps idle pipeline components off the GPU; it needs CUDA and
raises on any other device. model.pipeline is the loaded diffusers
Flux2KleinPipeline, for anything the LibreGen call does not cover.
Export
| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Image generation | Image generation to ONNX: not supported | Image generation to TorchScript: not supported | Image generation to ExecuTorch: not supported | Image generation to TensorRT: not supported | Image generation to OpenVINO: not supported | Image generation to Paddle: not supported | Image generation to MNN: not supported | Image generation to RKNN: not supported | Image generation to ncnn: not supported | Image generation to TFLite: not supported | Image generation to CoreML: not supported | Image generation to Core AI: not supported |
Export is not implemented: the model is a sampling loop over several
networks, and LibreYOLO has no exportable graph contract for that yet (ADR
0030 in the library). export(), train() and val() raise
NotImplementedError. train(data=...) is reserved for fine-tuning on
captioned images, and val(data=...) for generation metrics on a captioned
image set.
Licensing
Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.
This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.
- Original work
- FLUX.2 klein 4B, Black Forest Labs
- Upstream license
- Apache-2.0
- Upstream source
- github.com/black-forest-labs/flux2
- LibreYOLO code
- MIT
- Weights
- Apache-2.0, distributed by their authors. LibreYOLO does not host or mirror them.
- Interpretation
- Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. Black Forest Labs declares Apache-2.0 on the Hugging Face repository LibreYOLO downloads, black-forest-labs/FLUX.2-klein-4B, in its license tag and LICENSE.md, and its model card calls the model fully open under Apache 2.0. The license is not uniform across FLUX.2: Black Forest Labs releases the klein 9B models and FLUX.2 dev under its FLUX Non-Commercial License, and LibreYOLO does not load those. LibreYOLO's adapter is its own MIT code that calls the Apache-2.0 diffusers Flux2KleinPipeline; no upstream source is ported. The weights are not redistributed: they download from that repository at revision e7b7dc27f91deacad38e78976d1f2b499d76a294, component folders only.
FLUX.2 klein is the work of Black Forest Labs. Its reference code is black-forest-labs/flux2 and its weights are black-forest-labs/FLUX.2-klein-4B, both Apache-2.0. The same repository supplies the FLUX.2 VAE that Speridlabs Idol reads its input through. LibreYOLO adds no content filter; the model card lists the uses Black Forest Labs excludes.
Citation
@misc{flux-2-2025,
author={Black Forest Labs},
title={{FLUX.2: Frontier Visual Intelligence}},
year={2025},
howpublished={\url{https://bfl.ai/blog/flux-2}},
}Copied from the authors' citation block at github.com/black-forest-labs/flux2#citation.