flux.1-dev-offload.py 811 Bytes
Newer Older
muyangli's avatar
muyangli committed
1
2
3
import torch
from diffusers import FluxPipeline

4
5
from nunchaku import NunchakuFluxTransformer2dModel
from nunchaku.utils import get_precision
muyangli's avatar
muyangli committed
6

7
precision = get_precision()  # auto-detect your precision is 'int4' or 'fp4' based on your GPU
muyangli's avatar
muyangli committed
8
transformer = NunchakuFluxTransformer2dModel.from_pretrained(
9
    f"mit-han-lab/svdq-{precision}-flux.1-dev", offload=True
muyangli's avatar
muyangli committed
10
11
12
)  # set offload to False if you want to disable offloading
pipeline = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16
Muyang Li's avatar
Muyang Li committed
13
14
)  # no need to set the device here
pipeline.enable_sequential_cpu_offload()  # diffusers' offloading
muyangli's avatar
muyangli committed
15
image = pipeline("A cat holding a sign that says hello world", num_inference_steps=50, guidance_scale=3.5).images[0]
16
image.save(f"flux.1-dev-{precision}.png")