Views
No views yet
![]() | ![]() |
![]() | ![]() |


FLUX.2 [dev] is a 32 billion parameter rectified flow transformer capable of generating, editing and combining images based on text instructions.
For more information, please read our blog post.FLUX.2 [dev] more efficient.FLUX.2 [dev], as well as sampling code, in a dedicated github repository.
Developers and creatives looking to build on top of FLUX.2 [dev] are encouraged to use this as a starting point.1import torch
2from diffusers import Flux2Pipeline
3from diffusers.utils import load_image
4from huggingface_hub import get_token
5import requests
6import io
7
8repo_id = "diffusers/FLUX.2-dev-bnb-4bit" #quantized text-encoder and DiT. VAE still in bf16
9device = "cuda:0"
10torch_dtype = torch.bfloat16
11
12def remote_text_encoder(prompts):
13 response = requests.post(
14 "https://remote-text-encoder-flux-2.huggingface.co/predict",
15 json={"prompt": prompts},
16 headers={
17 "Authorization": f"Bearer {get_token()}",
18 "Content-Type": "application/json"
19 }
20 )
21 prompt_embeds = torch.load(io.BytesIO(response.content))
22
23 return prompt_embeds.to(device)
24
25pipe = Flux2Pipeline.from_pretrained(
26 repo_id, text_encoder=None, torch_dtype=torch_dtype
27).to(device)
28
29prompt = "Realistic macro photograph of a hermit crab using a soda can as its shell, partially emerging from the can, captured with sharp detail and natural colors, on a sunlit beach with soft shadows and a shallow depth of field, with blurred ocean waves in the background. The can has the text `BFL Diffusers` on it and it has a color gradient that start with #FF5733 at the top and transitions to #33FF57 at the bottom."
30
31#cat_image = load_image("https://huggingface.co/spaces/zerogpu-aoti/FLUX.1-Kontext-Dev-fp8-dynamic/resolve/main/cat.png")
32image = pipe(
33 prompt_embeds=remote_text_encoder(prompt),
34 #image=[cat_image] #optional multi-image input
35 generator=torch.Generator(device=device).manual_seed(42),
36 num_inference_steps=50, #28 steps can be a good trade-off
37 guidance_scale=4,
38).images[0]
39
40image.save("flux2_output.png")