在MLU370运行CogVideoX-2b轻轻松松!


一、paas平台环境配置

驱动版本选择:大于或等于5.10.29
显卡选择:MLU370系列
卡数:1-8卡【推荐2卡起步】
镜像选择:pytorch:v24.06-torch2.1.0-catch1.21.0-ubuntu22.04-py310
在这里插入图片描述

二、模型下载

依然是我们的老朋友魔搭社区

apt install git-lfs -y
git-lfs clone https://www.modelscope.cn/ZhipuAI/CogVideoX-2b.git

三、环境下载

1.pip 正常安装

pip install transformers==4.44.0 accelerate==0.31.0  opencv-python sentencepiece
#如果你的环境有自带apex的话,请卸载它
pip uninstall apex

2.diffusers安装

请私聊

四、代码准备

import torch
import torch_mlu
from diffusers import CogVideoXPipeline
from torch_mlu.utils.model_transfer import transfer
from diffusers.utils import export_to_video

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(
    "/workspace/volume/guojunceshi2/CogVideoX-2b",
    torch_dtype=torch.float16
)

pipe.enable_model_cpu_offload()

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,
)

video = pipe(
    num_inference_steps=50,
    guidance_scale=6,
    prompt_embeds=prompt_embeds,
).frames[0]

export_to_video(video, "output.mp4", fps=8)

五、运行效果演示

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值