使用HunyuanVideo搭建文本生视频大模型

1.摘要

HunyuanVideo是一个全新的开源视频基础模型,其视频生成性能堪比领先的闭源模型,甚至超越它们。我们采用了多项模型学习的关键技术,通过有效的模型架构和数据集扩展策略,我们成功训练了一个拥有超过 130 亿个参数的视频生成模型,使其成为所有开源模型中规模最大的模型。

部署环境为:linux服务器,GPU大小为64G。

2. 安装

2.1 下载项目代码

git clone https://github.com/tencent/HunyuanVideo

cd HunyuanVideo

2.2 linux 环境部署

#1. Create conda environment

conda create -n HunyuanVideo python==3.10.9

2. Activate the environment

conda activate HunyuanVideo

3. Install PyTorch and other dependencies using conda

For CUDA 11.8

conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=11.8 -c pytorch -c nvidia

For CUDA 12.4

conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.4 -c pytorch -c nvidia

conda install pytorch-cuda -c pytorch -c nvidia

4. Install pip dependencies

python -m pip install -r requirements.txt

5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)

python -m pip install ninja

python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.6.3

6. Install xDiT for parallel inference (It is recommended to use torch 2.4.0 and flash-attn 2.6.3)

python -m pip install xfuser==0.4.0

2.3 模型下载

https://huggingface.co/tencent/HunyuanVideo/tree/refs%2Fpr%2F18

  • 需要下载hunyuan-video-t2v-720p,text_encoder,text_encoder_2,tokenizer,tokenizer_2这5个。
  • 下载完成以后需要把tokenizer里面的内容放到text_encoder内。需要把tokenizer_2里面的内容放到text_encoder_2内。

cp tokenizer/* text_encoder

cp tokenizer_2/* text_encoder_2

  • 把hunyuan-video-t2v-720p,text_encoder,text_encoder_2放到目录HunyuanVideo/ckpts下面:
  • 目录结构:

3. 生成视频

3.1 本地生成

cd HunyuanVideo

CUDA_VISIBLE_DEVICES=0 python sample_video.py \

--video-size 544 544 \

--video-length 129 \

--infer-steps 50 \

--prompt "A cat walks on the grass, realistic style." \

--flow-reverse \

--use-cpu-offload \

--save-path ./results

文本生成视频成功,视频时长5秒,生成用时18分钟。

生成的视频在results目录下面:

最后去掉引号:

mv '2025-04-25-12:40:56_seed293232_A cat walks on the grass, realistic style..mp4' cat.mp4

3.2 运行Gradio Server

3.2.1 启动服务

Python gradio_server.py --flow-reverse

由于本机端口占用,所以我把端口改成了8881.

运行成功:

3.2.2 网页生成视频

由于GPU才64G,所以Number of Inference Steps设置为20。

3.3 参数详解

4. 可能遇到的问题及解决方法

4.1 问题1

TypeError: argument of type 'bool' is not iterable

ValueError: When localhost is not accessible, a shareable link must be created. Please set share=True or check your proxy settings to allow access to localhost.

解决方案:

pydantic这个包版本的问题,退回2.10.6版本即可 pip install pydantic==2.10.6,完美解决。

4.2 问题2

RuntimeError: Unable to find a valid cuDNN algorithm to run convolution

解决方案:

在gradio_server.py中增加以下代码:

import torch

torch.backends.cudnn.benchmark = True

4.3 问题3

ffmpy.ffmpy.FFExecutableNotFoundError: Executable 'ffprobe' not found

解决方案:

sudo apt-get install ffmpeg

相关推荐
BYSJMG2 分钟前
计算机毕设选题做什么好?基于大数据的用户美食数据分析与可视化,PySpark预处理+ECharts大屏,含Isolation Forest异常检测算法
大数据·python·信息可视化·数据分析·spark·课程设计·美食
等一朵映山红2 分钟前
扩散模型在跨模态生成任务中的时序一致性优化
人工智能·机器学习
顿哥GPT3 分钟前
ChatGPT Plus / Pro + Codex 深度实战指南(2026年9月5日):从模型能力对比到 Codex 自动化编程工作流全解析
人工智能·chatgpt·自动化
奈斯先生Vector4 分钟前
AIGC 视频生成换个拍法:用 Kling Video 把一张人物图变成可剪辑的短故事
开发语言·人工智能·windows·python·aigc·音视频
IT_陈寒4 分钟前
Java的HashMap竟然不是线程安全的,现在才知道!
前端·人工智能·后端
IT_陈寒4 分钟前
React hooks闭包陷阱让我加了一宿班
前端·人工智能·后端
用户5274675614214 分钟前
Agent 能跑不等于岗位还合格:给 AI 员工做一次可回滚的上岗发布
人工智能
卷无止境5 分钟前
当"精简主义"住进AI编程助手:Ponytail深度解读
后端·python·fastapi
2601_962298277 分钟前
交易开拓者通常使用什么编程语言?这种语言如何帮助自动化交易?
java·c++·python·编程语言·自动化交易