简介
EasyAnimate是一个基于transformer结构的pipeline,可用于生成AI图片与视频、训练Diffusion Transformer的基线模型与Lora模型,我们支持从已经训练好的EasyAnimate模型直接进行预测,生成不同分辨率,6秒左右、fps8的视频(EasyAnimateV5.1,1 ~ 49帧),也支持用户训练自己的基线模型与Lora模型,进行一定的风格变换。
模型地址
EasyAnimateV5.1 for diffusers:
该权重文件主要用于 diffusers 仓库。
需要注意的是,EasyAnimate 仓库与 diffusers 仓库在权重格式和使用方式上存在些许差异,请务必仔细甄别。
7B:
名称 | 种类 | 存储空间 | Hugging Face | 描述 |
---|---|---|---|---|
EasyAnimateV5.1-7b-zh-InP | EasyAnimateV5.1 | 30 GB | 🤗Link | 官方的图生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-7b-zh-Control | EasyAnimateV5.1 | 30 GB | 🤗Link | 官方的视频控制权重,支持不同的控制条件,如Canny、Depth、Pose、MLSD等,同时支持使用轨迹控制。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-7b-zh-Control-Camera | EasyAnimateV5.1 | 30 GB | 🤗Link | 官方的视频相机控制权重,支持通过输入相机运动轨迹控制生成方向。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-7b-zh | EasyAnimateV5.1 | 30 GB | 🤗Link | 官方的文生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
12B:
名称 | 种类 | 存储空间 | Hugging Face | 描述 |
---|---|---|---|---|
EasyAnimateV5.1-12b-zh-InP | EasyAnimateV5.1 | 39 GB | 🤗Link | 官方的图生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-12b-zh-Control | EasyAnimateV5.1 | 39 GB | 🤗Link | 官方的视频控制权重,支持不同的控制条件,如Canny、Depth、Pose、MLSD等,同时支持使用轨迹控制。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-12b-zh-Control-Camera | EasyAnimateV5.1 | 39 GB | 🤗Link | 官方的视频相机控制权重,支持通过输入相机运动轨迹控制生成方向。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-12b-zh | EasyAnimateV5.1 | 39 GB | 🤗Link | 官方的文生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1:
该权重文件主要用于 EasyAnimate 仓库。
需要注意的是,EasyAnimate 仓库与 diffusers 仓库在权重格式和使用方式上存在些许差异,请务必仔细甄别。
7B:
名称 | 种类 | 存储空间 | Hugging Face | Model Scope | 描述 |
---|---|---|---|---|---|
EasyAnimateV5.1-7b-zh-InP | EasyAnimateV5.1 | 30 GB | 🤗Link | 😄Link | 官方的图生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-7b-zh-Control | EasyAnimateV5.1 | 30 GB | 🤗Link | 😄Link | 官方的视频控制权重,支持不同的控制条件,如Canny、Depth、Pose、MLSD等,同时支持使用轨迹控制。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-7b-zh-Control-Camera | EasyAnimateV5.1 | 30 GB | 🤗Link | 😄Link | 官方的视频相机控制权重,支持通过输入相机运动轨迹控制生成方向。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-7b-zh | EasyAnimateV5.1 | 30 GB | 🤗Link | 😄Link | 官方的文生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
12B:
名称 | 种类 | 存储空间 | Hugging Face | Model Scope | 描述 |
---|---|---|---|---|---|
EasyAnimateV5.1-12b-zh-InP | EasyAnimateV5.1 | 39 GB | 🤗Link | 😄Link | 官方的图生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-12b-zh-Control | EasyAnimateV5.1 | 39 GB | 🤗Link | 😄Link | 官方的视频控制权重,支持不同的控制条件,如Canny、Depth、Pose、MLSD等,同时支持使用轨迹控制。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-12b-zh-Control-Camera | EasyAnimateV5.1 | 39 GB | 🤗Link | 😄Link | 官方的视频相机控制权重,支持通过输入相机运动轨迹控制生成方向。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
EasyAnimateV5.1-12b-zh | EasyAnimateV5.1 | 39 GB | 🤗Link | 😄Link | 官方的文生视频权重。支持多分辨率(512,768,1024)的视频预测,支持多分辨率(512,768,1024)的视频预测,以49帧、每秒8帧进行训练,支持多语言预测 |
视频作品
图生视频 EasyAnimateV5.1-12b-zh-InP
文生视频 EasyAnimateV5.1-12b-zh
控制生视频 EasyAnimateV5.1-12b-zh-Control
轨迹控制
普通控制生视频(Canny、Pose、Depth等)
相机镜头控制 EasyAnimateV5.1-12b-zh-Control-Camera
Pan Up | Pan Left | Pan Right |
Pan Down | Pan Up + Pan Left | Pan Up + Pan Right |
如何使用
a、Text to video
import torch
import numpy as np
from diffusers import EasyAnimatePipeline
from diffusers.utils import export_to_video
# Models: "alibaba-pai/EasyAnimateV5.1-7b-zh-diffusers" or "alibaba-pai/EasyAnimateV5.1-12b-zh-diffusers"
pipe = EasyAnimatePipeline.from_pretrained(
"alibaba-pai/EasyAnimateV5.1-12b-zh-diffusers",
torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()
prompt = (
"A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. "
"The panda's fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other "
"pandas gather, watching curiously and some clapping in rhythm. Sunlight filters through the tall bamboo, "
"casting a gentle glow on the scene. The panda's face is expressive, showing concentration and joy as it plays. "
"The background includes a small, flowing stream and vibrant green foliage, enhancing the peaceful and magical "
"atmosphere of this unique musical performance."
)
negative_prompt = "bad detailed"
height = 512
width = 512
guidance_scale = 6
num_inference_steps = 50
num_frames = 49
seed = 43
generator = torch.Generator(device="cuda").manual_seed(seed)
video = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
num_frames=num_frames,
height=height,
width=width,
generator=generator,
).frames[0]
export_to_video(video, "output.mp4", fps=8)
b、Image to video
import torch
from diffusers import EasyAnimateInpaintPipeline
from diffusers.pipelines.easyanimate.pipeline_easyanimate_inpaint import \
get_image_to_video_latent
from diffusers.pipelines.easyanimate.pipeline_easyanimate_control import \
get_video_to_video_latent
from diffusers.utils import export_to_video, load_image, load_video
# Models: "alibaba-pai/EasyAnimateV5.1-12b-zh-InP-diffusers" or "alibaba-pai/EasyAnimateV5.1-7b-zh-InP-diffusers"
pipe = EasyAnimateInpaintPipeline.from_pretrained(
"alibaba-pai/EasyAnimateV5.1-12b-zh-InP-diffusers",
torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()
prompt = "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
negative_prompt = "Twisted body, limb deformities, text subtitles, comics, stillness, ugliness, errors, garbled text."
validation_image_start = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg")
validation_image_end = None
sample_size = (448, 576)
num_frames = 49
input_video, input_video_mask = get_image_to_video_latent([validation_image_start], validation_image_end, num_frames, sample_size)
video = pipe(
prompt,
negative_prompt=negative_prompt,
num_frames=num_frames,
height=sample_size[0],
width=sample_size[1],
video=input_video,
mask_video=input_video_mask
)
export_to_video(video.frames[0], "output.mp4", fps=8)
c、Video to video
import torch
from diffusers import EasyAnimateInpaintPipeline
from diffusers.pipelines.easyanimate.pipeline_easyanimate_inpaint import \
get_image_to_video_latent
from diffusers.pipelines.easyanimate.pipeline_easyanimate_control import \
get_video_to_video_latent
from diffusers.utils import export_to_video, load_image, load_video
# Models: "alibaba-pai/EasyAnimateV5.1-12b-zh-InP-diffusers" or "alibaba-pai/EasyAnimateV5.1-7b-zh-InP-diffusers"
pipe = EasyAnimateInpaintPipeline.from_pretrained(
"alibaba-pai/EasyAnimateV5.1-12b-zh-InP-diffusers",
torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()
prompt = "一只穿着小外套的猫咪正安静地坐在花园的秋千上弹吉他。它的小外套精致而合身,增添了几分俏皮与可爱。晚霞的余光洒在它柔软的毛皮上,给它的毛发镀上了一层温暖的金色光辉。和煦的微风轻轻拂过,带来阵阵花香和草木的气息,令人心旷神怡。周围斑驳的光影随着音乐的旋律轻轻摇曳,仿佛整个花园都在为这只小猫咪的演奏伴舞。阳光透过树叶间的缝隙,投下一片片光影交错的图案,与悠扬的吉他声交织在一起,营造出一种梦幻而宁静的氛围。猫咪专注而投入地弹奏着,每一个音符都似乎充满了魔力,让这个傍晚变得更加美好。"
negative_prompt = "Twisted body, limb deformities, text subtitles, comics, stillness, ugliness, errors, garbled text."
sample_size = (384, 672)
num_frames = 49
input_video = load_video("https://huggingface.co/alibaba-pai/EasyAnimateV5.1-12b-zh-InP/resolve/main/asset/1.mp4")
input_video, input_video_mask, _ = get_video_to_video_latent(input_video, num_frames=num_frames, validation_video_mask=None, sample_size=sample_size)
video = pipe(
prompt,
num_frames=num_frames,
negative_prompt=negative_prompt,
height=sample_size[0],
width=sample_size[1],
video=input_video,
mask_video=input_video_mask,
strength=0.70
)
export_to_video(video.frames[0], "output.mp4", fps=8)
d、Control to video
import numpy as np
import torch
from diffusers import EasyAnimateControlPipeline
from diffusers.pipelines.easyanimate.pipeline_easyanimate_control import \
get_video_to_video_latent
from diffusers.pipelines.easyanimate.pipeline_easyanimate_inpaint import \
get_image_to_video_latent
from diffusers.utils import export_to_video, load_video
from PIL import Image
# Models: "alibaba-pai/EasyAnimateV5.1-12b-zh-Control-diffusers" or "alibaba-pai/EasyAnimateV5.1-7b-zh-Control-diffusers"
pipe = EasyAnimateControlPipeline.from_pretrained(
"alibaba-pai/EasyAnimateV5.1-12b-zh-Control-diffusers",
torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()
control_video = load_video(
"https://huggingface.co/alibaba-pai/EasyAnimateV5.1-12b-zh-Control/resolve/main/asset/pose.mp4"
)
prompt = (
"In this sunlit outdoor garden, a beautiful woman is dressed in a knee-length, sleeveless white dress. "
"The hem of her dress gently sways with her graceful dance, much like a butterfly fluttering in the breeze. "
"Sunlight filters through the leaves, casting dappled shadows that highlight her soft features and clear eyes, "
"making her appear exceptionally elegant. It seems as if every movement she makes speaks of youth and vitality. "
"As she twirls on the grass, her dress flutters, as if the entire garden is rejoicing in her dance. "
"The colorful flowers around her sway in the gentle breeze, with roses, chrysanthemums, and lilies each "
"releasing their fragrances, creating a relaxed and joyful atmosphere."
)
negative_prompt = "Twisted body, limb deformities, text subtitles, comics, stillness, ugliness, errors, garbled text."
sample_size = (672, 384)
num_frames = 49
generator = torch.Generator(device="cuda").manual_seed(43)
input_video, _, _ = get_video_to_video_latent(np.array(control_video), num_frames, sample_size)
video = pipe(prompt, num_frames=num_frames, negative_prompt=negative_prompt, height=sample_size[0], width=sample_size[1], control_video=input_video, generator=generator).frames[0]
export_to_video(video, "output.mp4", fps=8)
e、Camera Control to video
由于镜头控制模型需要对镜头文件进行处理,请前往asset下载对应镜头移动的txt文件。
相关代码较为复杂,已经隐藏,请点击打开。
EasyAnimateV5.1:
import numpy as np
import torch
from diffusers import EasyAnimateControlPipeline
from diffusers.pipelines.easyanimate.pipeline_easyanimate_control import \
get_video_to_video_latent
from diffusers.pipelines.easyanimate.pipeline_easyanimate_inpaint import \
get_image_to_video_latent
from diffusers.utils import export_to_video, load_video, load_image
from einops import rearrange
from packaging import version as pver
from PIL import Image
class Camera(object):
"""Copied from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
"""
def __init__(self, entry):
fx, fy, cx, cy = entry[1:5]
self.fx = fx
self.fy = fy
self.cx = cx
self.cy = cy
w2c_mat = np.array(entry[7:]).reshape(3, 4)
w2c_mat_4x4 = np.eye(4)
w2c_mat_4x4[:3, :] = w2c_mat
self.w2c_mat = w2c_mat_4x4
self.c2w_mat = np.linalg.inv(w2c_mat_4x4)
def custom_meshgrid(*args):
"""Copied from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
"""
# ref: https://pytorch.org/docs/stable/generated/torch.meshgrid.html?highlight=meshgrid#torch.meshgrid
if pver.parse(torch.__version__) < pver.parse('1.10'):
return torch.meshgrid(*args)
else:
return torch.meshgrid(*args, indexing='ij')
def get_relative_pose(cam_params):
"""Copied from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
"""
abs_w2cs = [cam_param.w2c_mat for cam_param in cam_params]
abs_c2ws = [cam_param.c2w_mat for cam_param in cam_params]
cam_to_origin = 0
target_cam_c2w = np.array([
[1, 0, 0, 0],
[0, 1, 0, -cam_to_origin],
[0, 0, 1, 0],
[0, 0, 0, 1]
])
abs2rel = target_cam_c2w @ abs_w2cs[0]
ret_poses = [target_cam_c2w, ] + [abs2rel @ abs_c2w for abs_c2w in abs_c2ws[1:]]
ret_poses = np.array(ret_poses, dtype=np.float32)
return ret_poses
def ray_condition(K, c2w, H, W, device):
"""Copied from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
"""
# c2w: B, V, 4, 4
# K: B, V, 4
B = K.shape[0]
j, i = custom_meshgrid(
torch.linspace(0, H - 1, H, device=device, dtype=c2w.dtype),
torch.linspace(0, W - 1, W, device=device, dtype=c2w.dtype),
)
i = i.reshape([1, 1, H * W]).expand([B, 1, H * W]) + 0.5 # [B, HxW]
j = j.reshape([1, 1, H * W]).expand([B, 1, H * W]) + 0.5 # [B, HxW]
fx, fy, cx, cy = K.chunk(4, dim=-1) # B,V, 1
zs = torch.ones_like(i) # [B, HxW]
xs = (i - cx) / fx * zs
ys = (j - cy) / fy * zs
zs = zs.expand_as(ys)
directions = torch.stack((xs, ys, zs), dim=-1) # B, V, HW, 3
directions = directions / directions.norm(dim=-1, keepdim=True) # B, V, HW, 3
rays_d = directions @ c2w[..., :3, :3].transpose(-1, -2) # B, V, 3, HW
rays_o = c2w[..., :3, 3] # B, V, 3
rays_o = rays_o[:, :, None].expand_as(rays_d) # B, V, 3, HW
# c2w @ dirctions
rays_dxo = torch.cross(rays_o, rays_d)
plucker = torch.cat([rays_dxo, rays_d], dim=-1)
plucker = plucker.reshape(B, c2w.shape[1], H, W, 6) # B, V, H, W, 6
# plucker = plucker.permute(0, 1, 4, 2, 3)
return plucker
def process_pose_file(pose_file_path, width=672, height=384, original_pose_width=1280, original_pose_height=720, device='cpu', return_poses=False):
"""Modified from https://github.com/hehao13/CameraCtrl/blob/main/inference.py
"""
with open(pose_file_path, 'r') as f:
poses = f.readlines()
poses = [pose.strip().split(' ') for pose in poses[1:]]
cam_params = [[float(x) for x in pose] for pose in poses]
if return_poses:
return cam_params
else:
cam_params = [Camera(cam_param) for cam_param in cam_params]
sample_wh_ratio = width / height
pose_wh_ratio = original_pose_width / original_pose_height # Assuming placeholder ratios, change as needed
if pose_wh_ratio > sample_wh_ratio:
resized_ori_w = height * pose_wh_ratio
for cam_param in cam_params:
cam_param.fx = resized_ori_w * cam_param.fx / width
else:
resized_ori_h = width / pose_wh_ratio
for cam_param in cam_params:
cam_param.fy = resized_ori_h * cam_param.fy / height
intrinsic = np.asarray([[cam_param.fx * width,
cam_param.fy * height,
cam_param.cx * width,
cam_param.cy * height]
for cam_param in cam_params], dtype=np.float32)
K = torch.as_tensor(intrinsic)[None] # [1, 1, 4]
c2ws = get_relative_pose(cam_params) # Assuming this function is defined elsewhere
c2ws = torch.as_tensor(c2ws)[None] # [1, n_frame, 4, 4]
plucker_embedding = ray_condition(K, c2ws, height, width, device=device)[0].permute(0, 3, 1, 2).contiguous() # V, 6, H, W
plucker_embedding = plucker_embedding[None]
plucker_embedding = rearrange(plucker_embedding, "b f c h w -> b f h w c")[0]
return plucker_embedding
def get_image_latent(ref_image=None, sample_size=None):
if ref_image is not None:
if isinstance(ref_image, str):
ref_image = Image.open(ref_image).convert("RGB")
ref_image = ref_image.resize((sample_size[1], sample_size[0]))
ref_image = torch.from_numpy(np.array(ref_image))
ref_image = ref_image.unsqueeze(0).permute([3, 0, 1, 2]).unsqueeze(0) / 255
else:
ref_image = torch.from_numpy(np.array(ref_image))
ref_image = ref_image.unsqueeze(0).permute([3, 0, 1, 2]).unsqueeze(0) / 255
return ref_image
# Models: "alibaba-pai/EasyAnimateV5.1-7b-zh-Control-Camera-diffusers" or "alibaba-pai/EasyAnimateV5.1-12b-zh-Control-Camera-diffusers"
pipe = EasyAnimateControlPipeline.from_pretrained(
"alibaba-pai/EasyAnimateV5.1-12b-zh-Control-Camera-diffusers",
torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()
input_video, input_video_mask = None, None
prompt = "Fireworks light up the evening sky over a sprawling cityscape with gothic-style buildings featuring pointed towers and clock faces. The city is lit by both artificial lights from the buildings and the colorful bursts of the fireworks. The scene is viewed from an elevated angle, showcasing a vibrant urban environment set against a backdrop of a dramatic, partially cloudy sky at dusk."
negative_prompt = "Twisted body, limb deformities, text subtitles, comics, stillness, ugliness, errors, garbled text."
sample_size = (384, 672)
num_frames = 49
fps = 8
ref_image = load_image("https://huggingface.co/alibaba-pai/EasyAnimateV5.1-12b-zh-Control-Camera/resolve/main/asset/1.png")
control_camera_video = process_pose_file("/The_Path_To/Pan_Left.txt", sample_size[1], sample_size[0])
control_camera_video = control_camera_video[::int(24 // fps)][:num_frames].permute([3, 0, 1, 2]).unsqueeze(0)
ref_image = get_image_latent(sample_size=sample_size, ref_image=ref_image)
video = pipe(
prompt,
negative_prompt=negative_prompt,
num_frames=num_frames,
height=sample_size[0],
width=sample_size[1],
control_camera_video=control_camera_video,
ref_image=ref_image
).frames[0]
export_to_video(video, "output.mp4", fps=fps)
f、float8 model
由于EasyAnimateV5.1的参数非常大,我们需要考虑显存节省方案,以节省显存适应消费级显卡。我们可以将模型放入float8以节省显存。
以图生视频为例,我们将模型防止到float8上,然后在预测的时候转为bfloat16。
"""Modified from https://github.com/kijai/ComfyUI-MochiWrapper
"""
import torch
import torch.nn as nn
from diffusers import EasyAnimateInpaintPipeline
from diffusers.pipelines.easyanimate.pipeline_easyanimate_control import \
get_video_to_video_latent
from diffusers.pipelines.easyanimate.pipeline_easyanimate_inpaint import \
get_image_to_video_latent
from diffusers.utils import export_to_video, load_image, load_video
def autocast_model_forward(cls, origin_dtype, *inputs, **kwargs):
weight_dtype = cls.weight.dtype
cls.to(origin_dtype)
# Convert all inputs to the original dtype
inputs = [input.to(origin_dtype) for input in inputs]
out = cls.original_forward(*inputs, **kwargs)
cls.to(weight_dtype)
return out
def convert_weight_dtype_wrapper(module, origin_dtype):
for name, module in module.named_modules():
if name == "" or "embed_tokens" in name:
continue
original_forward = module.forward
if hasattr(module, "weight"):
setattr(module, "original_forward", original_forward)
setattr(
module,
"forward",
lambda *inputs, m=module, **kwargs: autocast_model_forward(m, origin_dtype, *inputs, **kwargs)
)
# Models: "alibaba-pai/EasyAnimateV5.1-12b-zh-InP-diffusers" or "alibaba-pai/EasyAnimateV5.1-7b-zh-InP-diffusers"
pipe = EasyAnimateInpaintPipeline.from_pretrained(
"alibaba-pai/EasyAnimateV5.1-12b-zh-InP-diffusers",
torch_dtype=torch.bfloat16
)
pipe.transformer = pipe.transformer.to(torch.float8_e4m3fn)
from fp8_optimization import convert_weight_dtype_wrapper
for _text_encoder in [pipe.text_encoder, pipe.text_encoder_2]:
if hasattr(_text_encoder, "visual"):
del _text_encoder.visual
convert_weight_dtype_wrapper(pipe.transformer, torch.bfloat16)
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()
prompt = "An astronaut hatching from an egg, on the surface of the moon, the darkness and depth of space realised in the background. High quality, ultrarealistic detail and breath-taking movie-like camera shot."
negative_prompt = "Twisted body, limb deformities, text subtitles, comics, stillness, ugliness, errors, garbled text."
validation_image_start = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/astronaut.jpg")
validation_image_end = None
sample_size = (448, 576)
num_frames = 49
input_video, input_video_mask = get_image_to_video_latent(
[validation_image_start], validation_image_end, num_frames, sample_size
)
video = pipe(
prompt,
negative_prompt=negative_prompt,
num_frames=num_frames,
height=sample_size[0],
width=sample_size[1],
video=input_video,
mask_video=input_video_mask
)
export_to_video(video.frames[0], "output.mp4", fps=8)
显存需求
EasyAnimateV5.1-12B的视频大小可以由不同的GPU Memory生成,包括:
GPU memory | 384x672x25 | 384x672x49 | 576x1008x25 | 576x1008x49 | 768x1344x25 | 768x1344x49 |
---|---|---|---|---|---|---|
16GB | 🧡 | ⭕️ | ⭕️ | ⭕️ | ❌ | ❌ |
24GB | 🧡 | 🧡 | 🧡 | 🧡 | 🧡 | ❌ |
40GB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
80GB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
EasyAnimateV5.1-7B的视频大小可以由不同的GPU Memory生成,包括:
GPU memory | 384x672x25 | 384x672x49 | 576x1008x25 | 576x1008x49 | 768x1344x25 | 768x1344x49 |
---|---|---|---|---|---|---|
16GB | 🧡 | 🧡 | ⭕️ | ⭕️ | ❌ | ❌ |
24GB | ✅ | ✅ | ✅ | 🧡 | 🧡 | ❌ |
40GB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
80GB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
✅ 表示它可以在"model_cpu_offload"的情况下运行,🧡代表它可以在"model_cpu_offload" + float8的情况下运行,⭕️ 表示它可以在"sequential_cpu_offload"的情况下运行,当前由于qwen2vl不支持"sequential_cpu_offload",我们无法使用在diffusers中使用sequential_cpu_offload,具体修复时间未知,但可以在EasyAnimate官方仓库中使用,❌ 表示它无法运行。请注意,使用sequential_cpu_offload运行会更慢。
有一些不支持torch.bfloat16的卡型,如2080ti、V100,需要使用torch.float16才可以运行。
EasyAnimateV5.1-12B使用不同GPU在25个steps中的生成时间如下:
GPU | 384x672x72 | 384x672x49 | 576x1008x25 | 576x1008x49 | 768x1344x25 | 768x1344x49 |
---|---|---|---|---|---|---|
A10 24GB | 约120秒 (4.8s/it) | 约240秒 (9.6s/it) | 约320秒 (12.7s/it) | 约750秒 (29.8s/it) | ❌ | ❌ |
A100 80GB | 约45秒 (1.75s/it) | 约90秒 (3.7s/it) | 约120秒 (4.7s/it) | 约300秒 (11.4s/it) | 约265秒 (10.6s/it) | 约710秒 (28.3s/it) |
参考文献
- CogVideo: https://github.com/THUDM/CogVideo/
- Flux: https://github.com/black-forest-labs/flux
- magvit: https://github.com/google-research/magvit
- PixArt: https://github.com/PixArt-alpha/PixArt-alpha
- Open-Sora-Plan: https://github.com/PKU-YuanGroup/Open-Sora-Plan
- Open-Sora: https://github.com/hpcaitech/Open-Sora
- Animatediff: https://github.com/guoyww/AnimateDiff
- HunYuan DiT: https://github.com/tencent/HunyuanDiT
- ComfyUI-KJNodes: https://github.com/kijai/ComfyUI-KJNodes
- ComfyUI-EasyAnimateWrapper: https://github.com/kijai/ComfyUI-EasyAnimateWrapper
- ComfyUI-CameraCtrl-Wrapper: https://github.com/chaojie/ComfyUI-CameraCtrl-Wrapper
- CameraCtrl: https://github.com/hehao13/CameraCtrl
- DragAnything: https://github.com/showlab/DragAnything
许可证
本项目采用 Apache License (Version 2.0).
- Downloads last month
- 2