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.
- Tarefas
- image generation
- Tamanhos
- 4b at 1024 px
- Instalação
pip install "libreyolo[gen]"- Nível de suporte
- Nível irmão, desde a v1.7.0. Uma superfície de produto separada, com sua própria fábrica e seu próprio contrato.
- Origem
- FLUX.2 klein 4B por Black Forest Labs, Apache-2.0. Artigo, código-fonte
- Licenças
- Código MIT, pesos Apache-2.0. Uso comercial
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
| Tarefa | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Image generation | Image generation to ONNX: incompatível | Image generation to TorchScript: incompatível | Image generation to ExecuTorch: incompatível | Image generation to TensorRT: incompatível | Image generation to OpenVINO: incompatível | Image generation to Paddle: incompatível | Image generation to MNN: incompatível | Image generation to RKNN: incompatível | Image generation to ncnn: incompatível | Image generation to TFLite: incompatível | Image generation to CoreML: incompatível | Image generation to Core AI: incompatível |
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
Confira a licença no repositório do Hugging Face correspondente aos pesos que você baixar. Cada checkpoint na organização LibreYOLO tem uma licença, e ela nem sempre é a mesma em toda a família. Esse repositório é a fonte oficial. O resumo abaixo descreve o que se aplicava na última verificação desta página.
Esta é uma descrição das licenças envolvidas, não uma orientação jurídica. Se a resposta tiver importância comercial, leia as licenças e procure sua própria assessoria.
- Trabalho original
- FLUX.2 klein 4B, Black Forest Labs
- Licença original
- Apache-2.0
- Código-fonte original
- github.com/black-forest-labs/flux2
- Código do LibreYOLO
- MIT
- Pesos
- Apache-2.0, distribuído pelos autores. O LibreYOLO não hospeda nem espelha esses pesos.
- Interpretação
- 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}},
}Copiado do bloco de citação dos autores em github.com/black-forest-labs/flux2#citation.