使用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

相关推荐
回眸&啤酒鸭5 天前
【回眸】Minicart 电商购物车核心功能落地指南
人工智能
一隅论数智5 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
默_笙5 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
AI的探索之旅5 天前
97 个 OpenCV 实例(三十):双目立体,从标定到点云
人工智能·opencv·计算机视觉
AlbertZein5 天前
Step-5-Preview 上手实测:3D 游戏、金融分析、网页设计一次跑完
人工智能·aigc
LaughingZhu5 天前
Product Hunt 每日热榜 | 2026-09-19
人工智能·深度学习·神经网络·搜索引擎·百度
qq_426003965 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫5 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
美狐美颜SDK开放平台5 天前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk