flux.1-dev-lora.py 1.05 KB
Newer Older
1
2
3
import torch
from diffusers import FluxPipeline

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

7
8
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-dev")
9
10
11
12
13
14
pipeline = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16
).to("cuda")

### LoRA Related Code ###
transformer.update_lora_params(
Muyang Li's avatar
Muyang Li committed
15
16
    "aleksa-codes/flux-ghibsky-illustration/lora.safetensors"
)  # Path to your LoRA safetensors, can also be a remote HuggingFace path
17
18
19
20
transformer.set_lora_strength(1)  # Your LoRA strength here
### End of LoRA Related Code ###

image = pipeline(
21
    "GHIBSKY style, cozy mountain cabin covered in snow, with smoke curling from the chimney and a warm, inviting light spilling through the windows",  # noqa: E501
22
23
24
    num_inference_steps=25,
    guidance_scale=3.5,
).images[0]
25
image.save(f"flux.1-dev-ghibsky-{precision}.png")