|
|
import os |
|
|
import json |
|
|
import torch |
|
|
import numpy as np |
|
|
import PIL |
|
|
from PIL import Image |
|
|
from IPython.display import HTML |
|
|
from pyramid_dit import PyramidDiTForVideoGeneration |
|
|
from IPython.display import Image as ipython_image |
|
|
from diffusers.utils import load_image, export_to_video, export_to_gif |
|
|
|
|
|
|
|
|
model_path = "/mnt/bn/yufan-dev-my/ysh/Ckpts/rain1011/pyramid-flow-miniflux/" |
|
|
model_name = "pyramid_flux" |
|
|
variant='diffusion_transformer_384p' |
|
|
model_dtype = 'bf16' |
|
|
|
|
|
|
|
|
prompt = "A movie trailer featuring the adventures of the 30 year old space man wearing a red wool knitted motorcycle helmet, blue sky, salt desert, cinematic style, shot on 35mm film, vivid colors" |
|
|
|
|
|
width = 640 |
|
|
height = 384 |
|
|
|
|
|
|
|
|
|
|
|
temp = 16 |
|
|
|
|
|
|
|
|
device_id = 0 |
|
|
torch.cuda.set_device(device_id) |
|
|
|
|
|
model = PyramidDiTForVideoGeneration( |
|
|
model_path, |
|
|
model_dtype, |
|
|
model_name=model_name, |
|
|
model_variant=variant, |
|
|
) |
|
|
|
|
|
model.vae.to("cuda") |
|
|
model.dit.to("cuda") |
|
|
model.text_encoder.to("cuda") |
|
|
|
|
|
model.vae.enable_tiling() |
|
|
|
|
|
if model_dtype == "bf16": |
|
|
torch_dtype = torch.bfloat16 |
|
|
elif model_dtype == "fp16": |
|
|
torch_dtype = torch.float16 |
|
|
else: |
|
|
torch_dtype = torch.float32 |
|
|
|
|
|
with torch.no_grad(), torch.amp.autocast('cuda', enabled=True if model_dtype != 'fp32' else False, dtype=torch_dtype): |
|
|
frames = model.generate( |
|
|
prompt=prompt, |
|
|
num_inference_steps=[20, 20, 20], |
|
|
video_num_inference_steps=[10, 10, 10], |
|
|
height=height, |
|
|
width=width, |
|
|
temp=temp, |
|
|
guidance_scale=7.0, |
|
|
video_guidance_scale=5.0, |
|
|
output_type="pil", |
|
|
save_memory=True, |
|
|
) |
|
|
|
|
|
export_to_video(frames, "./text_to_video_sample.mp4", fps=24) |