当前位置: 首页 > web >正文

vlm MiniCPM 学习部署实战

目录

开源地址:

模型repo下载:

单图片demo:

多图推理demo:

论文学习笔记:

部署完整教程:

微调教程:

部署,微调教程,视频实测

BitCPM4 技术报告

创意:把量化塞进训练 


开源地址:

https://github.com/OpenBMB/MiniCPM

openbmb/MiniCPM4-8B-Eagle-vLLM

模型 2.29G

模型repo下载:

modelscope download --model=OpenBMB/MiniCPM-V-2_6 --local_dir ./MiniCPM-V-2_6  

单文件GGUF下载:

modelscope download --model=OpenBMB/MiniCPM-V-2_6-gguf --local_dir ./ ggml-model-Q4_K_M.gguf

单图片demo:

自动下载模型:

C:\Users\xxx\.cache\modelscope\hub\models\OpenBMB\MiniCPM-V-2_6

需要显存20G,模型文件15G

# test.py
import torch
from PIL import Image
from modelscope import AutoModel, AutoTokenizermodel = AutoModel.from_pretrained('OpenBMB/MiniCPM-V-2_6', trust_remote_code=True,attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('OpenBMB/MiniCPM-V-2_6', trust_remote_code=True)image = Image.open(r"B:\360MoveData\Users\Administrator\Pictures\liuying\IMG_20150903_123711.jpg").convert('RGB')
question = 'What is in the image?'
msgs = [{'role': 'user', 'content': [image, question]}]res = model.chat(image=None,msgs=msgs,tokenizer=tokenizer
)
print(res)## if you want to use streaming, please make sure sampling=True and stream=True
## the model.chat will return a generator
res = model.chat(image=None,msgs=msgs,tokenizer=tokenizer,sampling=True,stream=True
)generated_text = ""
for new_text in res:generated_text += new_textprint(new_text, flush=True, end='')

多图推理demo:

import torch  
from PIL import Image  
from modelscope import AutoModel, AutoTokenizer  model = AutoModel.from_pretrained('OpenBMB/MiniCPM-V-2_6', trust_remote_code=True,  attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager  
model = model.eval().cuda()  
tokenizer = AutoTokenizer.from_pretrained('OpenBMB/MiniCPM-V-2_6', trust_remote_code=True)  image1 = Image.open('image1.jpg').convert('RGB')  
image2 = Image.open('image2.jpg').convert('RGB')  
question = 'Compare image 1 and image 2, tell me about the differences between image 1 and image 2.'  msgs = [{'role': 'user', 'content': [image1, image2, question]}]  answer = model.chat(  image=None,  msgs=msgs,  tokenizer=tokenizer  
)  
print(answer)  

视频理解

import torch  
from PIL import Image  
from modelscope import AutoModel, AutoTokenizer  
from decord import VideoReader, cpu    # pip install decord  params={}  model = AutoModel.from_pretrained('OpenBMB/MiniCPM-V-2_6', trust_remote_code=True,  attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager  
model = model.eval().cuda()  
tokenizer = AutoTokenizer.from_pretrained('OpenBMB/MiniCPM-V-2_6', trust_remote_code=True)  MAX_NUM_FRAMES=64  def encode_video(video_path):  def uniform_sample(l, n):  gap = len(l) / n  idxs = [int(i * gap + gap / 2) for i in range(n)]  return [l[i] for i in idxs]  vr = VideoReader(video_path, ctx=cpu(0))  sample_fps = round(vr.get_avg_fps() / 1)  # FPS  frame_idx = [i for i in range(0, len(vr), sample_fps)]  if len(frame_idx) > MAX_NUM_FRAMES:  frame_idx = uniform_sample(frame_idx, MAX_NUM_FRAMES)  frames = vr.get_batch(frame_idx).asnumpy()  frames = [Image.fromarray(v.astype('uint8')) for v in frames]  print('num frames:', len(frames))  return frames  video_path="car.mp4"  
frames = encode_video(video_path)  
question = "Describe the video"  
msgs = [  {'role': 'user', 'content': frames + [question]},   
]  # Set decode params for video  
params["use_image_id"] = False  
params["max_slice_nums"] = 2 # 如果cuda OOM且视频分辨率大于448*448 可设为1  answer = model.chat(  image=None,  msgs=msgs,  tokenizer=tokenizer,  **params  
)  
print(answer)  

论文学习笔记:

MiniCPM,能被斯坦福抄袭究竟有何魅力?我们一起看看论文吧!-腾讯云开发者社区-腾讯云

部署完整教程:

MiniCPM-V 2.6:端侧最强多模态大模型探索【推理实战大全】_vllm minicpm-CSDN博客

微调教程:

MiniCPM-o-2.6 多模态大模型微调实战(完整代码)_minicpm-o 2.6-CSDN博客

部署,微调教程,视频实测

多图、视频首上端!面壁「小钢炮」 MiniCPM-V 2.6 模型重磅上新!魔搭推理、微调、部署实战教程modelscope-CSDN博客

BitCPM4 技术报告

而刚刚提到的43页技术报告,我看了一遍,觉得可以拆成以下:

InfLLM v2:Attention 层只看重点
FR-Spec:草稿阶段不全写
BitCPM4:训练时就考虑压缩
CPM.cu + ArkInfer:定制推理 & 部署系统
风洞 2.0:小模型先试,大模型再训

创意:把量化塞进训练 

MiniCPM 4.0 技术报告:端侧速度的奔涌,是模型的自我Rag | 人人都是产品经理

http://www.xdnf.cn/news/16289.html

相关文章:

  • 模型的存储、加载和部署
  • RCLAMP0512TQTCT 升特半导体 TVS二极管 12通道全防护芯片 以太网/PLC控制/5G基站专用
  • 微信通话自动录音器
  • 复矩阵与共轭转置矩阵乘积及其平方根矩阵
  • 基于xxl-job的分片实现分库分表后的扫表
  • MySQL深度理解-MySQL事务优化
  • 深度分析Java类加载机制
  • 智能小e-同步说明文档
  • 力扣189:轮转数组
  • 基于springboot的工商局商家管理系统
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘notebook’问题
  • 电子书转PDF格式教程,实现epub转PDF步骤
  • SGLang + 分布式推理部署DeepSeek671B满血版
  • Edwards爱德华泵软件 支持nEXT85和nXDS系列泵,包括nXRi, nRVi和nXLi增强型 nEXT nXDS nXLi
  • YOLO11有效涨点优化:注意力魔改 | 新颖的多尺度卷积注意力(MSCA),即插即用,助力小目标检测
  • 工具分享02 | Python批量文件重命名工具
  • 从零用java实现 小红书 springboot vue uniapp(14) 集成阿里云短信验证码
  • 核心数据结构:DataFrame
  • 征服 Linux 网络:核心服务与实战解析
  • 从指标定义到AI执行流:衡石SENSE 6.0的BI PaaS如何重构ISV分析链路
  • day46.通道注意力
  • jina-embedding-v4 环境搭建全过程
  • 实验-OSPF
  • 智能Agent场景实战指南 Day 20:Agent多模态交互能力
  • Windows 系统中 CURL 命令使用指南及常见错误解析
  • ai存在意义的对话
  • Unity UI的未来之路:从UGUI到UI Toolkit的架构演进与特性剖析(3)
  • UFS 描述符、标志和属性(二)
  • Java进阶3:Java集合框架、ArrayList、LinkedList、HashSet、HashMap和他们的迭代器
  • 外企本土化布局对国内连接器企业影响几何?