【GPT入门】第67课 多模态模型实践: 本地部署文生视频模型和图片推理模型

【GPT入门】第67课 多模态模型实践: 本地部署文生视频模型和图片推理模型

  • [1. 文生视频模型CogVideoX-5b 本地部署](#1. 文生视频模型CogVideoX-5b 本地部署)
    • [1.1 模型介绍](#1.1 模型介绍)
    • [1.2 环境安装](#1.2 环境安装)
    • [1.3 模型下载](#1.3 模型下载)
    • [1.4 测试](#1.4 测试)
  • [2.ollama部署图片推理模型 llama3.2-vision](#2.ollama部署图片推理模型 llama3.2-vision)
    • [2.1 模型介绍](#2.1 模型介绍)
    • [2.2 安装ollama](#2.2 安装ollama)
    • [2.3 下载模型](#2.3 下载模型)
    • [2.4 测试模型](#2.4 测试模型)
    • [2.5 测试](#2.5 测试)

1. 文生视频模型CogVideoX-5b 本地部署

https://www.modelscope.cn/models/ZhipuAI/CogVideoX-5b/summary

1.1 模型介绍

https://www.modelscope.cn/models/ZhipuAI/CogVideoX-5b/summary

1.2 环境安装

下载 安装conda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

conda create --prefix /root/autodl-tmp/xxzhenv/video python=3.10 -y

conda create --name video python=3.10

复制代码
 pip install --upgrade transformers accelerate diffusers imageio-ffmpeg 

1.3 模型下载

复制代码
modelscope download --model ZhipuAI/CogVideoX-5b   --local_dir /root/autodl-tmp/models_xxzh/ZhipuAI/CogVideoX-5b  

1.4 测试

复制代码
import torch
from modelscope import CogVideoXPipeline
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(
    "/root/autodl-tmp/models_xxzh/ZhipuAI/CogVideoX-5b",
    torch_dtype=torch.bfloat16
)

pipe.enable_sequential_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()

video = pipe(
    prompt=prompt,
    num_videos_per_prompt=1,
    num_inference_steps=50,
    num_frames=49,
    guidance_scale=6,
    generator=torch.Generator(device="cuda").manual_seed(42),
).frames[0]

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

2.ollama部署图片推理模型 llama3.2-vision

2.1 模型介绍

官网: https://ollama.com/library/llama3.2-vision

Llama 3.2-Vision 多模态大型语言模型(LLM)系列,是包含 110 亿参数和 900 亿参数两种规模的指令微调型图像推理生成模型集合,支持 "输入文本 + 图像 / 输出文本" 的交互模式。

经过指令微调的 Llama 3.2-Vision 模型,在视觉识别、图像推理、图像描述生成,以及回答与图像相关的通用问题等任务上进行了优化。在行业常用基准测试中,该系列模型的性能优于多款已有的开源及闭源多模态模型。

支持语言

  • 纯文本任务:官方支持英语、德语、法语、意大利语、葡萄牙语、印地语、西班牙语和泰语共 8 种语言。此外,Llama 3.2 的训练数据涵盖了比这 8 种官方支持语言更广泛的语种范围。
  • 图像 + 文本任务:需注意,目前仅支持英语。

2.2 安装ollama

curl -fsSL https://ollama.com/install.sh | sh

2.3 下载模型

复制代码
ollama pull llama3.2-vision

2.4 测试模型

conda create --prefix /root/autodl-tmp/xxzhenv/ollama python=3.10 -y

conda activate ollama

pip install ollama

2.5 测试

放一个图片

复制代码
import ollama

response = ollama.chat(
    model='llama3.2-vision',
    messages=[{
        'role': 'user',
        'content': 'What is in this image?',
        'images': ['image.jpeg']
    }]
)

print(response)

回复:

复制代码
(/root/autodl-tmp/xxzhenv/ollama) root@autodl-container-b197439d52-c6eeee38:~/autodl-tmp/xxzh# python test01.py 
model='llama3.2-vision' created_at='2025-09-12T07:40:47.282497498Z' done=True done_reason='stop' total_duration=9314004386 load_duration=6304258184 prompt_eval_count=16 prompt_eval_duration=1965372891 eval_count=74 eval_duration=1036467359 message=Message(role='assistant', content='The image is a painting of a starry night sky with a village below, featuring a large cypress tree and a bright crescent moon. The painting is called "The Starry Night" and was created by Vincent van Gogh in 1889. It is one of his most famous works and is widely considered a masterpiece of Post-Impressionism.', thinking=None, images=None, tool_name=None, tool_calls=None)
相关推荐
桂花饼19 小时前
GPT-5.1-Codex-Max:原生“记忆压缩”重塑编程范式,让 AI 连续写代码 24 小时不再是梦
人工智能·gpt·ai绘图·nano banana 2·图像生成api·openai兼容接口·gpt-5.1-codex
陈 洪 伟2 天前
Transformer彻底剖析(1):GPT中的Transformer架构
gpt·深度学习·transformer
zxcxylong2 天前
almalinux系统-数据盘扩容后文件系统扩容步骤
gpt·almalinux·parted·lvm·/dev/sdb
hay_lee3 天前
DeepSeek发布V3.2系列模型,性能媲美GPT-5与Gemini
gpt
生信大表哥4 天前
GPT-5-Codex VS Gemini 3 VS Claude Sonnet 4.5 新手小白入门学习教程
人工智能·gpt·学习·rstudio·数信院生信服务器
致Great6 天前
DeepSeek-V3.2技术报告解读:开源大模型的逆袭之战——如何用10%算力追平GPT-5
人工智能·gpt·开源·大模型·agent·智能体
黑客思维者6 天前
重塑信任与效率:Salesforce Einstein GPT 客服体系深度案例研究
人工智能·gpt·llm·客服系统·salesforce
*星星之火*7 天前
【大白话 AI 答疑】第2篇 GPT 全系列发展历程:从 GPT-1 到 GPT-5,每一代的关键突破都在这!
gpt
DO_Community7 天前
碾压GPT-5,Qwen3-VL开源多模态新标杆:99.5%长视频定位准确率
人工智能·gpt·开源·llm·音视频
聊天QQ:4877392787 天前
基于蛇鹫优化算法(SBOA)求解FJSP问题:柔性作业车间调度的MATLAB代码实现与优化研究
gpt