FLUX.2 Klein
FLUX.2 Klein——在 Clore.ai 的 GPU 上实现亚秒级图像生成
最后更新于
这有帮助吗?
这有帮助吗?
import torch
from diffusers import FluxPipeline
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.2-klein",
torch_dtype=torch.bfloat16
)
pipe.to("cuda")
# 在 < 0.5 秒内生成图像!
image = pipe(
prompt="一个赛博朋克风格的 GPU 挖矿机架在霓虹灯服务器室中,照片级真实感",
height=1024,
width=1024,
num_inference_steps=4, # Klein 只需 4 步!
guidance_scale=3.5,
).images[0]
image.save("output.png")pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.2-klein",
torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload() # 适配 16GB
pipe.vae.enable_tiling() # 省约 ~2GB
image = pipe("日落时的山地风景", num_inference_steps=4).images[0]# 为 ComfyUI 下载模型
cd ComfyUI/models/diffusion_models/
wget https://huggingface.co/black-forest-labs/FLUX.2-klein/resolve/main/flux2-klein.safetensorsimport torch
from diffusers import FluxPipeline
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.2-klein", torch_dtype=torch.bfloat16
).to("cuda")
prompts = [
"一辆红色跑车在山路上,电影感",
"一个舒适的咖啡馆内部,温暖的灯光",
"一名宇航员悬浮在地球上空,超真实",
"秋天的中世纪城堡,奇幻艺术",
# … 再添加数百个
]
for i, prompt in enumerate(prompts):
image = pipe(prompt, num_inference_steps=4, guidance_scale=3.5).images[0]
image.save(f"batch_{i:04d}.png")
print(f"已生成 {i+1}/{len(prompts)}")
# 在 RTX 4090 上:不到 1 分钟生成约 100 张图像!pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.2-klein", torch_dtype=torch.bfloat16
).to("cuda")
# 加载在 FLUX 架构上训练的 LoRA
pipe.load_lora_weights("your-lora/flux2-style-lora", weight_name="lora.safetensors")
pipe.fuse_lora(lora_scale=0.8)
image = pipe("以训练风格的人像", num_inference_steps=4).images[0]