MiniCPM: 展现端侧大语言模子的无穷潜力 github页面

[复制链接]
发表于 2026-1-29 23:41:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
MiniCPM: 展现端侧大语言模子的无穷潜力




中文 | English


MiniCPM 是面壁智能与清华大学自然语言处置处罚实行室共同开源的系列端侧大模子,主体语言模子 MiniCPM-2B 仅有 24亿(2.4B)的非词嵌入参数目, 总计2.7B参数目。


  • 颠末 SFT 后,MiniCPM-2B 在公开综合性评测集上与 Mistral-7B 体现相近(中文、数学、代码本领更优),团体性能逾越 Llama2-13B、MPT-30B、Falcon-40B 等模子。
  • 颠末 DPO 后,MiniCPM-2B 在当前最靠近用户体感的评测集 MTBench 上也逾越了 Llama2-70B-Chat、Vicuna-33B、Mistral-7B-Instruct-v0.1、Zephyr-7B-alpha 等浩繁代表性开源大模子。
  • 以 MiniCPM-2B 为底子构建端侧多模态大模子 MiniCPM-V 2.0,在多个测试基准中实现了 7B 以下模子的最佳性能,在 OpenCompass 榜单上凌驾了 Qwen-VL-Chat 9.6B、CogVLM-Chat 17.4B 和 Yi-VL 34B 等更大参数规模的模子。MiniCPM-V 2.0 还显现出领先的 OCR 本领,在场景笔墨辨认本领上靠近 Gemini Pro。
  • 颠末 Int4 量化后,MiniCPM 可在手机上举行摆设推理,流式输出速率略高于人类语言速率。MiniCPM-V 也直接跑通了多模态大模子在手机上的摆设。
  • 一张1080/2080可高效参数微调,一张3090/4090可全参数微调,一台呆板可一连练习 MiniCPM,二次开辟本钱较低。
我们完全开源MiniCPM系列的模子参数供学术研究和有限商用。 具体而言,我们现在已公开以下模子,地点详见 模子下载 部门


  • 基于MiniCPM-2B的指令微调与人类偏好对齐版本MiniCPM-2B-SFT/DPO。
  • 基于MiniCPM-2B的多模态模子MiniCPM-V 2.0。
  • MiniCPM-2B-SFT/DPO的Int4量化版MiniCPM-2B-SFT/DPO-Int4。
  • MiniCPM-2B的128k长文本版本MiniCPM-2B-128k。
  • MiniCPM-2B的MoE版本MiniCPM-MoE-8x2B。
  • 更轻量级的MiniCPM-1B指令微调版本MiniCPM-1B-SFT。
  • 基于MLC-LLM、LLMFarm开辟的MiniCPM手机端步调,文本及多模态模子均可在手机端举行推理。
  • MiniCPM-2B练习过程中的30个Checkpoints供模子机理研究。
范围性:




  • 受限于模子规模,模子大概出现幻觉性题目。此中由于DPO模子天生的复兴内容更长,更轻易出现幻觉。我们也将一连举行MiniCPM模子的迭代改进。
  • 为了包管在学术研究用途上模子的通用性,我们未对模子举行任何身份认同练习。同时由于我们用ShareGPT开源语料作为部门练习数据,模子大概会输出类似GPT系列模子的身份认同信息。
  • 受限于模子规模,模子的输出受到提示词(prompt)的影响较大,大概多次实验产生不同等的结果。
  • 受限于模子容量,模子的知识影象较禁绝确,后续我们将团结RAG方法来加强模子的知识影象本领。
目次




  • 更新日志日志|
  • 模子下载|
  • 快速上手|
  • 模子量化|
  • 开源社区|
  • 评测结果|
  • 手机摆设|
  • Demo & API 摆设|
  • 二次开辟|
  • 开源协议|
  • 工作引用|
  • 范例示例|
常用模块导航


