开源视频生成 Pyramid Flow 本地部署实测

前段时间,给微信 AI 小助理-小爱接入了文生视频的能力:

我把「国产Sora」接入了「小爱」,邀你免费体验

采用的是智谱开源的 CogVideo 模型,最近开源社区新出了一款视频生成模型 - pyramid-flow-sd3,社区反馈效果要优于 CogVideo。

今日分享,手把手带大家在本地部署,实测看看是否如宣传一般惊艳。

1. Pyramid Flow 简介

项目地址:https://github.com/jy0205/Pyramid-Flow

老规矩,先来简单介绍下~

Pyramid Flow 有哪些亮点?

  • 仅需 2B 参数,可生成768p分辨率、24fps的10秒视频;
  • 支持「文本到视频」 和 「图像到视频」 ;
  • 自回归生成,基于先前帧来预测生成后续帧,确保视频内容的连贯性和流畅性;
  • 金字塔式的多尺度架构,在不同分辨率的潜变量之间进行插值,因此生成效率更高:

官方评测结果:除了semantic score,其它指标均优于开源方案 CogVideo:

2. 在线体验

在线体验地址:https://huggingface.co/spaces/Pyramid-Flow/pyramid-flow

Pyramid Flow 已上线 huggingface,无需本地部署,即刻在线体验!

如无法访问,可参看官方的生成样例:https://pyramid-flow.github.io/

接下来,我们把模型在本地跑起来。

3. 本地部署

3.1 环境准备

首先准备 Pyramid Flow 环境:

git clone https://github.com/jy0205/Pyramid-Flow
cd Pyramid-Flow
conda create -n pyramid python==3.8.10
conda activate pyramid
pip install -r requirements.txt

然后,把模型下载到本地,方便调用:

export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download rain1011/pyramid-flow-sd3 --local-dir ckpts/

其中,模型权重包括 768p 和 384p 两种版本。384p版本支持 5 秒长的 24 FPS视频,而 768p 版本则可以生成 10 秒。

3.2 推理测试

首先,加载模型进来:

import os
import torch
from PIL import Image
from pyramid_dit import PyramidDiTForVideoGeneration
from diffusers.utils import export_to_video

os.environ['CUDA_VISIBLE_DEVICES'] = '2'

model = PyramidDiTForVideoGeneration('ckpts/', 'bf16', model_variant='diffusion_transformer_384p')

model.vae.enable_tiling()
# model.vae.to("cuda")
# model.dit.to("cuda")
# model.text_encoder.to("cuda")
# if you're not using sequential offloading bellow uncomment the lines above ^
model.enable_sequential_cpu_offload()

如果把模型都加载进 GPU,至少需要 19G 显存,否则建议采用上述代码!

然后,测试文本生成视频

def t2v():
    prompt = "A movie trailer featuring the adventures of the 30 year old space man wearing a red wool knitted motorcycle helmet, blue sky, salt desert, cinematic style, shot on 35mm film, vivid colors"
    with torch.no_grad(), torch.amp.autocast('cuda', dtype=torch.bfloat16):
        frames = model.generate(
            prompt=prompt,
            num_inference_steps=[20, 20, 20],
            video_num_inference_steps=[10, 10, 10],
            height=384,     
            width=640,
            temp=16,                    # temp=16: 5s, temp=31: 10s
            guidance_scale=9.0,         # The guidance for the first frame, set it to 7 for 384p variant
            video_guidance_scale=5.0,   # The guidance for the other video latent
            output_type="pil",
            save_memory=True,           # If you have enough GPU memory, set it to `False` to improve vae decoding speed
        )
    export_to_video(frames, "./text_to_video_sample.mp4", fps=24)

测试图片生成视频

def i2v():
    image = Image.open('assets/the_great_wall.jpg').convert("RGB").resize((640, 384))
    prompt = "FPV flying over the Great Wall"
    with torch.no_grad(), torch.amp.autocast('cuda', dtype=torch.bfloat16):
        frames = model.generate_i2v(
            prompt=prompt,
            input_image=image,
            num_inference_steps=[10, 10, 10],
            temp=16,
            video_guidance_scale=4.0,
            output_type="pil",
            save_memory=True,           # If you have enough GPU memory, set it to `False` to improve vae decoding speed
        )
    export_to_video(frames, "./image_to_video_sample.mp4", fps=24)

Pyramid Flow 对显存要求较高,否则生成 5 秒视频,至少 13 分钟:

100%|████| 16/16 [13:11<00:00, 49.45s/it]

生成效果咋样?

pyramid_flow_t2v

实测来看,并未和 CogVideo 拉开差距。。。

写在最后

本文带大家本地部署并实测了最新开源的视频生成模型 - Pyramid Flow

AI 应用大体可分为:文本、语音、图片、视频,其中语音已被硅基生物攻破。

而 AI 视频生成,从当前效果来看。。。依然任重道远!

如果对你有帮助,欢迎点赞收藏备用。


为方便大家交流,新建了一个 AI 交流群,欢迎感兴趣的小伙伴加入。

最近打造的微信机器人小爱(AI)也在群里,公众号后台「联系我」,拉你进群。

### 部署视频生成模型于LM Studio LM Studio是一个简化了本地AI模型部署流程的工具,使得用户无需复杂的技术背景即可快速启动并运行多种类型的大型语言模型[^1]。不过针对视频生成模型的具体部署,在官方文档和支持资源中并未直接提及此功能。 考虑到这一点,下面是一般性的指导建议: #### 准备工作 - **确认兼容性**:首先需验证目标视频生成模型是否能够被LM Studio所支持。这通常涉及到查阅该软件最新的更新日志或特性列表来获取支持的模型种类。 #### 获取模型 对于受支持的视频生成模型, ```python # 假设有一个函数用于下载特定名称的预训练模型到指定路径 download_model(model_name="video-generation-model", save_path="./models/") ``` 如果遇到无法通过内置接口下载的情况,则可参照解决方案采用替代源进行手动下载[^2]。 #### 加载与配置 一旦获得了所需的视频生成模型文件,下一步就是将其集成至LM Studio环境中。由于LM Studio主要面向文字类大语言模型设计,因此对于非标准的语言处理任务(如视频生成),可能需要额外编写适配层或是利用插件扩展其能力。 #### 测试与优化 完成上述步骤之后,应该能够在LM Studio内选择新加入的视频生成模型来进行交互测试。注意观察是否存在性能瓶颈,并据此调整参数设置以达到最佳效果。 尽管LM Studio极大地降低了本地化应用先进AI技术门槛,但对于某些特殊领域内的高级应用场景的支持程度有限。对于希望深入探索视频生成方向的研究者来说,或许还需要关注更多专门为此目的打造的专业级平台和服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值