查看 Markdown

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.

任务
image generation
尺寸
4b at 1024 px
安装
pip install "libreyolo[gen]"
支持层级
兄弟层级,自 v1.7.0 起。一个独立的产品面,有自己的工厂和契约。
上游
FLUX.2 klein 4B,由 Black Forest Labs 发布,采用 Apache-2.0 许可。论文、源码
许可
代码采用 MIT,权重采用 Apache-2.0。商用

Install

bash
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

Python
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)
CLI
# Saves the image as .png under runs/generate/predict.libreyolo generate prompt="a red fox sleeping in fresh snow" model=flux2-klein-4b seed=0
Settings
from 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,)
Results
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 row

One 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.

SettingDefaultMeaning
imgsz1024Output size: an int for a square image, or (height, width). Each side is rounded up to a multiple of 16, with a warning.
steps4Sampling steps. The distilled checkpoint is trained for 4.
guidance1.0Fixed. 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

任务ONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
Image generationImage generation to ONNX:不支持Image generation to TorchScript:不支持Image generation to ExecuTorch:不支持Image generation to TensorRT:不支持Image generation to OpenVINO:不支持Image generation to Paddle:不支持Image generation to MNN:不支持Image generation to RKNN:不支持Image generation to ncnn:不支持Image generation to TFLite:不支持Image generation to CoreML:不支持Image generation to Core AI:不支持

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

请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。

这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。

原始工作
FLUX.2 klein 4B, Black Forest Labs
上游许可
Apache-2.0
LibreYOLO 代码
MIT
权重
采用 Apache-2.0 许可,由作者分发。LibreYOLO 不托管或镜像这些权重。
解读
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}},
}

复制自作者在 github.com/black-forest-labs/flux2#citation 上提供的引用块。

已针对 LibreYOLO v1.7.0 验证。本页的支持表、检查点和基准测试数据由已发布的库和权重生成,并非手工编写。