Black Forest Labs FLUX.3 Image Klein 现已上线,并且从第一天起就支持 Diffusers。该模型同时具备文本到图像生成和多参考图像到图像转换功能,并新增了一项新功能:布局控制。您可以在提示词中写入边界框,以指定图像的每个部分应放置的位置,或确定参考图像中的哪些部分需要移动。
这两个开源检查点均包含在 FLUX.3 Image Klein 集合中:
您可以前往 Hugging Face 空间,立即生成一些图像!
TL;DR
一个模型即可实现文本到图像、多参考图像到图像以及边界框布局控制。
蒸馏后的检查点在 H100 上仅需约 2 秒即可生成 1024 × 1024 的图像。
NVFP4 和 FP8 权重可通过 from_single_file 加载,适用于显存较小的 GPU。
提供用于文本到图像和图像编辑的 LoRA 训练脚本。
以模块化 Diffusers 管道形式发布,您可以移除或添加自己的模块。
目录
入门指南
安装最新的 diffusers 和 transformers(用于 Qwen3-VL 文本编码器):
pip install -U diffusers transformers
加载蒸馏后的检查点并生成图像:
import torch
from diffusers import ModularPipeline
pipe = ModularPipeline.from_pretrained( "black-forest-labs/flux-3-image-klein" )
pipe.load_components(dtype=torch.bfloat16)
pipe.to( "cuda" )
pipe(prompt= "a red fox" , output= "images" )[ 0 ].save( "fox.png" )
FLUX.3 能做什么
文本到图像
FLUX.3 对包含主体、场景、光线、构图和风格的完整场景描述响应最佳。Black Forest Labs 官方提示词指南中有更多技巧。默认情况下,蒸馏后的检查点通过 16 步生成 1024 × 1024 的图像。您可以传递 height、width 或 num_inference_steps 参数来更改这些设置。
prompt = (
"A wide-angle wildlife photograph of a red fox standing alert in a snow-covered forest clearing at golden hour. "
"The fox is centered in the frame, its thick orange winter coat contrasting with the fresh white snow, breath "
"visible in the cold air. Snow-laden pine trees fill the softly blurred background, and low warm sunlight rakes "
"across the scene from the left, casting long blue shadows."
)
fox = pipe(
prompt=prompt,
generator=torch.Generator().manual_seed( 0 ),
output= "images"
)[ 0 ]
fox.save( "fox.png" )
文本到图像
图像到图像
通过 image 参数传入参考图像(或多个)。将提示词编写为您想要生成的图像的说明,并包含所需的更改。
prompt = (
"The same red fox in the same snow-covered forest clearing, now at night under a full moon: cool blue "
"moonlight, deep shadows, stars visible through the pine branches, the fox's eyes catching the light."
)
night = pipe(
prompt=prompt,
image=fox,
generator=torch.Generator().manual_seed( 0 ),
output= "images" ,
)[ 0 ]
night.save( "night.png" )
图像到图像
使用多个参考时,在提示词中按传入 image 参数的顺序引用它们,格式为 <ref_image_0>、<ref_image_1> 等:
red_fox = pipe(prompt= "a red fox" , generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
bench = pipe(prompt= "a wooden bench" , generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
combined = pipe(
prompt= "The fox from
image=[red_fox, bench],
output= "images" ,
)[ 0 ]
combined.save( "combined.png" )
坐在长椅上的狐狸
布局控制
在说明之后添加一个区域 JSON 列表。每个区域包含 id、bbox 和 desc,并在说明中以 <id> 的形式提及。
边界框的格式为 [y_min, x_min, y_max, x_max],先写 y 坐标,数值范围为 0–1000。由于该比例是归一化的,因此相同的边界框适用于任何图像尺寸。
在新图像中放置区域
layout_prompt = (
"极简主义图形插图,画面中央是一个黑色的人物剪影
'[{"id": "background_1", "bbox": [0, 0, 1000, 1000], "desc": "一片平坦的霓虹黄绿色区域,带有微妙的纸张纹理和细腻的有机颗粒感。"}, {"id": "silhouette_1", "bbox": [150, 150, 850, 850], "desc": "一个处于运动状态的人物黑色剪影,由密集的点画墨水构成。前缘轮廓清晰实心;后方的手臂和腿部则分解为粗糙的正方形像素和散落的圆点。"}]'
)
runner = pipe(prompt=layout_prompt, generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
每个区域的 desc 内容绘制在其对应的 bbox 内部
在参考图像中移动区域
对于编辑操作,每个区域指明其内容的来源(参考图像中的 src_bbox)以及目标位置(输出图像中的 tgt_bbox)。如果某个区域的两个框坐标相同,则该区域保持原位不动。
此示例将针织骑士向上并向左移动,同时固定背景、悬崖、针、龙和火焰:
from diffusers.utils import load_image
knight_image = load_image( "knight_orig.png" )
edit_prompt = (
"在
'[{"id": "knight_1", "from": "ref_image_0", "src_bbox": [500, 150, 850, 350], "tgt_bbox": [194, 55, 544, 255], '
'"desc": "一个用厚灰色羊毛纱线钩织而成的微型 amigurumi 骑士。"}, '
'{"id": "backdrop_1", "from": "ref_image_0", "src_bbox": [0, 0, 1000, 1000], "tgt_bbox": [0, 0, 1000, 1000], '
'"desc": "柔和且失焦的奶油色与靛蓝色针织纱线背景。"}, '
'{"id": "cliff_1", "from": "ref_image_0", "src_bbox": [300, 0, 1000, 450], "tgt_bbox": [300, 0, 1000, 450], '
'"desc": "由芥末色、赤陶色和靛蓝色纱线团堆叠而成的陡峭悬崖。"}, '
'{"id": "needle_1", "from": "ref_image_0", "src_bbox": [420, 250, 550, 450], "tgt_bbox": [420, 250, 550, 450], '
'"desc": "一根超大号的抛光钢制挂毯针。"}, '
'{"id": "dragon_1", "from": "ref_image_0", "src_bbox": [100, 600, 950, 1000], "tgt_bbox": [100, 600, 950, 1000], '
'"desc": "一个用赤陶色和芥末色纱线编织的大型蓬松针织龙。"}, '
'{"id": "fire_1", "from": "ref_image_0", "src_bbox": [350, 400, 650, 650], "tgt_bbox": [350, 400, 650, 650], '
'"desc": "悬浮在半空中的炽热橙色安哥拉纱线卷曲团块。"}]'
)
moved = pipe(prompt=edit_prompt, image=knight_image, generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
骑士从其 src_bbox 移动到其 tgt_bbox,而场景的其余部分保持不动
基础模型及量化变体
基础模型
上述所有内容均使用蒸馏后的检查点。基础检查点运行 50 步,并采用无分类器引导(classifier-free guidance),它是进行微调的目标(参见 LoRA finetuning)。
pipe = ModularPipeline.from_pretrained( "black-forest-labs/flux-3-image-klein-base" )
pipe.load_components(dtype={ "vae" : torch.float32, "default" : torch.bfloat16})
pipe.to( "cuda" )
pipe.guider = pipe.guider.new(guidance_scale= 5.0 )
image = pipe(prompt=prompt, output= "images" )[ 0 ]
单文件格式检查点
Black Forest Labs 还以单文件形式提供 transformer,包括 bf16 以及两种量化格式:fp8r(逐行 FP8)和 nvfp4 。使用 from_single_file 加载其中任意一种,然后通过名称加载其他组件,以避免重复下载 bf16 版本的 transformer。
from diffusers import BFLQuantizationConfig, Flux3Transformer2DModel, ModularPipeline
model_id = "black-forest-labs/flux-3-image-klein-base"
variant = "fp8r"
transformer = Flux3Transformer2DModel.from_single_file(
f"https://huggingface.co/ {model_id} /blob/main/variants/ {variant} /model.safetensors" ,
config=model_id,
subfolder= "transformer" ,
quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16),
dtype=torch.bfloat16,
)
pipe = ModularPipeline.from_pretrained(model_id)
pipe.load_components(dtype=torch.bfloat16)
pipe.update_components(transformer=transformer)
pipe.to( "cuda" )
对于未量化的单文件,请使用 https://huggingface.co/{model_id}/blob/main/model.safetensors 并移除 quantization_config 。
变体 (Variant)
Fast kernels on
其他 GPU
fp8r
计算能力 8.9+ (Ada, Hopper, Blackwell)
权重在每一步去量化:内存占用更低,无加速效果
nvfp4
Blackwell,需同时安装版本一致的 flashinfer-python 和 flashinfer-cubin
与上述相同
LoRA 微调
FLUX.3 支持文本到图像和图像到图像生成,这使其成为自定义 LoRA 的理想基础。diffusers 提供了针对这两项任务的 DreamBooth LoRA 训练脚本(你也可以使用 Ostris 的 AI Toolkit 进行训练)。
以下是一个文本到图像的示例,它从 multimodalart/1920-raider-waite-tarot-public-domain 数据集学习塔罗牌风格,并通过 trtcrd 触发:
accelerate launch train_dreambooth_lora_flux3_klein.py \
--pretrained_model_name_or_path= "black-forest-labs/flux-3-image-klein-base" \
--dataset_name= "multimodalart/1920-raider-waite-tarot-public-domain" \
--caption_column= "caption" \
--instance_prompt= "trtcrd" \
--output_dir= "trained-flux3-tarot-lora" \
--mixed_precision= "bf16" \
--resolution=1024 \
--use_aspect_ratio_buckets \
--train_batch_size=1 \
--rank=16 \
--lora_alpha=16 \
--learning_rate=1e-4 \
--lr_scheduler= "constant" \
--max_train_steps=1500 \
--validation_prompt= "a trtcrd of a cat, tarot style" \
--validation_epochs=25 \
--seed=0 \
--push_to_hub
为了降低内存使用,请添加以下优化标志:
--gradient_checkpointing \
--cache_latents \
--use_8bit_adam
--gradient_checkpointing 在反向传播中重新计算激活值(降低 VRAM 占用,速度稍慢),--cache_latents 预编码图像并释放 VAE,而 --use_8bit_adam 将优化器状态保持在 8 位。
有几个参数值得尝试。下表使用不同的 LoRA 秩和优化器训练相同的塔罗牌风格;这些适配器托管在 Hub 上的 diffusers-modular/flux3-tarot-lora 。更多训练功能和配置请参阅 DreamBooth FLUX.3 README 。
对于基于指令的编辑,图像到图像的脚本 (train_dreambooth_lora_flux3_klein_img2img.py) 在(参考图像、目标图像、指令)三元组上进行训练,其中参考图像在提示中通过
请参阅 DreamBooth FLUX.3 README 以获取所有选项和完整的图像到图像示例。
运行成本
在本节中,我们将讨论模型的内存消耗和生成速度。
内存
名称
峰值分配(加载后)GiBs
峰值分配(推理后)GiBs
nvfp4 (RTX6000)
13.4
15.3
fp8r (H100)
14.35
16.27
bf16 (H100)
18.80
20.72
如果你的内存较少:
加载量化的 transformer 。
单独运行文本编码器并释放它。它每张图片仅运行一次,在去噪之前(参见“编码一次,生成多次”)。
开启自动 CPU 卸载,该功能仅在组件运行时将其移动到 GPU(我们未对此进行基准测试)
from diffusers import ComponentsManager, ModularPipeline
manager = ComponentsManager()
manager.enable_auto_cpu_offload(device= "cuda" )
pipe = ModularPipeline.from_pretrained( "black-forest-labs/flux-3-image-klein" , components_manager=manager)
pipe.load_components(dtype={ "vae" : torch.float32, "default" : torch.bfloat16})
速度
蒸馏检查点(16 步)的端到端计时,在预热后取三次运行的平均值:
工作流
输出尺寸
时间
峰值内存
文本到图像
1024 × 1024
1.93 秒
23.8 GiB
图像到图像,一个 1024 × 1024 参考图
1024 × 1024
3.87 秒
23.8 GiB
布局编辑(骑士),一张 1360 × 768 参考图
1360 × 768
4.10 秒
23.8 GiB
单张 NVIDIA H100 80GB,无卸载,默认注意力后端。
参考图像会使时间大致翻倍。参考令牌与生成的文本和图像加入同一序列,因此一张 1024 × 1024 的参考图会为每次 Transformer 调用增加 4,096 个令牌。
每次 Transformer 调用的令牌堆叠柱状图:文生图 4,256 个令牌;图生图 8,272 个;布局文生图 4,336 个;布局图生图 8,800 个。
架构
让我们逐块拆解模型。该模型接受三种类型的令牌:
文本
正在生成的带噪图像
以及可选的参考图像
从像素到令牌
FLUX.3 是一个用于图像生成的潜在空间流模型。这意味着去噪器以潜在变量作为输入,并输出潜在变量。我们使用 VAE 将潜在变量解码回像素。FLUX.3 使用与 Flux.2 相同的 VAE 架构。
FLUX.2 的 VAE 在两个方向上将图像压缩 8 倍至 32 个通道,然后将该潜在变量中每个 2 × 2 的块打包为一个具有 128 个通道的单个令牌。
因此,一个令牌覆盖一个 16 × 16 像素的块,一张 1024 × 1024 的图像变为由 4,096 个令牌组成的 64 × 64 网格。带噪图像以完全相同形状的随机噪声开始。参考图像经过相同的 VAE 编码器和打包过程,并保持其自身的大小。
从提示词到令牌
文本编码器是 Qwen3-VL,一种视觉语言模型。FLUX.3 不仅仅取其最后一层。它读取其 36 层中的八层的隐藏状态(第 4、8、…、32 层)并将它们堆叠起来,因此每个文本令牌在通过线性层投影到 Transformer 的宽度 3072 之前,变成一个 8 × 2560 = 20,480 维的向量。
这为 Transformer 提供了来自语言模型多个深度的特征,而不仅仅是其最后一层。提示词被填充至 80 个令牌的倍数,Transformer 也会关注填充部分,这就是为什么每个调用需要一个提示词的原因。
两个阶段
Transformer 分两个阶段处理令牌:
阶段 1:按模式块。每个流经过具有各自权重的 5 个块。文本有自己的块,带噪图像有自己的块,参考图像也有自己的块。
阶段 2:联合块。这些流被连接成一个序列 [文本 | 图像 | 参考],该序列经过共享一组权重的 28 个块。
这两个阶段的区别在于谁可以关注谁。
在阶段 1 中,每个流只关注自身,因此每种类型的令牌首先按照自己的条件进行细化。在阶段 2 中,所有内容都相互关注,图像从文本和参考中学习。作为比较,FLUX.2 的双流块也为文本和图像提供单独的权重,但让它们从一开始就相互关注。FLUX.3 先将流完全分开,然后再合并它们。
最后,文本和参考令牌被简单地丢弃。只有图像令牌通过输出层,这些层预测如何将它们向干净图像移动一步。
一个块内部
无论处于哪个阶段,每个块的形状都相同。注意力和 MLP 在相同的归一化输入上并行运行,它们的总和加回到残差流中。
每个块以 LayerNorm 开始,该 LayerNorm 没有自己的学习缩放或偏移。缩放、偏移和门控来自时间步嵌入(这称为调制)。在注意力内部,查询和键经过 RMS 归一化并获得旋转位置嵌入(RoPE),我们在下面会看到这一点。
在联合块中,所有令牌共享相同的权重,但文本、图像和参考令牌各自获得自己的缩放、偏移和门控。
def block ( x, shift, scale, gate ):
h = layer_norm(x)
h = ( 1 + scale) * h + shift
q, k, v = to_q(h), to_k(h), to_v(h)
q, k = rope(rms_norm(q)), rope(rms_norm(k))
out = attention(q, k, v) + mlp(h)
return x + gate * out
每个令牌都有自己的时间步
在 FLUX.1 和 FLUX.2 中,一个时间步嵌入(timestep embedding)对每个 token 进行调制。而在 FLUX.3 中,调制方式取决于 token 的类型。
带有噪声的图像 token 由当前时间步 t 进行调制。文本 token 和参考 token 始终由时间步 0 进行调制,这意味着“干净、无需去噪”。因此,即使某个参考图像看起来与输出几乎相同,它也被标记为给定上下文,而非需要生成的内容。
Black Forest Labs FLUX.3 Image Klein is here, and it runs in Diffusers from day one. One model does text-to-image and multi-reference image-to-image, and it adds something new, the
layout control . You write bounding boxes into the prompt to say where each part of the image should go, or which parts of a reference image to move.
Both open checkpoints are in the FLUX.3 Image Klein collection :
You can head on to the Hugging Face space and generate some images right now!
TL;DR
One model for text-to-image, multi-reference image-to-image, and bounding-box layout control.
The distilled checkpoint makes a 1024 × 1024 image in about 2 seconds on an H100.
NVFP4 and FP8 weights load with from_single_file , for smaller GPUs.
LoRA training scripts for both text-to-image and image editing.
Ships as a Modular Diffusers pipeline, so you can pop blocks out or add your own.
Contents
Getting started
Install the latest diffusers and transformers (for the Qwen3-VL text encoder):
pip install -U diffusers transformers
Load the distilled checkpoint and generate an image:
import torch
from diffusers import ModularPipeline
pipe = ModularPipeline.from_pretrained( "black-forest-labs/flux-3-image-klein" )
pipe.load_components(dtype=torch.bfloat16)
pipe.to( "cuda" )
pipe(prompt= "a red fox" , output= "images" )[ 0 ].save( "fox.png" )
What FLUX.3 can do
Text-to-image
FLUX.3 responds best to a full scene description with the subject, the setting, the light, the composition, and the style. The official prompting guide from Black Forest Labs has more tips. The distilled checkpoint generates a 1024 × 1024 image in 16 steps by default. Pass height , width , or num_inference_steps to change them.
prompt = (
"A wide-angle wildlife photograph of a red fox standing alert in a snow-covered forest clearing at golden hour. "
"The fox is centered in the frame, its thick orange winter coat contrasting with the fresh white snow, breath "
"visible in the cold air. Snow-laden pine trees fill the softly blurred background, and low warm sunlight rakes "
"across the scene from the left, casting long blue shadows."
)
fox = pipe(
prompt=prompt,
generator=torch.Generator().manual_seed( 0 ),
output= "images"
)[ 0 ]
fox.save( "fox.png" )
Text to image
Image-to-image
Pass a reference image (or more) with the image argument. Write the prompt as a caption of the image you want , with the change included.
prompt = (
"The same red fox in the same snow-covered forest clearing, now at night under a full moon: cool blue "
"moonlight, deep shadows, stars visible through the pine branches, the fox's eyes catching the light."
)
night = pipe(
prompt=prompt,
image=fox,
generator=torch.Generator().manual_seed( 0 ),
output= "images" ,
)[ 0 ]
night.save( "night.png" )
Image to image
With several references, refer to them in the prompt as
red_fox = pipe(prompt= "a red fox" , generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
bench = pipe(prompt= "a wooden bench" , generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
combined = pipe(
prompt= "The fox from
image=[red_fox, bench],
output= "images" ,
)[ 0 ]
combined.save( "combined.png" )
The fox on the bench
Layout control
Add a JSON list of regions after the caption. Each region has an id , a bbox , and a desc , and the caption mentions it as
Boxes are written as [y_min, x_min, y_max, x_max] , y first , on a 0–1000 scale. Because the scale is normalized, the same box works at any image size.
Placing regions in a new image
layout_prompt = (
"Minimalist graphic illustration featuring a black silhouette of a person
"solid, vibrant chartreuse background
"pose, facing toward the left side of the frame. "
'[{"id": "background_1", "bbox": [0, 0, 1000, 1000], "desc": "A flat field of neon yellow-green with a subtle '
'paper texture and fine, organic grain."}, {"id": "silhouette_1", "bbox": [150, 150, 850, 850], "desc": "A '
"black silhouette of a person in motion, made of dense stippled ink. The leading edges are solid; the trailing "
'arm and leg dissolve into coarse square pixels and scattered dots."}]'
)
runner = pipe(prompt=layout_prompt, generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
Each region's desc is drawn inside its bbox
Moving regions within a reference image
For edits, each region says where its content comes from ( src_bbox in the reference) and where it goes ( tgt_bbox in the output). A region with the same two boxes stays where it is.
This example moves the knitted knight up and to the left, and pins the backdrop, the cliff, the needle, the dragon, and the fire:
from diffusers.utils import load_image
knight_image = load_image( "knight_orig.png" )
edit_prompt = (
"In
"yarn cliff
"
'[{"id": "knight_1", "from": "ref_image_0", "src_bbox": [500, 150, 850, 350], "tgt_bbox": [194, 55, 544, 255], '
'"desc": "A miniature amigurumi knight crocheted from thick grey woolen yarn."}, '
'{"id": "backdrop_1", "from": "ref_image_0", "src_bbox": [0, 0, 1000, 1000], "tgt_bbox": [0, 0, 1000, 1000], '
'"desc": "A soft, out-of-focus backdrop of cream and indigo knitted yarn."}, '
'{"id": "cliff_1", "from": "ref_image_0", "src_bbox": [300, 0, 1000, 450], "tgt_bbox": [300, 0, 1000, 450], '
'"desc": "A steep cliff of stacked yarn skeins in mustard, terracotta, and indigo."}, '
'{"id": "needle_1", "from": "ref_image_0", "src_bbox": [420, 250, 550, 450], "tgt_bbox": [420, 250, 550, 450], '
'"desc": "An oversized polished steel tapestry needle."}, '
'{"id": "dragon_1", "from": "ref_image_0", "src_bbox": [100, 600, 950, 1000], "tgt_bbox": [100, 600, 950, 1000], '
'"desc": "A large, fluffy knitted dragon in terracotta and mustard yarn."}, '
'{"id": "fire_1", "from": "ref_image_0", "src_bbox": [350, 400, 650, 650], "tgt_bbox": [350, 400, 650, 650], '
'"desc": "Curled puffs of fiery orange angora thread suspended in mid-air."}]'
)
moved = pipe(prompt=edit_prompt, image=knight_image, generator=torch.Generator().manual_seed( 0 ), output= "images" )[ 0 ]
The knight moves from its src_bbox to its tgt_bbox , and the rest of the scene stays put
Base model and quantized variants
Base model
Everything above uses the distilled checkpoint. The base checkpoint runs 50 steps with classifier-free guidance, and it's the one to fine-tune (see LoRA finetuning ).
pipe = ModularPipeline.from_pretrained( "black-forest-labs/flux-3-image-klein-base" )
pipe.load_components(dtype={ "vae" : torch.float32, "default" : torch.bfloat16})
pipe.to( "cuda" )
pipe.guider = pipe.guider.new(guidance_scale= 5.0 )
image = pipe(prompt=prompt, output= "images" )[ 0 ]
Single-file format checkpoints
Black Forest Labs also ships the transformer as a single file, in bf16 and in two quantized formats: fp8r (rowwise FP8) and nvfp4 . Load any of them with from_single_file , then load the other components by name so the bf16 transformer isn't downloaded too.
from diffusers import BFLQuantizationConfig, Flux3Transformer2DModel, ModularPipeline
model_id = "black-forest-labs/flux-3-image-klein-base"
variant = "fp8r"
transformer = Flux3Transformer2DModel.from_single_file(
f"https://huggingface.co/ {model_id} /blob/main/variants/ {variant} /model.safetensors" ,
config=model_id,
subfolder= "transformer" ,
quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16),
dtype=torch.bfloat16,
)
pipe = ModularPipeline.from_pretrained(model_id)
pipe.load_components(dtype=torch.bfloat16)
pipe.update_components(transformer=transformer)
pipe.to( "cuda" )
For the unquantized single file, use https://huggingface.co/{model_id}/blob/main/model.safetensors and drop quantization_config .
Variant
Fast kernels on
Other GPUs
fp8r
Compute capability 8.9+ (Ada, Hopper, Blackwell)
Weights are dequantized each step: lower memory, no speedup
nvfp4
Blackwell, with flashinfer-python and flashinfer-cubin at the same version
Same as above
LoRA finetuning
FLUX.3 works for both text-to-image and image-to-image, which makes it a great base for custom LoRAs. diffusers ships DreamBooth LoRA training scripts for both tasks (you can also train with Ostris' AI Toolkit ).
Here is a text-to-image example that learns a tarot-card style from the multimodalart/1920-raider-waite-tarot-public-domain dataset, triggered with trtcrd :
accelerate launch train_dreambooth_lora_flux3_klein.py \
--pretrained_model_name_or_path= "black-forest-labs/flux-3-image-klein-base" \
--dataset_name= "multimodalart/1920-raider-waite-tarot-public-domain" \
--caption_column= "caption" \
--instance_prompt= "trtcrd" \
--output_dir= "trained-flux3-tarot-lora" \
--mixed_precision= "bf16" \
--resolution=1024 \
--use_aspect_ratio_buckets \
--train_batch_size=1 \
--rank=16 \
--lora_alpha=16 \
--learning_rate=1e-4 \
--lr_scheduler= "constant" \
--max_train_steps=1500 \
--validation_prompt= "a trtcrd of a cat, tarot style" \
--validation_epochs=25 \
--seed=0 \
--push_to_hub
To reduce memory usage, add a few optimization flags:
--gradient_checkpointing \
--cache_latents \
--use_8bit_adam
--gradient_checkpointing recomputes activations in the backward pass (lower VRAM, slightly slower), --cache_latents pre-encodes the images and frees the VAE, and --use_8bit_adam keeps the optimizer states in 8-bit.
A couple of knobs are worth experimenting with. The grid below trains the same tarot style with different LoRA ranks and optimizers; the adapters are on the Hub at diffusers-modular/flux3-tarot-lora . More training features and configurations are documented in the DreamBooth FLUX.3 README .
For instruction-based editing, the image-to-image script ( train_dreambooth_lora_flux3_klein_img2img.py ) trains on (reference image, target image, instruction) triplets, where the reference is addressed in the prompt as
See the DreamBooth FLUX.3 README for all options and the full image-to-image example.
What it costs to run
In this section, we will talk about the memory consumption and the speed of generation of the models.
Memory
name
peak allocated (after load) GiBs
peak allocated (after inference) GiBs
nvfp4 (RTX6000)
13.4
15.3
fp8r (H100)
14.35
16.27
bf16 (H100)
18.80
20.72
If you have less memory:
Load a quantized transformer .
Run the text encoder separately and free it. It only runs once per image, before denoising (see Encode once, generate many ).
Turn on automatic CPU offloading, which moves each component to the GPU only while it runs (we didn't benchmark this)
from diffusers import ComponentsManager, ModularPipeline
manager = ComponentsManager()
manager.enable_auto_cpu_offload(device= "cuda" )
pipe = ModularPipeline.from_pretrained( "black-forest-labs/flux-3-image-klein" , components_manager=manager)
pipe.load_components(dtype={ "vae" : torch.float32, "default" : torch.bfloat16})
Speed
End-to-end timings for the distilled checkpoint (16 steps), averaged over three runs after a warmup:
Workflow
Output size
Time
Peak memory
Text-to-image
1024 × 1024
1.93 s
23.8 GiB
Image-to-image, one 1024 × 1024 reference
1024 × 1024
3.87 s
23.8 GiB
Layout editing (the knight), one 1360 × 768 reference
1360 × 768
4.10 s
23.8 GiB
Single NVIDIA H100 80GB, no offloading, default attention backend.
A reference image roughly doubles the time. Reference tokens join the same sequence as the text and the image being generated, so a 1024 × 1024 reference adds 4,096 tokens to every transformer call
Stacked bars of tokens per transformer call: text-to-image 4,256 tokens; image-to-image 8,272; layout text-to-image 4,336; layout image-to-image 8,800
The architecture
Let's open the model up, one piece at a time. The model takes three kinds of tokens:
text
the noisy image being generated
and optional reference images
From pixels to tokens
FLUX.3 is a latent-space flow model for image generation. This means that the denoiser takes latents as inputs and produces latents as outputs. We use a VAE to decode the latents back to pixels. FLUX.3 uses the same VAE architecture as Flux.2.
The FLUX.2 VAE compresses an image 8× in each direction into 32 channels, and then every 2 × 2 patch of that latent is packed into a single token with 128 channels.
So one token covers a 16 × 16 pixel patch , and a 1024 × 1024 image becomes a 64 × 64 grid of 4,096 tokens. The noisy image starts as random noise of exactly that shape. A reference image goes through the same VAE encoder and packing, and keeps its own size.
From prompt to tokens
The text encoder is Qwen3-VL, a vision-language model. FLUX.3 doesn't just take its last layer. It reads the hidden states of eight of its 36 layers (layers 4, 8, …, 32) and stacks them, so each text token becomes a 8 × 2560 = 20,480-dimensional vector before a linear layer projects it to the transformer's width of 3072.
This gives the transformer features from several depths of the language model, not just its final layer. The prompt is padded to a multiple of 80 tokens, and the transformer attends to the padding too, which is why the pipeline takes one prompt per call.
Two stages
The transformer processes the tokens in two stages:
Stage 1: per-mode blocks. Each stream goes through 5 blocks with its own weights. Text has its own blocks, the noisy image has its own, and the reference images have their own.
Stage 2: joint blocks. The streams are concatenated into one sequence, [text | image | reference] , which goes through 28 blocks that share one set of weights.
The two stages differ in who can attend to whom .
In stage 1, each stream only attends to itself, so each kind of token gets refined on its own terms first. In stage 2, everything attends to everything, where the image learns from the text and from the references. For comparison, FLUX.2's double-stream blocks also give text and image separate weights, but let them attend to each other from the start. FLUX.3 keeps the streams fully apart first, then merges them.
At the end, the text and reference tokens are simply dropped. Only the image tokens go through the output layers, which predict how to move them one step toward a clean image.
Inside one block
Every block, in either stage, has the same shape. Attention and the MLP run in parallel on the same normalized input, and their sum is added back to the residual stream.
Each block starts with a LayerNorm that has no learned scale or shift of its own. The scale, shift, and gate come from a timestep embedding instead (this is called modulation ). Inside the attention, the queries and keys are RMS-normalized and get rotary position embeddings (RoPE), which we look at below.
In a joint block, all tokens share the same weights, but text, image, and reference tokens each get their own scale, shift, and gate.
def block ( x, shift, scale, gate ):
h = layer_norm(x)
h = ( 1 + scale) * h + shift
q, k, v = to_q(h), to_k(h), to_v(h)
q, k = rope(rms_norm(q)), rope(rms_norm(k))
out = attention(q, k, v) + mlp(h)
return x + gate * out
Every token gets its own timestep
In FLUX.1 and FLUX.2, one timestep embedding modulates every token. In FLUX.3, the modulation depends on the kind of token.
The noisy image tokens are modulated by the current timestep t . The text and reference tokens are always modulated by timestep 0 , which means "clean, nothing to denoise here". So even a reference that looks almost the same as the output is marked as given context, not as something to gene
| 刊期 | 得分 | 排名 | 结果 |
|---|---|---|---|
| 2026-10-19 | 8.49 | 17 | 入选 |
| 2026-10-18 | 8.77 | 23 | 未入选 |
| 2026-10-17 | 9.22 | 35 | 未入选 |
| 2026-10-16 | 9.95 | 31 | 未入选 |