推理微调手机摆设量化TransformersTransformersMLC摆设GPTQvLLMmlx_finetunellama.cppAWQllama.cppllama_factory狐疑度测试ollamafastllmmlx_lmpowerinfer
更新日志日志




  • 2024/04/11 开源MiniCPM-V-2.0、MiniCPM-2B-128k、MiniCPM-MoE-8x2B和MiniCPM-1B!点击这里检察技能博客。
  • 2024/03/16 MiniCPM-2B 的30余个中心查抄点开放了!HuggingFace链接
  • 2024/02/13 支持了llama.cpp
  • 2024/02/09 我们在README里参加了一个开源社区章节,用来网络开源社区对MiniCPM的支持案例。
  • 2024/02/08 我们更新了llama-format的模子权重,方便各人更加快捷地使用我们的模子。
  • 2024/02/01 初始发布。

模子下载




  • 语言模子
       HuggingFaceModelScopeWiseModelMiniCPM-2B-sft-bf16MiniCPM-2B-sft-bf16MiniCPM-2B-sft-bf16MiniCPM-2B-dpo-bf16MiniCPM-2B-dpo-bf16MiniCPM-2B-dpo-bf16MiniCPM-2B-128kMiniCPM-2B-128kMiniCPM-MoE-8x2BMiniCPM-MoE-8x2BMiniCPM-1B-sft-bf16MiniCPM-1B-sft-bf16注: 更多模子版本见这里。
  • 多模态模子
       HuggingFaceModelScopeWiseModelMiniCPM-V 2.0MiniCPM-V 2.0MiniCPM-VMiniCPM-VMiniCPM-VOmniLMM-12BOmniLMM-12BOmniLMM-12B

快速上手


在线体验




  • Colab

Huggingface 模子


MiniCPM-2B




  • 安装transformers>=4.36.0以及accelerate后,运行以下代码
  1. from transformers import AutoModelForCausalLM, AutoTokenizer
  2. import torch
  3. torch.manual_seed(0)
  4. path = 'openbmb/MiniCPM-2B-dpo-bf16'
  5. tokenizer = AutoTokenizer.from_pretrained(path)
  6. model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map='cuda', trust_remote_code=True)
  7. responds, history = model.chat(tokenizer, "山东省最高的山是哪座山, 它比黄山高还是矮?差距多少?", temperature=0.5, top_p=0.8, repetition_penalty=1.02)
  8. print(responds)
复制代码


  • 盼望输出
  1. 山东省最高的山是泰山,海拔1545米。
  2. 相对于黄山(海拔1864米),泰山海拔较低,相差约319米。
复制代码

MiniCPM-2B (Llama Format)


我们将MiniCPM的模子权重转化成了Llama代码可以直接调用的格式,以便各人实验:
  1. import torch
  2. from transformers import LlamaTokenizerFast, LlamaForCausalLM
  3. model_path = "openbmb/MiniCPM-2B-dpo-bf16-llama-format"
  4. tokenizer = LlamaTokenizerFast.from_pretrained(model_path)
  5. model = LlamaForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map='cuda', trust_remote_code=True)
  6. prompt="Now you act like a terminal situated within a beginner's C++ practice repository folder, please provide the output for the command: `ls -l`"
  7. input_ids = tokenizer.encode("<用户>{}<AI>".format(prompt), return_tensors='pt', add_special_tokens=True).cuda()
  8. responds = model.generate(input_ids, temperature=0.3, top_p=0.8, repetition_penalty=1.02, max_length=1024)
  9. responds = tokenizer.decode(responds[0], skip_special_tokens=True)
  10. print(responds)
复制代码
MiniCPM-V


  1. import torch
  2. from PIL import Image
  3. from transformers import AutoModel, AutoTokenizer
  4. model = AutoModel.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True)
  5. tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V', trust_remote_code=True)
  6. model.eval().cuda()
  7. image = Image.open('xx.jpg').convert('RGB')
  8. question = 'What is in the image?'
  9. msgs = [{'role': 'user', 'content': question}]
  10. res, context, _ = model.chat(
  11.     image=image,
  12.     msgs=msgs,
  13.     context=None,
  14.     tokenizer=tokenizer,
  15.     sampling=True,
  16.     temperature=0.7
  17. )
  18. print(res)
复制代码
vLLM 推理




  • 安装vLLM
  1. pip install "vllm>=0.4.1"
