FLUX.3 Image Klein เปิดตัวสู่ Diffusers รองรับการควบคุมเลย์เอาต์

· By: TanasakP

Black Forest Labs ประกาศเปิดตัว FLUX.3 Image Klein พร้อมให้ใช้งานใน Diffusers ได้ตั้งแต่วันแรก โดยโมเดลเดียวสามารถรองรับได้ทั้ง text-to-image และ multi-reference image-to-image

จุดเด่นที่เพิ่มเข้ามาคือ layout control ซึ่งช่วยให้คุณระบุตำแหน่งวัตถุได้แม่นยำด้วยการเขียน bounding box ลงใน prompt เพื่อกำหนดจุดวางหรือย้ายส่วนประกอบจากภาพอ้างอิง

checkpoint แบบเปิดทั้งสองเวอร์ชันสามารถเข้าถึงได้ผ่าน FLUX.3 Image Klein collection:

Checkpointคืออะไรค่าเริ่มต้น
black-forest-labs/flux-3-image-kleinTime step distilled เพื่อการประมวลผลที่รวดเร็ว16 steps, no CFG
black-forest-labs/flux-3-image-klein-baseBase model50 steps, CFG

a red fox in a snowy forest (text-to-image), the same fox re-rendered from that image (image-to-image), a black stippled running silhouette on a chartreuse background, drawn inside its labeled bounding box, and a knitted knight moved from a "from" box to a "to" box next to a knitted dragon (layout editing)

ผู้ใช้งานสามารถทดลองสร้างรูปภาพได้ทันทีที่ Hugging Face space

TL;DR

  • รวมความสามารถ text-to-image, multi-reference image-to-image และการคุมเลย์เอาต์ด้วย bounding-box ไว้ในโมเดลเดียว
  • checkpoint แบบ distilled สร้างภาพขนาด 1024 × 1024 ได้ในเวลาเพียง 2 วินาที บน H100
  • รองรับ weight แบบ NVFP4 และ FP8 ผ่าน from_single_file ช่วยให้รันบน GPU ขนาดเล็กได้
  • มี script สำหรับเทรน LoRA ทั้งการสร้างภาพใหม่และการแก้ไขภาพ
  • สถาปัตยกรรมแบบ Modular Diffusers ช่วยให้ปรับแต่งเพิ่มหรือถอด block ได้ตามต้องการ

Contents

Getting started

เริ่มต้นด้วยการติดตั้ง diffusers และ transformers เวอร์ชันล่าสุด เพื่อรองรับ Qwen3-VL text encoder:

pip install -U diffusers transformers

ตัวอย่างการโหลด distilled checkpoint เพื่อสร้างภาพ:

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 ทำอะไรได้บ้าง

Text-to-image

FLUX.3 ให้ผลลัพธ์ดีที่สุดเมื่อใช้คำบรรยายฉากที่ละเอียด ทั้งตัวแบบ แสง และองค์ประกอบ โดยสามารถศึกษาเทคนิคเพิ่มเติมได้จาก คู่มือการเขียน prompt อย่างเป็นทางการ ปกติ distilled checkpoint จะสร้างภาพขนาด 1024 × 1024 ใน 16 steps ซึ่งคุณสามารถปรับค่า 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")
A red fox standing alert in a snow-covered forest clearing, lit by low golden sunlight from the left
Text to image

Image-to-image

คุณสามารถส่งภาพอ้างอิงผ่านอาร์กิวเมนต์ image และเขียน prompt บรรยายผลลัพธ์ที่ต้องการเพื่อสั่งแก้ไขหรือเปลี่ยนสไตล์

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, # จากตัวอย่าง text to image ก่อนหน้า
    generator=torch.Generator().manual_seed(0),
    output="images",
)[0]
night.save("night.png")
The fox from the previous image, relit in cold blue light
Image to image

