forked from Eco-Sphere/cache-dit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_flux_kontext.py
More file actions
47 lines (35 loc) · 936 Bytes
/
run_flux_kontext.py
File metadata and controls
47 lines (35 loc) · 936 Bytes
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
38
39
40
41
42
43
44
45
46
47
import os
import sys
sys.path.append("..")
import time
import torch
from diffusers import FluxKontextPipeline
from diffusers.utils import load_image
from utils import get_args, strify, cachify
import cache_dit
args = get_args()
print(args)
pipe = FluxKontextPipeline.from_pretrained(
os.environ.get(
"FLUX_KONTEXT_DIR",
"black-forest-labs/FLUX.1-Kontext-dev",
),
torch_dtype=torch.bfloat16,
).to("cuda")
if args.cache:
cachify(args, pipe)
start = time.time()
image = pipe(
image=load_image("../data/cat.png"),
prompt="Add a hat to the cat",
guidance_scale=2.5,
num_inference_steps=28,
generator=torch.Generator("cpu").manual_seed(0),
).images[0]
end = time.time()
stats = cache_dit.summary(pipe)
time_cost = end - start
save_path = f"flux-kontext.{strify(args, stats)}.png"
print(f"Time cost: {time_cost:.2f}s")
print(f"Saving image to {save_path}")
image.save(save_path)