复制代码


  • 测试样例
  1. python inference/inference_vllm.py --model_path <hf_repo_path> --prompt_path prompts/prompt_demo.txt
复制代码


  • 盼望输出
  1. <用户>: Which city is the capital of China?
  2. <AI>:
  3. The capital city of China is Beijing. Beijing is a major political, cultural, and economic center in China, and it is known for its rich history, beautiful architecture, and vibrant nightlife. It is also home to many of China's most important cultural and historical sites, including the Forbidden City, the Great Wall of China, and the Temple of Heaven. Beijing is a popular destination for tourists from around the world, and it is an important hub for international business and trade.
复制代码
llama.cpp、Ollama、fastllm、mlx_lm推理


MiniCPM支持llama.cpp 、ollama、fastllm、mlx_lm推理。感谢@runfuture对llama.cpp和ollama的适配。

llama.cpp



  • 安装llama.cpp
  • 下载gguf情势的模子。下载链接-fp16格式 下载链接-q4km格式
  • 在下令行运行示例代码:
  1. ./main -m ../../model_ckpts/download_from_hf/MiniCPM-2B-dpo-fp16-gguf.gguf --prompt "<用户>写藏头诗,藏头是龙年大吉<AI>" --temp 0.3 --top-p 0.8 --repeat-penalty 1.05
复制代码
更多参数调解详见

ollama


ollama自动安装模子

  • 安装ollama
  • 在下令行运行:
  1. ollama run modelbest/minicpm-2b-dpo
复制代码
ollama手动安装模子

  • 安装ollama
  • 下载gguf情势的模子。下载链接2b-fp16格式 下载链接2b-q4km格式 下载链接1b-fp16格式 下载链接1b-qr_1格式
  • 在下令行运行以下下令,model_name可自界说:
  1. touch model_name.Modelfile
复制代码

  • 将以上model_name.Modelfile的内容修改如下,FROM空格后写入gguf的模子路径
  1. FROM model_path/model_name.gguf
  2. TEMPLATE """<s><USER>{{ .Prompt }}<AI>{{ .Response }}"""
  3. PARAMETER stop "<\s>"
复制代码

  • 在下令行运行以下下令,创建ollama模子,ollama_model_name可自界说,model_name.Modelfile参考第3步定名
  1. ollama create ollama_model_name -f model_name.Modelfile
复制代码

  • 运行ollama模子:
  1. ollama run ollama_model_name
复制代码

fastllm



  • 编译安装fastllm
  • 模子推理
  1. import torch
  2. from transformers import AutoTokenizer, LlamaTokenizerFast, AutoModelForCausalLM
  3. path = 'openbmb/MiniCPM-2B-dpo-fp16'
  4. tokenizer = AutoTokenizer.from_pretrained(path)
  5. model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.float16, device_map='cuda', trust_remote_code=True)
  6. from fastllm_pytools import llm
  7. llm.set_device_map("cpu")
  8. model = llm.from_hf(model, tokenizer, dtype = "float16") # dtype支持 "float16", "int8", "int4"
  9. print(model.response("<用户>山东省最高的山是哪座山, 它比黄山高还是矮?差距多少?<AI>", top_p=0.8, temperature=0.5, repeat_penalty=1.02))
复制代码

mlx_lm



  • 安装mlx_lm库
    1. pip install mlx_lm
    复制代码
  • 下载转换后的模子权重MiniCPM-2B-sft-bf16-llama-format-mlx
  • 模子推理
    1. python -m mlx_lm.generate --model mlx-community/MiniCPM-2B-sft-bf16-llama-format-mlx --prompt "hello, tell me a joke." --trust-remote-code
    复制代码

powerinfer


powerinfer现在仅针对MiniCPM-S-1B模子,其他版本暂不支持,敬请等待。

  • 包管cmake版本3.17以上,假如已经安装过,则跳过此步调
  1.   # 下载安装包
  2.   sudo wget https://cmake.org/files/v3.23/cmake-3.23.0.tar.gz
  3.   # 解压安装包
  4.   sudo tar -zxvf cmake-3.23.0.tar.gz
  5.   # 配置安装环境
  6.   sudo ./configure
  7.   sudo make -j8
  8.   # 编译安装
  9.   sudo make install
  10.   # 查看安装后版本
  11.   cmake --version
  12.   # 返回版本号则安装成功
  13.   #cmake version 3.23.0
