-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantize.py
37 lines (33 loc) · 1.11 KB
/
quantize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
from diffusers import AutoPipelineForText2Image, FluxTransformer2DModel, BitsAndBytesConfig
import torch
ckpt_id = "black-forest-labs/FLUX.1-dev"
bnb_4bit_compute_dtype = torch.float16
nf4_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=bnb_4bit_compute_dtype,
)
transformer = FluxTransformer2DModel.from_pretrained(
"fused_transformer",
quantization_config=nf4_config,
torch_dtype=bnb_4bit_compute_dtype,
)
pipeline = AutoPipelineForText2Image.from_pretrained(
ckpt_id, transformer=transformer, torch_dtype=bnb_4bit_compute_dtype
)
pipeline.enable_model_cpu_offload()
image = pipeline(
"a professional photograph of JRussell with a clean-shaven head, wearing a suit and tie",
num_inference_steps=28,
guidance_scale=3.5,
height=768
).images[0]
image.save("JRussell_headshot.png")
image = pipeline(
"A christmas card with adult ARussell, child CRussell, and adult JRussell lit by the warm glow of the fireplace",
num_inference_steps=28,
guidance_scale=3.5,
height=768
).images[0]
image.save("family_christmas.png")