EasyAnimate是阿里云PAI自主研发的DiT的视频生成框架,它提供了完整的高清长视频生成解决方案,包括视频数据预处理、VAE训练、DiT训练、模型推理和模型评测等,可用于文生视频和图生视频推理。本文介绍如何在PAI上使用EasyAnimate,完成模型部署和微调。
方案介绍
本文为您介绍以下两种视频生成的方式:
简介 | DSW为您云端AI开发IDE或开发机,内置多种开发环境,对熟悉Notebook/VSCode的用户,可以快速开始模型开发。 其中,DSW Gallery提供多种案例。您可以打开案例,一键运行Notebook,来完成EasyAnimate模型的推理和训练。您也可以在此基础上进行二次开发,例如模型微调。 | Model Gallery集成了众多开源的优质预训练模型,帮助您零代码,高效快捷地训练和部署大模型。您可以通过Model Gallery一键部署EasyAnimate模型并生成视频,快速体验AI应用。 |
计费说明 |
| Model Gallery封装了DLC和EAS,其费用说明如下:
|
前提条件
开通PAI。登录PAI控制台,左上角选择开通区域,然后一键开通并创建默认工作空间。建议使用主账号开通产品,以避免权限受限。
方式一:使用DSW
步骤一:创建DSW实例
进入DSW页面。
登录PAI控制台。
在概览页面选择目标地域。
在左侧导航栏单击工作空间列表,在工作空间列表页面中单击目标工作空间名称,进入对应工作空间内。
在工作空间页面的左侧导航栏选择模型开发与训练>交互式建模(DSW),进入DSW页面。
单击新建实例。
在新建实例向导页面,配置以下关键参数,其他参数保持默认即可。
参数
说明
实例名称
本教程使用的示例值为:AIGC_test_01
资源类型
选择公共资源。
资源规格
选择GPU规格下的
ecs.gn7i-c8g1.2xlarge
,或其他A10、GU100规格。镜像
选择官方镜像,搜索并选择的
easyanimate:1.1.5-pytorch2.2.0-gpu-py310-cu118-ubuntu22.04
。单击确定,创建实例。
步骤二:下载EasyAnimate模型
单击目标DSW实例操作列下的打开,进入DSW实例的开发环境。
在Notebook页签的Launcher页面,单击快速开始区域下的浏览 Gallery,打开DSW Gallery页面。
在DSW Gallery页面中,搜索基于EasyAnimate的AI视频生成示例 (V5)。单击在DSW中打开,即可自动将本教程所需的资源下载至DSW实例中。
基于EasyAnimate的AI视频生成示例有多个版本,本文以V5版本为例进行说明。
下载EasyAnimate相关代码和模型并进行安装。
在easyanimate的教程文件中,单击
依次运行函数定义、下载代码和下载模型节点命令。
步骤三:使用WebUI生成视频
单击
运行模型推理 > UI启动节点的命令,进行模型推理。
单击生成的链接,进入WebUI界面。
在WebUI界面选择预训练模型路径,其它参数按需配置即可。
单击Generate(生成),等待大约5分钟后,即可在右侧查看或下载生成的视频。
本文使用了公共资源创建DSW实例,计费方式为按量付费。当您不需要使用DSW时请停止或删除实例,以免继续扣费。
方式二:使用Model Gallery
场景一:直接部署模型
进入Model Gallery页面。
登录PAI控制台。
在左侧导航栏单击工作空间列表,在工作空间列表页面单击目标工作空间名称,进入对应工作空间。
在左侧导航栏单击
。
在Model Gallery页面,搜索EasyAnimate 高清长视频生成模型,然后单击部署,配置相关参数。
单击部署 > 确定部署服务。当状态变为运行中时,表示模型部署成功。
模型部署完成后,您可以使用WebUI及API两种方式调用服务来生成视频。
后续查看部署任务详情,您可通过在左侧导航栏单击Model Gallery > 任务管理 > 部署任务,然后再单击服务名称查看。
WebUI方式
在服务详情页面,单击查看WEB应用。
在WebUI界面选择预训练的模型路径,其它参数按需配置即可。
单击Generate(生成),等待大约5分钟后,即可在右侧查看或下载生成的视频。
API方式
在服务详情页面的资源详情区域,单击查看调用信息,获取调用服务所需的信息。
通过接口更新Transformer模型,可在DSW实例或本地Python环境中执行。
如果已经在WebUI中选择模型,则无需发送请求重复调用。如遇请求超时,请在EAS日志中确认模型已加载完毕。加载完成,日志中将提示
Update diffusion transformer done
。Python请求示例如下。
import json import requests def post_diffusion_transformer(diffusion_transformer_path, url='http://127.0.0.1:7860', token=None): datas = json.dumps({ "diffusion_transformer_path": diffusion_transformer_path }) head = { 'Authorization': token } r = requests.post(f'{url}/easyanimate/update_diffusion_transformer', data=datas, headers=head, timeout=15000) data = r.content.decode('utf-8') return data def post_update_edition(edition, url='http://0.0.0.0:7860',token=None): head = { 'Authorization': token } datas = json.dumps({ "edition": edition }) r = requests.post(f'{url}/easyanimate/update_edition', data=datas, headers=head) data = r.content.decode('utf-8') return data if __name__ == '__main__': url = '<eas-service-url>' token = '<eas-service-token>' # -------------------------- # # Step 1: update edition # -------------------------- # edition = "v3" outputs = post_update_edition(edition,url = url,token=token) print('Output update edition: ', outputs) # -------------------------- # # Step 2: update edition # -------------------------- # # 默认路径 (二选一) diffusion_transformer_path = "/mnt/models/Diffusion_Transformer/EasyAnimateV3-XL-2-InP-512x512" # diffusion_transformer_path = "/mnt/models/Diffusion_Transformer/EasyAnimateV3-XL-2-InP-768x768" outputs = post_diffusion_transformer(diffusion_transformer_path, url = url, token=token) print('Output update edition: ', outputs)
其中:
调用服务,生成视频或图片。
服务输入参数说明
参数名
说明
类型
默认值
prompt_textbox
用户输入的正向提示词。
string
必填。无默认值
negative_prompt_textbox
用户输入的负向提示词。
string
"The video is not of a high quality, it has a low resolution, and the audio quality is not clear. Strange motion trajectory, a poor composition and deformed video, low resolution, duplicate and ugly, strange body structure, long and strange neck, bad teeth, bad eyes, bad limbs, bad hands, rotating camera, blurry camera, shaking camera. Deformation, low-resolution, blurry, ugly, distortion."
sample_step_slider
用户输入的步数。
int
30
cfg_scale_slider
引导系数。
int
6
sampler_dropdown
采样器类型。
取值包括:Eluer、EluerA、DPM++、PNDM、DDIM
string
Eluer
width_slider
生成视频宽度。
int
672
height_slider
生成视频高度。
int
384
length_slider
生成视频帧数。
int
144
is_image
是否是图片。
bool
FALSE
lora_alpha_slider
LoRA模型参数的权重。
float
0.55
seed_textbox
随机种子。
int
43
lora_model_path
额外的LoRA模型路径。
若有,则会在请求时带上lora。在当次请求后移除。
string
none
base_model_path
需要更新的transformer模型路径。
string
none
motion_module_path
需要更新的motion_module模型路径。
string
none
generation_method
生成类型。包括:Video Generation,Image Generation
string
none
Python请求示例
服务返回base64_encoding,为base64结果。
您可以在/mnt/workspace/demos/easyanimate/目录中查看生成结果。
import base64 import json import sys import time from datetime import datetime from io import BytesIO import cv2 import requests import base64 def post_infer(generation_method, length_slider, url='http://127.0.0.1:7860',token=None): head = { 'Authorization': token } datas = json.dumps({ "base_model_path": "none", "motion_module_path": "none", "lora_model_path": "none", "lora_alpha_slider": 0.55, "prompt_textbox": "This video shows Mount saint helens, washington - the stunning scenery of a rocky mountains during golden hours - wide shot. A soaring drone footage captures the majestic beauty of a coastal cliff, its red and yellow stratified rock faces rich in color and against the vibrant turquoise of the sea.", "negative_prompt_textbox": "Strange motion trajectory, a poor composition and deformed video, worst quality, normal quality, low quality, low resolution, duplicate and ugly, strange body structure, long and strange neck, bad teeth, bad eyes, bad limbs, bad hands, rotating camera, blurry camera, shaking camera", "sampler_dropdown": "Euler", "sample_step_slider": 30, "width_slider": 672, "height_slider": 384, "generation_method": "Video Generation", "length_slider": length_slider, "cfg_scale_slider": 6, "seed_textbox": 43, }) r = requests.post(f'{url}/easyanimate/infer_forward', data=datas, headers=head, timeout=1500) data = r.content.decode('utf-8') return data if __name__ == '__main__': # initiate time now_date = datetime.now() time_start = time.time() url = '<eas-service-url>' token = '<eas-service-token>' # -------------------------- # # Step 3: infer # -------------------------- # # "Video Generation" and "Image Generation" generation_method = "Video Generation" length_slider = 72 outputs = post_infer(generation_method, length_slider, url = url, token=token) # Get decoded data outputs = json.loads(outputs) base64_encoding = outputs["base64_encoding"] decoded_data = base64.b64decode(base64_encoding) is_image = True if generation_method == "Image Generation" else False if is_image or length_slider == 1: file_path = "1.png" else: file_path = "1.mp4" with open(file_path, "wb") as file: file.write(decoded_data) # End of record time # The calculated time difference is the execution time of the program, expressed in seconds / s time_end = time.time() time_sum = (time_end - time_start) % 60 print('# --------------------------------------------------------- #') print(f'# Total expenditure: {time_sum}s') print('# --------------------------------------------------------- #')
其中:
本文使用了公共资源创建模型服务,计费方式为按量付费。当您不需要使用服务时请停止或删除服务,以免继续扣费。
场景二:微调训练后部署模型
进入Model Gallery页面。
登录PAI控制台。
在左侧导航栏单击工作空间列表,在工作空间列表页面单击目标工作空间名称,进入对应工作空间。
在左侧导航栏单击
。
在Model Gallery页面,搜索EasyAnimate 高清长视频生成模型,单击训练进入配置页面。
资源来源选择公共资源,实例规格选择A10及其以上显卡的实例,超参数可以按需配置,其他参数默认即可。
单击训练 > 确定创建训练任务。训练大约需要40分钟,当任务状态为成功时,代表模型训练成功。
后续查看训练任务详情,您可通过在左侧导航栏单击Model Gallery > 任务管理 > 训练任务,然后再单击任务名称查看。
单击右上角的部署部署微调后的模型。当状态变为运行中时,代表模型部署成功。
在服务详情页面,单击页面上方的查看WEB应用。
后续查看服务详情,您可通过在左侧导航栏单击Model Gallery > 任务管理 > 部署任务,然后再单击服务名称查看。
在WebUI界面,选择训练完成的LoRA模型进行视频生成。
本文使用了公共资源创建模型服务,计费方式为按量付费。当您不需要使用服务时请停止或删除服务,以免继续扣费。
相关文档
EAS提供了场景化部署方式,可一键部署基于ComfyUI和Stable Video Diffusion模型的AI视频生成服务,帮助您完成社交平台短视频内容生成、动画制作等任务。具体操作,请参见AI视频生成-ComfyUI部署。