复制代码

  • 安装powerinfer:
  1.   git clone https://github.com/SJTU-IPADS/PowerInfer
  2.   cd PowerInfer
  3.   pip install -r requirements.txt # install Python helpers' dependencies
复制代码

  • cpu版本powerinfer编译,假如你的呆板只有cpu,大概只想使用cpu举行推理,则运行以下下令:
  1.   cmake -S . -B build
  2.   cmake --build build --config Release
复制代码

  • gpu版本powerinfer编译,假如你的呆板有gpu,则可以运行以下下令:
  1.   cmake -S . -B build -DLLAMA_CUBLAS=ON
  2.   cmake --build build --config Release
复制代码

  • 获取希奇模子
  1. git clone https://huggingface.co/openbmb/MiniCPM-S-1B-sft-gguf/tree/main
  2. #or
  3. git clone https://modelscope.cn/models/OpenBMB/MiniCPM-S-1B-sft-gguf
复制代码

  • 模子推理:
  1. cd PowerInfer
  2. # 以下是命令模版,output_token_count为最大输出tokens,thread_num 为线程数,prompt为输入prompt字符
  3. #./build/bin/main -m /PATH/TO/MODEL -n $output_token_count -t $thread_num -p $prompt
  4. # 以下是示例
  5. ./build/bin/main -m /root/ld/ld_model_pretrain/1b-s-minicpm/MiniCPM-S-1B-sft.gguf -n 2048 -t 8 -p '<用户>hello,tell me a story please.<AI>'
复制代码

模子量化



gptq量化

  • 起首git获取minicpm_gptqd代码
  • 进入minicpm_gptqd主目次./AutoGPTQ,下令行输入:
    1. pip install e .
    复制代码
  • 前往模子下载下载未量化的MiniCPM堆栈下全部文件放至本地同一文件夹下,1b、2b模子均可,练习后模子亦可。
  • 下令行输入以下下令,此中no_quantized_model_path是第3步模子下载路径,save_path是量化模子生存路径,--bits 为量化位数可以选择输入4大概8
    1. cd Minicpm/quantize
    2. python gptq_quantize.py --pretrained_model_dir no_quant_model_path --quantized_model_dir quant_save_path --bits 4
    复制代码
  • 可以使用./AutoGPTQ/examples/quantization/inference.py举行推理,也可以参考前文使用vllm对量化后的模子,单卡4090下minicpm-1b-int4模子vllm推理在2000token/s左右。

awq量化

  • 在quantize/awq_quantize.py 文件中修改根据解释修改设置参数:
  1. model_path = '/root/ld/ld_model_pretrained/MiniCPM-1B-sft-bf16' # model_path or model_id
  2. quant_path = '/root/ld/ld_project/pull_request/MiniCPM/quantize/awq_cpm_1b_4bit' # quant_save_path
  3. quant_data_path='/root/ld/ld_project/pull_request/MiniCPM/quantize/quantize_data/wikitext'# 写入自带量化数据集,data下的alpaca或者wikitext
  4. quant_config = { "zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM" } # "w_bit":4 or 8
  5. quant_samples=512 # how many samples to use for calibration
  6. custom_data=[{'question':'你叫什么名字。','answer':'我是openmbmb开源的小钢炮minicpm。'}, # 自定义数据集可用
  7.                {'question':'你有什么特色。','answer':'我很小,但是我很强。'}]
