Views
No views yet
![FLUX.1 [dev] Grid](./dev_grid.png)
BitsAndBytes in NF4 format. This enables GPU inference with reduced VRAM requirements, making it
accessible even on the Google Colab free tier or on GPUs with 8GB VRAM.pip install bitsandbytes==0.48.1 diffusers==0.35.1 peft==0.17.1 protobuf==5.29.5 sentencepiece==0.2.1 transformers==4.56.11import torch
2from diffusers import FluxPipeline
3
4ckpt_4bit_id = "aniketppanchal/flux.1-dev-nf4-pkg"
5prompt = "A cat holding a sign that says hello world"
6height = 1024
7width = 1024
8
9pipeline = FluxPipeline.from_pretrained(
10 ckpt_4bit_id,
11 torch_dtype=torch.float16,
12 device_map="cuda",
13)
14
15image = pipeline(
16 prompt=prompt,
17 height=height,
18 width=width,
19 num_inference_steps=28,
20 guidance_scale=3.5,
21 max_sequence_length=512,
22).images[0]
23image.save("output.png")1import gc
2
3import torch
4from diffusers import FluxPipeline, FluxTransformer2DModel
5from transformers import T5EncoderModel
6
7ckpt_4bit_id = "aniketppanchal/flux.1-dev-nf4-pkg"
8prompt = "A cat holding a sign that says hello world"
9height = 1024
10width = 1024
11
12# ----------Encode Prompt Embeddings----------
13
14text_encoder_2 = T5EncoderModel.from_pretrained(
15 ckpt_4bit_id,
16 subfolder="text_encoder_2",
17 torch_dtype=torch.float16,
18 device_map="cuda",
19)
20pipeline = FluxPipeline.from_pretrained(
21 ckpt_4bit_id,
22 text_encoder_2=text_encoder_2,
23 transformer=None,
24 vae=None,
25 torch_dtype=torch.float16,
26 device_map="cuda",
27)
28
29with torch.no_grad():
30 prompt_embeds, pooled_prompt_embeds, _ = pipeline.encode_prompt(
31 prompt=prompt,
32 max_sequence_length=512,
33 )
34
35del text_encoder_2, pipeline
36gc.collect()
37torch.cuda.empty_cache()
38
39# ----------Generate Diffusion Latents----------
40
41transformer = FluxTransformer2DModel.from_pretrained(
42 ckpt_4bit_id,
43 subfolder="transformer",
44 torch_dtype=torch.float16,
45 device_map="cuda",
46)
47pipeline = FluxPipeline.from_pretrained(
48 ckpt_4bit_id,
49 text_encoder=None,
50 text_encoder_2=None,
51 tokenizer=None,
52 tokenizer_2=None,
53 transformer=transformer,
54 vae=None,
55 torch_dtype=torch.float16,
56 device_map="cuda",
57)
58
59packed_latents = pipeline(
60 height=height,
61 width=width,
62 num_inference_steps=28,
63 guidance_scale=3.5,
64 prompt_embeds=prompt_embeds,
65 pooled_prompt_embeds=pooled_prompt_embeds,
66 output_type="latent",
67 max_sequence_length=512,
68).images
69
70del prompt_embeds, pooled_prompt_embeds, transformer, pipeline
71gc.collect()
72torch.cuda.empty_cache()
73
74# ----------Decode Latents to Image----------
75
76pipeline = FluxPipeline.from_pretrained(
77 ckpt_4bit_id,
78 text_encoder=None,
79 text_encoder_2=None,
80 tokenizer=None,
81 tokenizer_2=None,
82 transformer=None,
83 torch_dtype=torch.float16,
84 device_map="cuda",
85)
86
87unpacked_latents = (
88 pipeline._unpack_latents(
89 packed_latents,
90 height=height,
91 width=width,
92 vae_scale_factor=pipeline.vae_scale_factor,
93 )
94 / pipeline.vae.config.scaling_factor
95 + pipeline.vae.config.shift_factor
96)
97
98with torch.no_grad():
99 image_tensor = pipeline.vae.decode(unpacked_latents, return_dict=False)[0]
100
101image = pipeline.image_processor.postprocess(image_tensor)[0]
102image.save("output.png")
103
104del packed_latents, unpacked_latents, image_tensor, pipeline
105gc.collect()
106torch.cuda.empty_cache()LICENSE.md file corresponds
to the frozen state of the original repository as of 3rd November 2025. For the latest version, see
the FLUX.1 [dev] License.