欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > 部署cogvideox视频生成模型

部署cogvideox视频生成模型

2025/2/23 6:21:33 来源:https://blog.csdn.net/xinvictory/article/details/142756175  浏览:    关键词:部署cogvideox视频生成模型

      CogVideoX是智谱AI开源的一款视频生成模型,其核心在于3D变分自编码器和3D旋转位置编码(3D RoPE)技术。这些技术使得CogVideoX能够在保持视频帧间连贯性的同时,极大地降低计算资源需求,并生成流畅、连贯的视频序列。此外,CogVideoX还具备强大的文本理解能力,能够处理超长且复杂的文本提示,生成与用户输入高度相关的视频内容.

查看显存

nvidia-smi

在线创建Python虚拟环境

 python3.10 -m venv python310

激活Python虚拟环境

 #source /usr/local/bin/python310/bin/activate

拉取CogVideo代码

#cd /home

git clone https://github.com/THUDM/CogVideo.git

安装CogVideo依赖

pip install -r requirements.txt  

modelscope下载cogvideox-2b模型

pip install modelscope

modelscope download --model zhipuai/cogvideox-2b

模型具体位置:

/home/admin/workspace/.cache/modelscope/hub/zhipuai/cogvideox-2b

创建test.py

vi test.py

import torchfrom diffusers import CogVideoXPipelinefrom diffusers.utils import export_to_videoimport osos.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'# prompt里写自定义想要生成的视频内容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."pipe = CogVideoXPipeline.from_pretrained("/home/admin/workspace/.cache/modelscope/hub/zhipuai/cogvideox-2b", # 这里填CogVideo模型存放的位置,此处是放在了数据盘中torch_dtype=torch.float16).to("cuda")# 参数do_classifier_free_guidance设置为True可以启用无分类器指导,增强生成内容一致性和多样性# num_videos_per_prompt控制每个prompt想要生成的视频数量# max_sequence_length控制输入序列的最大长度prompt_embeds, _ = pipe.encode_prompt(prompt=prompt,do_classifier_free_guidance=True,num_videos_per_prompt=1,max_sequence_length=226,device="cuda",dtype=torch.float16,)# 释放不需要的张量del _torch.cuda.empty_cache()# 生成视频video = pipe(num_inference_steps=10,  # 减少推理步骤guidance_scale=4,  # 降低指导比例prompt_embeds=prompt_embeds,).frames[0]#使用较少的推理步骤和较低的指导比例来减少显存使用。export_to_video(video, "output.mp4", fps=8)

运行test.py

#python test.py

模型对比

模型名

CogVideoX-2B (本仓库)

CogVideoX-5B

CogVideoX-5B-I2V

模型介绍

入门级模型,兼顾兼容性。运行,二次开发成本低。

视频生成质量更高,视觉效果更好的更大尺寸模型。

CogVideoX-5B 图生视频版本。

推理精度

FP16*(推荐), BF16, FP32,FP8*,INT8,不支持INT4

BF16(推荐), FP16, FP32,FP8*,INT8,不支持INT4

单GPU显存消耗

SAT FP16: 18GB
diffusers FP16: 4GB起*
diffusers INT8(torchao): 3.6G起*

SAT BF16: 26GB
diffusers BF16 : 5GB起*
diffusers INT8(torchao): 4.4G起*

多GPU推理显存消耗

FP16: 10GB* using diffusers

BF16: 15GB* using diffusers

推理速度
(Step = 50, FP/BF16)

单卡A100: ~90秒
单卡H100: ~45秒

单卡A100: ~180秒
单卡H100: ~90秒

微调精度

FP16

BF16

微调显存消耗

47 GB (bs=1, LORA)
61 GB (bs=2, LORA)
62GB (bs=1, SFT)

63 GB (bs=1, LORA)
80 GB (bs=2, LORA)
75GB (bs=1, SFT)

78 GB (bs=1, LORA)
75GB (bs=1, SFT, 16GPU)

提示词语言

English*

提示词长度上限

226 Tokens

视频长度

6 秒

帧率

8 帧 / 秒

视频分辨率

720 * 480,不支持其他分辨率(含微调)

位置编码

3d_sincos_pos_embed

3d_rope_pos_embed

3d_rope_pos_embed + learnable_pos_embed

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词