Upload klein.py
Browse files
klein.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import Flux2KleinPipeline
|
| 3 |
+
from transformers import BitsAndBytesConfig
|
| 4 |
+
|
| 5 |
+
bnb_config = BitsAndBytesConfig(
|
| 6 |
+
load_in_4bit=True,
|
| 7 |
+
bnb_4bit_quant_type="nf4", # BEST quality/speed
|
| 8 |
+
bnb_4bit_compute_dtype=torch.bfloat16, # fast on Ampere+
|
| 9 |
+
bnb_4bit_use_double_quant=True, # lower VRAM
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
device = "cuda"
|
| 13 |
+
dtype = torch.bfloat16
|
| 14 |
+
|
| 15 |
+
pipe = Flux2KleinPipeline.from_pretrained("./FLUX.2-9B-bnb-4bit", torch_dtype=dtype)
|
| 16 |
+
|
| 17 |
+
"""
|
| 18 |
+
pipe = Flux2KleinPipeline.from_pretrained(
|
| 19 |
+
"black-forest-labs/FLUX.2-klein-4B",
|
| 20 |
+
torch_dtype=torch.bfloat16,
|
| 21 |
+
device_map="auto", # REQUIRED
|
| 22 |
+
quantization_config=bnb_config, # APPLY 4-bit
|
| 23 |
+
)
|
| 24 |
+
"""
|
| 25 |
+
pipe.to("cuda")
|
| 26 |
+
#pipe.enable_model_cpu_offload() # save some VRAM by offloading the model to CPU
|
| 27 |
+
|
| 28 |
+
from PIL import Image
|
| 29 |
+
|
| 30 |
+
init_image = Image.open("suji.jpg").convert("RGB")
|
| 31 |
+
#prompt = "an very beautiful sexy korean kpop young woman with white bikini is smiling on the waikiki beach. hiqh quality realistic photo."# pixar 3d style"
|
| 32 |
+
prompt = "beautiful young korea sexy woman in the beach holding plate with Circulus "
|
| 33 |
+
image = pipe(
|
| 34 |
+
prompt=prompt,
|
| 35 |
+
image=init_image,
|
| 36 |
+
height=1024,
|
| 37 |
+
width=1024,
|
| 38 |
+
guidance_scale=1.0,
|
| 39 |
+
num_inference_steps=4,
|
| 40 |
+
generator=torch.Generator(device=device).manual_seed(0)
|
| 41 |
+
).images[0]
|
| 42 |
+
image.save("./output/flux_suji3.png")
|