复制代码

  • 在quantize/quantize_data文件下已经提供了alpaca和wiki_text两个数据集作为量化校准集,修改上述quant_data_path为此中一个文件夹的路径
  • 假如必要自界说数据集,修改quantize/awq_quantize.py中的custom_data变量,如:
    1. custom_data=[{'question':'过敏性鼻炎有什么症状?','answer':'过敏性鼻炎可能鼻塞,流鼻涕,头痛等症状反复发作,严重时建议及时就医。'},
    2.              {'question':'1+1等于多少?','answer':'等于2'}]
    复制代码
  • 根据选择的数据集,选择以下某一行代码更换 quantize/awq_quantize.py 中第三十八行:
  1.   #使用wikitext进行量化
  2.   model.quantize(tokenizer, quant_config=quant_config, calib_data=load_wikitext(quant_data_path=quant_data_path))
  3.   #使用alpaca进行量化
  4.   model.quantize(tokenizer, quant_config=quant_config, calib_data=load_alpaca(quant_data_path=quant_data_path))
  5.   #使用自定义数据集进行量化
  6.   model.quantize(tokenizer, quant_config=quant_config, calib_data=load_cust_data(quant_data_path=quant_data_path))
  7.   
复制代码

  • 运行quantize/awq_quantize.py文件,在设置的quan_path目次下可得awq量化后的模子。

量化测试

  • 下令行进入到 MiniCPM/quantize 目次下
  • 修改quantize_eval.sh文件中awq_path,gptq_path,awq_path,假如不必要测试的范例保持为空字符串,如下示例体现仅测试awq模子:
  1.   awq_path="/root/ld/ld_project/AutoAWQ/examples/awq_cpm_1b_4bit"
  2.   gptq_path=""
  3.   model_path=""
复制代码

  • 在MiniCPM/quantize路径下下令行输入:
  1.   bash quantize_eval.sh
复制代码

  • 窗口将输出该模子的内存占用情况、狐疑度。

开源社区




  • ChatLLM框架:在CPU上跑MiniCPM

评测结果


评测设置




  • 由于大模子评测难以同一,且大量评测也没有公开的prompt和测试代码,对于具体评测方式,我们只能只管做到得当各类模子。
  • 团体而言,我们测试时接纳同一的prompt输入,并按照各模子对应的模板举行输入调解。
  • 评测脚本及prompt已开源在我们的Github堆栈中,也接待更多开辟者来不停改进我们的评测方式。

    • 文本评测部门,接纳了我们的开源大模子本领评测框架UltraEval。以下为开源模子复现流程:

      • 安装UltraEval
        1. git clone https://github.com/OpenBMB/UltraEval.git
        2. cd UltraEval
        3. pip install -e .
        复制代码
      • 下载干系数据并解压处置处罚
        1. wget -O RawData.zip "https://cloud.tsinghua.edu.cn/f/71b5232264ae4833a4d0/?dl=1"
        2. unzip RawData.zip
        3. python data_process.py
        复制代码
      • 实行评测脚本(提供了模板,可自界说)
        1. bash run_eval.sh
        复制代码


摆设模式




  • 由于MiniCPM接纳Mup的结构,与现有模子在具体盘算上有渺小差异,我们是基于vllm=0.2.2版本举行了我们模子的实现。
  • 对于非MiniCPM模子,我们接纳了vllm=0.2.7的最新版本举行推理。
评测度量




  • 对于QA使命(选择题使命),我们选用两种方式举行测试:

    • PPL:将选项作为标题天生的一连,并根据各个选项的PPL来举行答案选择;
    • 第二种是直接天生答案选项。

  • 对于差别模子,这两种方式得到的结果差异较大。MiniCPM两种模式上的结果较为靠近,而Mistral-7B-v0.1等模子在PPL上体现较好,直接天生上结果较差。
  • 在具体评测时,我们以两种评测方式得分的最高者为终极结果,以此包管对比的公平性(以下表格中*号体现接纳PPL)。
文本模子评测


