forked from Eco-Sphere/cache-dit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_mochi.py
More file actions
62 lines (50 loc) · 1.36 KB
/
run_mochi.py
File metadata and controls
62 lines (50 loc) · 1.36 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
sys.path.append("..")
import time
import torch
from diffusers import MochiPipeline
from diffusers.utils import export_to_video
from diffusers.quantizers import PipelineQuantizationConfig
from utils import get_args, strify, cachify
import cache_dit
args = get_args()
print(args)
pipe = MochiPipeline.from_pretrained(
os.environ.get(
"MOCHI_DIR",
"genmo/mochi-1-preview",
),
torch_dtype=torch.bfloat16,
quantization_config=PipelineQuantizationConfig(
quant_backend="bitsandbytes_4bit",
quant_kwargs={
"load_in_4bit": True,
"bnb_4bit_quant_type": "nf4",
"bnb_4bit_compute_dtype": torch.bfloat16,
},
components_to_quantize=["transformer", "text_encoder"],
),
)
pipe.to("cuda")
if args.cache:
cachify(args, pipe)
pipe.enable_vae_tiling()
prompt = (
"Close-up of a chameleon's eye, with its scaly skin "
"changing color. Ultra high resolution 4k."
)
start = time.time()
video = pipe(
prompt,
num_frames=49,
num_inference_steps=64,
generator=torch.Generator("cpu").manual_seed(0),
).frames[0]
end = time.time()
stats = cache_dit.summary(pipe)
time_cost = end - start
save_path = f"mochi.{strify(args, stats)}.mp4"
print(f"Time cost: {time_cost:.2f}s")
print(f"Saving video to {save_path}")
export_to_video(video, save_path, fps=10)