bubbliiiing
Update Readme
f658613
|
raw
history blame
38.2 kB

Arxiv Page Project Page Modelscope Studio Hugging Face Spaces Discord Page

Introduction

EasyAnimate is a pipeline based on the transformer architecture, designed for generating AI images and videos, and for training baseline models and Lora models for Diffusion Transformer. We support direct prediction from pre-trained EasyAnimate models, allowing for the generation of videos with various resolutions, approximately 6 seconds in length, at 8fps (EasyAnimateV5, 1 to 49 frames). Additionally, users can train their own baseline and Lora models for specific style transformations.

English | 简体中文

Model zoo

EasyAnimateV5.1 for diffusers:

This weight file is mainly used for the diffusers repository.

Please note that there are some differences in the weight format and usage between the EasyAnimate repository and the diffusers repository. Be sure to carefully distinguish between them.

7B:

Name Type Storage Space Hugging Face Description
EasyAnimateV5.1-7b-zh-InP EasyAnimateV5.1 30 GB 🤗Link Official image-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-7b-zh-Control EasyAnimateV5.1 30 GB 🤗Link Official video control weights, supporting various control conditions such as Canny, Depth, Pose, MLSD, and trajectory control. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-7b-zh-Control-Camera EasyAnimateV5.1 30 GB 🤗Link Official video camera control weights, supporting direction generation control by inputting camera motion trajectories. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-7b-zh EasyAnimateV5.1 30 GB 🤗Link Official text-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.

12B:

Name Type Storage Space Hugging Face Description
EasyAnimateV5.1-12b-zh-InP EasyAnimateV5.1 39 GB 🤗Link Official image-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-12b-zh-Control EasyAnimateV5.1 39 GB 🤗Link Official video control weights, supporting various control conditions such as Canny, Depth, Pose, MLSD, and trajectory control. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-12b-zh-Control-Camera EasyAnimateV5.1 39 GB 🤗Link Official video camera control weights, supporting direction generation control by inputting camera motion trajectories. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-12b-zh EasyAnimateV5.1 39 GB 🤗Link Official text-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1:

7B:

Name Type Storage Space Hugging Face Model Scope Description
EasyAnimateV5.1-7b-zh-InP EasyAnimateV5.1 30 GB 🤗Link 😄Link Official image-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-7b-zh-Control EasyAnimateV5.1 30 GB 🤗Link 😄Link Official video control weights, supporting various control conditions such as Canny, Depth, Pose, MLSD, and trajectory control. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-7b-zh-Control-Camera EasyAnimateV5.1 30 GB 🤗Link 😄Link Official video camera control weights, supporting direction generation control by inputting camera motion trajectories. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-7b-zh EasyAnimateV5.1 30 GB 🤗Link 😄Link Official text-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.

12B:

Name Type Storage Space Hugging Face Model Scope Description
EasyAnimateV5.1-12b-zh-InP EasyAnimateV5.1 39 GB 🤗Link 😄Link Official image-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-12b-zh-Control EasyAnimateV5.1 39 GB 🤗Link 😄Link Official video control weights, supporting various control conditions such as Canny, Depth, Pose, MLSD, and trajectory control. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-12b-zh-Control-Camera EasyAnimateV5.1 39 GB 🤗Link 😄Link Official video camera control weights, supporting direction generation control by inputting camera motion trajectories. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.
EasyAnimateV5.1-12b-zh EasyAnimateV5.1 39 GB 🤗Link 😄Link Official text-to-video weights. Supports video prediction at multiple resolutions (512, 768, 1024), trained with 49 frames at 8 frames per second, and supports for multilingual prediction.

Video Result

Image to Video with EasyAnimateV5.1-12b-zh-InP

Text to Video with EasyAnimateV5.1-12b-zh

Control Video with EasyAnimateV5.1-12b-zh-Control

Trajectory Control:

Generic Control Video (Canny, Pose, Depth, etc.):

Camera Control with EasyAnimateV5.1-12b-zh-Control-Camera

Pan Up Pan Left Pan Right
Pan Down Pan Up + Pan Left Pan Up + Pan Right

How to use

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

Since the camera control model needs to process the camera files, please go to the asset page to download the corresponding TXT files for camera movements.

The relevant code is relatively complex and has been hidden. Please click to expand it.

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

Since the parameters of EasyAnimateV5.1 are very large, we need to consider memory-saving solutions to adapt to consumer-grade GPUs. We can convert the model to float8 to save GPU memory.

For example, in the case of text-to-video generation, we first load the model in float8 to save memory, and then convert it to bfloat16 during inference.

"""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)

GPU Memory

The video size for EasyAnimateV5.1-12B can be generated by different GPU Memory, including:

GPU memory 384x672x25 384x672x49 576x1008x25 576x1008x49 768x1344x25 768x1344x49
16GB 🧡 ⭕️ ⭕️ ⭕️
24GB 🧡 🧡 🧡 🧡 🧡
40GB
80GB

The video size for EasyAnimateV5.1-7B can be generated by different GPU Memory, including:

GPU memory 384x672x25 384x672x49 576x1008x25 576x1008x49 768x1344x25 768x1344x49
16GB 🧡 🧡 ⭕️ ⭕️
24GB 🧡 🧡
40GB
80GB

✅ Indicates that it can run under "model_cpu_offload", 🧡 indicates that it can run under "model_cpu_offload" + float8, and ⭕️ indicates that it can run under "sequential_cpu_offload". Currently, due to the fact that qwen2vl does not support "sequential_cpu_offload", we are unable to use "sequential_cpu_offload" in diffusers. The specific fix time is unknown, but it can be used in the official EasyAnimate repository. ❌ Indicates that it cannot run. Please note that running with "sequential_cpu_offload" will be slower.

Some GPUs that do not support torch.bfloat16, such as 2080ti and V100, require changing the torch.bfloat16 to torch.float16 in order to run.

The generation time for EasyAnimateV5.1-12B using different GPUs over 25 steps is as follows:

GPU 384x672x72 384x672x49 576x1008x25 576x1008x49 768x1344x25 768x1344x49
A10 24GB ~120s (4.8s/it) ~240s (9.6s/it) ~320s (12.7s/it) ~750s (29.8s/it)
A100 80GB ~45s (1.75s/it) ~90s (3.7s/it) ~120s (4.7s/it) ~300s (11.4s/it) ~265s (10.6s/it) ~710s (28.3s/it)

Contact Us

  1. Use Dingding to search group 77450006752 or Scan to join.
  2. You need to scan the image to join the WeChat group or if it is expired, add this student as a friend first to invite you.
ding group Wechat group Person

Reference

License

This project is licensed under the Apache License (Version 2.0).