越级比力:
模子均匀分英文均分中文均分C-EvalCMMLUMMLUHumanEvalMBPPGSM8KMATHBBHARC-EARC-CHellaSwagLlama2-7B35.4036.2131.76532.4231.1144.3212.227.1713.571.833.2375.2542.7575.62*Qwen-7B49.4647.1959.65558.9660.3557.6517.0742.1541.245.3437.7583.4264.7675.32*Deepseek-7B39.9639.1543.6442.8244.4547.8220.1241.4515.851.5333.3874.58*42.15*75.45*Mistral-7B48.9749.9644.5446.1242.9662.6927.4445.233.135.041.0683.9270.7380.43*Llama2-13B41.4842.4437.1937.3237.0654.7117.0732.5521.152.2537.9278.87*58.1979.23*MPT-30B38.1739.8230.7229.3432.0946.5621.9535.3610.311.5638.2278.66*46.08*79.72*Falcon-40B43.6244.2140.9340.2941.5753.5324.3936.5322.441.9236.2481.94*57.6883.26*MiniCPM-2B52.3352.651.151.1351.0753.4650.0047.3153.8310.2436.8785.4468.0068.25同级比力:
模子均匀分英文均分中文均分C-EvalCMMLUMMLUHumanEvalMBPPGSM8KMATHBBHARC-EARC-CHellaSwagTinyLlama-1.1B25.3625.5524.52525.0224.0324.36.7119.912.270.7428.7860.77*28.15*58.33*Qwen-1.8B34.7231.8747.5749.8145.3243.377.9317.8019.262.4229.0763.97*43.6959.28*Gemini Nano-3B-------27.2(report)22.8(report)-42.4(report)---StableLM-Zephyr-3B43.4646.3130.6230.3430.8945.935.3731.8552.5412.4937.6873.7855.3871.87*Phi-2-2B48.8454.4123.7823.3724.1852.6647.5655.0457.163.543.3986.1171.2573.07*MiniCPM-2B52.3352.651.1051.1351.0753.4650.0047.3153.8310.2436.8785.4468.0068.25Chat模子比力:
模子均匀分英文均分中文均分C-EvalCMMLUMMLUHumanEvalMBPPGSM8KMATHBBHARC-EARC-CHellaSwagChatGLM2-6B37.9835.1750.6352.0549.2145.7710.379.3822.745.9632.674.4556.8258.48*Mistral-7B-Instruct-v0.144.3645.8937.5138.0636.9653.5629.2739.3428.733.4839.5281.6163.9973.47*Mistral-7B-Instruct-v0.250.9152.8342.23542.5541.9260.5136.5948.9540.494.9539.8186.2873.3884.55*Qwen-7B-Chat44.9342.0557.958.5757.2356.0315.8540.5242.238.337.3464.44*39.25*74.52*Yi-6B-Chat50.4645.8970.99570.8871.1162.9514.0228.3436.543.8837.4384.8970.3974.6*Baichuan2-7B-Chat44.6842.7453.3953.2853.55321.3432.3225.256.3237.4679.6360.1569.23*Deepseek-7B-chat49.3449.5648.33546.9549.7251.6740.8548.4848.524.2635.776.8563.0576.68*Llama2-7B-Chat38.1639.1733.5934.5432.6447.6414.0227.421.152.0835.5474.2854.7875.65*MiniCPM-2B52.3352.651.1051.1351.0753.4650.0047.3153.8310.2436.8785.4468.0068.25DPO后模子比力:
模子MT-benchGPT-4-turbo9.32GPT-3.5-turbo8.39Mistral-8*7b-Instruct-v0.18.30Claude-2.18.18Zephyr-7B-beta7.34MiniCPM-2B7.25Vicuna-33B7.12Zephyr-7B-alpha6.88LLaMA-2-70B-chat6.86Mistral-7B-Instruct-v0.16.84MPT-34B-instruct6.39MiniCPM-2B-128k 模子评测


Modelavgavg w/o code&mathpasskeynumber_stringkv_retrievallongbook_choice_englongbook_qa_chnlongbook_qa_englongbook_sum_englongdialogue_qa_engmath_calcmath_findcode_debugcode_runLWM-Text-128k24.4533.6210097.80.628.8215.9314.319.991.503.4320.051Yarn-Mistral-7b-128k19.8427.3692.71027.9515.499.559.067.5017.140.761.25Mistral-7B-Instruct-v0.2(ABF 1000w)27.7536.910078.983.637.1211.7417.3721.129.5029.4317.510Yi-6B-200k22.1532.5410094.92036.6815.079.20.923.504.290.510.75chatglm3-6b-128k25.5836.5789.9399.665.246.2910.78.3825.916.5085.331MiniCPM-2.4B-128k27.3237.6898.3199.83929.6923.0616.3315.739.504.2922.080MiniCPM-MoE-8x2B模子评测


