一、模型简介
近期,阿里巴巴重磅开源了视频生成大模型——Wan 2.1( 通义万相 2.1)。此次开源采用 Apache 2.0 协议,当前全球开发者可通过直接下载体验。Wan2.1 提供了两个主要参数版本——14B 和 1.3B,以及四款具体模型,分别涵盖文本生成视频(T2V)和图像生成视频(I2V)任务,带来了一个全面且开放的视频基础模型套件。
- 文生视频模型:Wan2.1-T2V-14B 和 Wan2.1-T2V-1.3B
其中Wan2.1-T2V-14B 是唯一一个能生成中英文文本的视频模型,支持 480P 和 720P 分辨率的视频生成。而T2V-1.3B 模型支持在几乎所有消费级 GPU 上进行视频生成,仅需 8 GB 显存即可生成一段 5 秒钟的 480P 视频。
- 图生视频模型:Wan2.1-I2V-14B-480P 和 Wan2.1-I2V-14B-720P
I2V-14B 模型在性能上超越了领先的闭源模型以及所有现有的开源模型,达到了 SOTA 水平。它能够基于输入的文本和图像生成复杂的视觉场景和运动模式,包括 480P 和 720P 分辨率的视频。
本次教大家部署的是Wan2.1 GP,这是由 DeepBeepMeep 基于 Wan2.1 开发的视频生成项目,致力于为 GPU 资源有限的用户提供高性能、低资源消耗的视频生成解决方案。
相较于原始的 Alibaba 模型,Wan2.1 GP 具有以下改进:
- 资源需求降低:大幅减少了 RAM 和 VRAM 的需求,使模型能够在资源有限的设备上运行。
- 速度提升:通过编译和快速加载 / 卸载机制,显著提高了运行速度。
- 多配置支持:提供多种配置文件,可在低端消费级配置(32GB RAM 和 12GB VRAM)上以合理速度运行,也可在高端消费级配置(48GB RAM 和 24GB VRAM)上实现快速运行。
- 自动下载:支持自动下载所需的模型文件,简化了安装过程。
- 界面优化:改进了 Gradio 界面,增加了进度条和更多选项,提升了用户体验。
- 多提示支持:支持多个提示和每个提示的多代生成。
- Lora 支持:在 32GB RAM 或更少的情况下支持多个预训练的 Lora。
- 安装简化:安装过程更加简单,降低了使用门槛。
以下为具体的部署教程:
二、部署教程
1. 部署准备
1、项目地址:https://github.com/deepbeepmeep/Wan2GP
2、GPU云平台:如果你本地有12GB以上显卡,并且安装了Linux系统,可以跳过此步骤。否则建议使用GPU云平台,这里推荐使用星海智算。注册账号并进入星海智算平台后,可以创建一个实例,打开 JupyterLab,并进入终端。
2. 安装依赖
Linux系统需要安装以下依赖项:
- Git:用于下载项目。
- FFmpeg:用于音频和视频处理。
学术加速
source /etc/network_turbo
安装 Git 及其相关工具以及Curl工具。
apt-get update
apt install git-all
apt install ffmpeg
3. 下载项目
将 GitHub 上的 Wan2.1 GP仓库克隆到实例中
git clone https://github.com/deepbeepmeep/Wan2GP.git
cd Wan2GP
4. 创建虚拟环境
创建名为 wan2gp 的 Conda 环境,并指定 Python 版本为 3.10.9。
conda init --all
conda create -n wan2gp python=3.10.9
conda activate wan2gp
5. 安装项目依赖
安装项目所需依赖,如pytorch、Sage Attention、flash-attn等。
pip install torch==2.6.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu124
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
# 安装Sage Attention并指定版本1.0.6,Sage Attention 可以使程序运行速度提升约 30%(可选)
pip install sageattention==1.0.6
# 手动编译安装 Sage Attention 2,Sage Attention 2 能让程序运行速度提升约 40%(可选)
git clone https://github.com/thu-ml/SageAttention
cd SageAttention
pip install -e .
# 安装flash-attn,指定版本为2.7.2,Flash Attention 来优化程序性能(可选)
pip install flash-attn==2.7.2.post1
6. 运行程序
运行程序,首次运行会自动下载所需模型
python gradio_server.py
运行成功如图所示:
启动指定server-name,默认监听地址为http://localhost:7860,只能本机访问,修改为0.0.0.0可供外部访问。
python gradio_server.py --server-name 0.0.0.0
运行成功如图所示:
7. 访问程序
通过 SSH 隧道将程序端口(如 7860)映射到本地,以便访问:
进入星海智算平台,点击“端口映射”,输入需要映射的端口号(默认映射端口7860)
连接进入应用界面如下:
三、使用案例
- 文生视频
提示词:
A large orange octopus is seen resting on the bottom of the ocean floor, blending in with the sandy and rocky terrain. Its tentacles are spread out around its body, and its eyes are closed. The octopus is unaware of a king crab that is crawling towards it from behind a rock, its claws raised and ready to attack. The crab is brown and spiny, with long legs and antennae. The scene is captured from a wide angle, showing the vastness and depth of the ocean. The water is clear and blue, with rays of sunlight filtering through. The shot is sharp and crisp, with a high dynamic range. The octopus and the crab are in focus, while the background is slightly blurred, creating a depth of field effect.:32帧30步:生成时间70.2s,分辨率832x480 (16:9, 480p)
- 图生视频