teawhite's picture
Add files using upload-large-folder tool
51ac7cc verified
Raw History Blame Contribute Delete
1.64 kB
import sys, os, json, time, numpy as np, torch, cv2
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))); sys.path.insert(0, '/opt/dlami/nvme/zhiyangdeng/maliang/ref/gc25d-live-demo/code')
from tario import RunTars
from gc25d.geometry import resample_rgb
from diffsynth.pipelines.wan_video import ModelConfig, WanVideoPipeline
run, ci, strict, reps = sys.argv[1], int(sys.argv[2]), sys.argv[3] == 'strict', int(sys.argv[4]); dev = 'cuda:0'
R = RunTars(run); s = json.load(open(os.path.join(run, 'index', 'clips_81.json')))[ci]['start']
frames = np.stack([resample_rgb(cv2.cvtColor(cv2.imdecode(np.frombuffer(R.get(s + i, 'jpg'), np.uint8), cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)) for i in range(81)])
pipe = WanVideoPipeline.from_pretrained(torch_dtype=torch.bfloat16, device=dev, model_configs=[ModelConfig(path='/opt/dlami/nvme/zhiyangdeng/maliang/models/Wan2.2-TI2V-5B/Wan2.2_VAE.pth')], tokenizer_config=None, redirect_common_files=False)
pipe.vae.model.float()
def enc():
x = torch.from_numpy(frames).permute(3, 0, 1, 2).float().div_(127.5).sub_(1.0)
with torch.no_grad(): return pipe.vae.encode([x], device=dev, tiled=False).float().cpu()
torch.backends.cudnn.allow_tf32 = True; zt = enc()
if strict:
torch.backends.cudnn.allow_tf32 = False; torch.backends.cuda.matmul.allow_tf32 = False
z = enc(); torch.cuda.synchronize(); ts = []
for _ in range(reps):
t = time.time(); z = enc(); torch.cuda.synchronize(); ts.append(time.time() - t)
print(f'strict={strict} pid={os.getpid()} s/clip {np.round(ts, 3).tolist()} median {np.median(ts):.3f}; vs tf32 rel L2 {((z - zt).norm() / zt.norm()).item():.5f}', flush=True)