ModelBBHMMLUCEvalCMMLUHumanEvalMBPP†GSM8KMATHLlama2-34B*44.162.6--22.633.042.26.24Mistral-7B-Instruct-v0.239.8160.5142.5541.9236.5939.6340.494.95Gemma-7B*55.164.3--32.344.446.424.3Qwen1.5-7B*40.26174.173.13637.462.520.3Deepseek-MoE(16B)*-45.040.642.526.839.218.84.3MiniCPM-2.4B36.8753.4651.1351.0750.0035.9353.8310.24MiniCPM-MoE-8x2B39.2258.9058.1158.8055.4941.6861.5610.52
注:* 体现结果取自技能陈诉。† 体现评测集为MBPP全集。
多模态模子评测


ModelSizeTextVQA valDocVQA testOCRBenchOpenCompassMMEMMB dev(en)MMB dev(zh)MMMU valMathVistaLLaVA BenchObject HalBenchProprietary modelsGemini Pro Vision-74.688.168063.82148.975.274.048.945.879.9-GPT-4V-78.088.464563.21771.575.175.053.847.893.186.4 / 92.7Open-source models 6B~34BYi-VL-6B6.7B45.5*17.1*29049.31915.168.668.340.328.851.9-Qwen-VL-Chat9.6B61.562.648852.11860.060.656.737.033.867.756.2 / 80.0Yi-VL-34B34B43.4*16.9*29052.62050.271.171.445.130.762.3-DeepSeek-VL-7B7.3B64.7*47.0*43555.61765.474.172.838.336.877.8-TextMonkey9.7B64.366.7558--------CogVLM-Chat17.4B70.433.3*59052.51736.663.753.837.334.773.973.6 / 87.4Open-source models 1B~3BDeepSeek-VL-1.3B1.7B58.4*37.9*41346.01531.664.061.233.829.451.1-MobileVLM V23.1B57.519.4*--1440.5(P)63.2-----Mini-Gemini2.2B56.234.2*--1653.059.8-31.7---MiniCPM-V2.8B60.638.236647.61650.267.965.338.328.951.378.4 / 88.5MiniCPM-V 2.02.8B74.171.960555.01808.669.668.138.238.769.285.5 / 92.2* 我们自己评测了正式开源的模子权重。

手机摆设



摆设步调




  • 举行Int4量化后,MiniCPM只占2GB空间,具备在端侧手机举行模子摆设的条件。
  • 对于差别的操纵体系,我们举行了差别的适配。
  • 注意:当前开源框架对手机支持还在美满,并非全部芯片与操纵体系版本均能乐成运行MLC-LLM或LLMFarm。
  • Android、HarmonyOS

    • 使用开源框架MLC-LLM举行模子适配。
    • 支持文本模子、多模态模子。
    • 实用于MiniCPM-2B-SFT-INT4、MiniCPM-2B-DPO-INT4、MiniCPM-V。
    • 编译安装MiniCPM指南

  • iOS

    • 使用开源框架LLMFarm举行模子适配。
    • 支持文本模子。
    • 实用于MiniCPM-2B-SFT-INT4、MiniCPM-2B-DPO-INT4。
    • 编译安装MiniCPM指南

摆设性能




  • 我们未针对手机推理模子举行深度优化和体系测试,仅验证MiniCPM使用手机芯片举行推理的可行性。我们也接待更多开辟者进一步调优并更新下面的测试列表,不停提拔端侧大模子在手机上的推理性能。
