FLUX models are compatible with the diffusers library.
- Install diffusers:
pip install git+https://github.com/huggingface/diffusers.git - Use
FluxPipeline to load and run the model.
Tip: Use pipe.enable_model_cpu_offload() to save VRAM if you have limited GPU power. For FLUX.1 [dev], use a larger number of num_inference_steps than for schnell.
import torch
from diffusers import FluxPipeline
model_id = "black-forest-labs/FLUX.1-schnell"
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
prompt = "A cat holding a sign that says hello world"
seed = 42
image = pipe(
prompt,
output_type="pil",
num_inference_steps=4,
generator=torch.Generator("cpu").manual_seed(seed)
).images[0]
image.save("flux-schnell.png")