flux.1-fill-dev.py 1015 Bytes
Newer Older
muyangli's avatar
muyangli committed
1
2
3
4
import torch
from diffusers import FluxFillPipeline
from diffusers.utils import load_image

muyangli's avatar
muyangli committed
5
from nunchaku import NunchakuFluxTransformer2dModel
6
from nunchaku.utils import get_precision
muyangli's avatar
muyangli committed
7
8
9
10

image = load_image("https://huggingface.co/mit-han-lab/svdq-int4-flux.1-fill-dev/resolve/main/example.png")
mask = load_image("https://huggingface.co/mit-han-lab/svdq-int4-flux.1-fill-dev/resolve/main/mask.png")

11
12
precision = get_precision()  # auto-detect your precision is 'int4' or 'fp4' based on your GPU
transformer = NunchakuFluxTransformer2dModel.from_pretrained(f"mit-han-lab/svdq-{precision}-flux.1-fill-dev")
muyangli's avatar
muyangli committed
13
14
15
16
pipe = FluxFillPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-Fill-dev", transformer=transformer, torch_dtype=torch.bfloat16
).to("cuda")
image = pipe(
17
    prompt="A wooden basket of a cat.",
muyangli's avatar
muyangli committed
18
19
20
21
22
23
24
25
    image=image,
    mask_image=mask,
    height=1024,
    width=1024,
    guidance_scale=30,
    num_inference_steps=50,
    max_sequence_length=512,
).images[0]
26
image.save(f"flux.1-fill-dev-{precision}.png")