手机型号操纵体系处置处罚器Memory(GB)文本吞吐(token/s)OPPO Find N3Android 13snapdragon 8 Gen2126.5Samsung S23 UltraAndroid 14snapdragon 8 Gen2126.4Meizu M182QAndroid 11snapdragon 888Plus83.7Xiaomi 12 ProAndroid 13snapdragon 8 Gen18+33.7Xiaomi Redmi K40Android 11snapdragon 87083.5Oneplus LE 2100Android 13snapdragon 870123.5Oneplus HD1900Android 11snapdragon 86583.2Oneplus HD1900Android 11snapdragon 85583.0Oneplus HD1905Android 10snapdragon 85583.0Oneplus HD1900Android 11snapdragon 85583.0Xiaomi MI 8Android 9snapdragon 84562.3Huawei Nova 11SEHarmonyOS 4.0.0snapdragon 778121.9Xiaomi MIX 2Android 9snapdragon 83561.3iPhone 15 ProiOS 17.2.1A17 pro818.0iPhone 15iOS 17.2.1A16615.0iPhone 12 ProiOS 16.5.1A1465.8iPhone 12iOS 17.2.1A1445.8iPhone 11iOS 16.6A1344.6Xiaomi Redmi K50HyperOS 1.0.2MediaTek Dimensity 8100123.5

  • 我们也使用MLC-LLM验证了在手机上摆设MiniCPM-V系列模子的可行性,可以或许正常输入输出,但也存在图片处置处罚时间较长的题目,必要进一步优化,兼容性题目也必要进一步办理。下面的动图是使用小米14 Pro运行MiniCPM-V 2.0的屏幕录像,没有举行任何编辑。




Demo & API 摆设


基于Gradio的网页版Demo




  • 使用如下下令启动基于Gradio的网页版demo:
  1. # generation powered by vllm
  2. python demo/vllm_based_demo.py --model_path <vllmcpm_repo_path>
  3. # generation powered by huggingface
  4. python demo/hf_based_demo.py --model_path <hf_repo_path>
复制代码

二次开辟





  • 高效参数微调

    • 一张1080/2080可实现高效参数微调
    • 高效参数微调代码




  • 全参数微调 or 一连练习

    • 使用BMTrain,借助重盘算和ZeRO-3,一张3090/4090可实现全参数微调,一台呆板可实现一连练习
    • 干系代码也将一连推出




  • mlx高效参数微调

    • 情况预备
      1. pip install -r finetune/requirements_mlx.txt
      复制代码
    • 微调下令
      1. # train
      2. python mlx_finetune.py --model MiniCPM-2B-sft-bf16-llama-format-mlx  --data data/AdvertiseGen  --train  --seed 2024 --iters 500
      3. # test
      4. python mlx_finetune.py --model MiniCPM-2B-sft-bf16-llama-format-mlx  --data data/AdvertiseGen  --test --seed 2024
      复制代码

  • llama_factory微调

范例示例


文本天生





代码天生




数理逻辑




文本翻译




指令跟随




特别字符





开源协议


模子协议




  • 本堆栈中代码依照 Apache-2.0 协议开源
  • MiniCPM 模子权重的使用则必要遵照 “MiniCPM模子商用允许协议.md”。
  • MiniCPM 模子权重对学术研究完全开放,在填写“问卷”举行登记后亦允许免费商业使用。
声明




  • 作为一个语言模子,MiniCPM 通过学习大量的文原来天生内容,但它无法明白、表达个人观点或代价判定,它所输出的任何内容都不代表模子开辟者的观点和态度。
  • 因此用户在使用 MiniCPM 天生的内容时,应自行负责对其举行评估和验证。
  • 假如由于使用 MiniCPM 开源模子而导致的任何题目,包罗但不限于数据安全题目、公共舆论风险,或模子被误导、滥用、传播或不当使用所带来的任何风险和题目,我们将不负担当何责任。

工作引用




  • 假如以为MiniCPM有助于您的工作,请引用我们的论文
  1. @article{hu2024minicpm,
  2.   title={MiniCPM: Unveiling the Potential of Small Language Models with Scalable Training Strategies},
  3.   author={Hu, Shengding and Tu, Yuge and Han, Xu and He, Chaoqun and Cui, Ganqu and Long, Xiang and Zheng, Zhi and Fang, Yewei and Huang, Yuxiang and Zhao, Weilin and others},
  4.   journal={arXiv preprint arXiv:2404.06395},
  5.   year={2024}
  6. }
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表