หากมีภาพอ้างอิงหลายภาพ ให้ระบุใน prompt ด้วยโทเค็น <ref_image_0>, <ref_image_1> ตามลำดับภาพที่ส่งเข้าไปใน image ดังนี้:

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 <ref_image_0> sitting on the wooden bench from <ref_image_1> in a snowy setting.",
    image=[red_fox, bench],
    output="images",
)
[0]
 
combined.save("combined.png")
A red fox sitting on dry grassA slatted wooden bench against a plain grey wallThe same fox sitting on the same bench, with snow on the ground
<ref_image_0>: สุนัขจิ้งจอกสีแดง<ref_image_1>: ม้านั่งไม้สุนัขจิ้งจอกบนม้านั่ง

Layout control

การควบคุมเลย์เอาต์ทำได้โดยใส่ข้อมูล JSON ต่อท้ายคำบรรยาย โดยระบุ id, bbox (ในรูปแบบ [y_min, x_min, y_max, x_max] มาตราส่วน 0-1000) และ desc เพื่อระบุตำแหน่งวัตถุในภาพ

การวางภูมิภาคในภาพใหม่

layout_prompt = (
    "Minimalist graphic illustration featuring a black silhouette of a person <silhouette_1> centered against a "
    "solid, vibrant chartreuse background <background_1>. The figure is captured in a dynamic, mid-stride running "
    "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]
Diagram: the caption and the two region descriptions on the left, the two boxes on a 0–1000 grid in the middle, and the generated image on the right, where a black stippled runner fills the silhouette box on a chartreuse background
desc ของแต่ละภูมิภาคจะถูกวาดไว้ใน bbox ที่กำหนด

การเคลื่อนย้ายภูมิภาคภายในภาพอ้างอิง

สำหรับการแก้ไข คุณสามารถระบุจุดต้นทาง (src_bbox) และจุดหมาย (tgt_bbox) เพื่อย้ายวัตถุได้โดยที่ส่วนอื่นของภาพยังคงเดิม

from diffusers.utils import load_image
 
knight_image = load_image("knight_orig.png")
edit_prompt = (
    "In <ref_image_0>, move the miniature grey amigurumi knight figure <knight_1> upwards and to the left along the "
    "yarn cliff <cliff_1>. Keep the rest of the image completely unchanged, preserving the blurred yarn backdrop "
    "<backdrop_1>, the large knitted dragon <dragon_1>, and the fiery orange thread <fire_1>. "
    '[{"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]
Left: the reference with the knight's source box. Right: the output with an arrow from the source box to the target box; the pinned regions are outlined in white
ย้ายอัศวินจาก src_bbox ไปยัง tgt_bbox โดยตรึงองค์ประกอบอื่นไว้

Base model และตัวแปรแบบ quantized

Base model

Base checkpoint จะรันที่ 50 steps พร้อม classifier-free guidance เหมาะสำหรับงานที่ต้องการคุณภาพสูงสุดหรือใช้เป็นฐานในการ fine-tune

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]

Checkpoint แบบไฟล์เดียว (Single-file format)

รองรับการโหลด transformer ในรูปแบบไฟล์เดียว ทั้งแบบ bf16 และ quantized (fp8r, nvfp4) ผ่าน from_single_file เพื่อประหยัดการดาวน์โหลดซ้ำ

from diffusers import BFLQuantizationConfig, Flux3Transformer2DModel, ModularPipeline
 
model_id = "black-forest-labs/flux-3-image-klein-base"
variant = "fp8r"  # หรือ "nvfp4"
 
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")
รุ่นตัวแปรKernel ความเร็วสูงบนGPU อื่นๆ
fp8rCompute capability 8.9+ (Ada, Hopper, Blackwell)Weight จะถูก dequantize ทีละขั้นตอน: ใช้แรมน้อยลง แต่ไม่เร็วขึ้น
nvfp4Blackwell ที่ใช้ flashinfer เวอร์ชันเดียวกันเหมือนข้างต้น

LoRA finetuning

FLUX.3 รองรับการทำ LoRA แบบกำหนดเองผ่าน script DreamBooth ใน diffusers ทั้งสำหรับ text-to-image และ image-to-image

ตัวอย่างการเทรนสไตล์ไพ่ยิปซี:

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

FLUX.3 tarot-style LoRA across ranks and optimizers: the base model with no LoRA, then rank 16, rank 8 and rank 32 (AdamW, lr 1e-4) and a Prodigy run, on two held-out prompts

ศึกษารายละเอียดการปรับแต่งเพิ่มเติมได้ที่ DreamBooth FLUX.3 README

ค่าใช้จ่ายในการรัน

หน่วยความจำ (Memory)

ชื่อปริมาณสูงสุดที่จอง (หลังโหลด) GiBsปริมาณสูงสุดที่จอง (หลัง inference) GiBs
nvfp4 (RTX6000)13.415.3
fp8r (H100)14.3516.27
bf16 (H100)18.8020.72

หากแรมมีจำกัด แนะนำให้ใช้ quantized transformer หรือเปิดใช้งาน automatic CPU offloading เพื่อช่วยจัดการการใช้ GPU

ความเร็ว

ผลทดสอบเฉลี่ยบน NVIDIA H100 80GB สำหรับ 16 steps:

Workflowขนาดผลลัพธ์เวลาหน่วยความจำสูงสุด
Text-to-image1024 × 10241.93 s23.8 GiB
Image-to-image (1 ref)1024 × 10243.87 s23.8 GiB
Layout editing (1 ref)1360 × 7684.10 s23.8 GiB

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)

FLUX.3 ทำงานโดยรับ token 3 ประเภท คือ ข้อความ, ภาพที่มี noise และภาพอ้างอิง

กลไกการประมวลผล

  1. จากพิกเซลเป็น token: ใช้ VAE บีบอัดภาพลง 8 เท่า โดยหนึ่ง token จะครอบคลุมพื้นที่พิกเซล 16 × 16
  2. Text Encoding: ใช้ Qwen3-VL อ่าน hidden state จาก 8 เลเยอร์เพื่อให้ transformer เข้าถึงฟีเจอร์ภาษาในระดับความลึกที่ต่างกัน
  3. ขั้นตอนการประมวลผล: แบ่งเป็น 2 ขั้นคือ per-mode blocks (แยกประมวลผลตามประเภทข้อมูล) และ joint blocks (รวมทุกอย่างเพื่อทำ attention ร่วมกัน)
  4. Timestep: token ภาพที่มี noise จะถูกคุมด้วย timestep t ส่วนข้อความและภาพอ้างอิงจะอยู่ที่ timestep 0 เสมอ เพื่อเป็นบริบทที่สะอาด
  5. ตำแหน่ง 4 มิติ: ใช้ RoPE หมุนโทเค็นตามแกน (t, h, w, l) ทำให้โมเดลเข้าใจตำแหน่งที่แม่นยำของวัตถุ

step01 step05 step10 step15 step25 step50 แสดงภาพค่อยๆ เป็นรูปเป็นร่างในแต่ละขั้นตอนการทำ denoising

Modular Diffusers

การใช้รูปแบบ Modular ช่วยให้ผู้ใช้ปรับแต่งกระบวนการทำงานได้ยืดหยุ่น เช่น การ Encode ข้อความเพียงครั้งเดียวเพื่อสร้างภาพหลายใบ (Encode once, generate many) หรือการแทรก block พิเศษเข้าไปในลูปการสร้างภาพเพื่อบันทึกสถานะระหว่างขั้นตอน

ลองเลย

Source: Hugging Face Blog
ดูแลงานแปลและเรียบเรียงโดย TanasakP

ความคิดเห็น (0)

เข้าสู่ระบบเพื่อร่วมแสดงความเห็น

สมัครสมาชิก

มาเป็นคนแรกที่แสดงความเห็นกันเลยโบร