返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

将端侧大模型进行到底-MiniCPM3-4B开源

[复制链接]
链载Ai 显示全部楼层 发表于 前天 11:18 |阅读模式 打印 上一主题 下一主题

面壁一直都在做端侧大模型,之前有文本系列MiniCPM-2B模型,还有多模态系列的MiniCPM-V系列模型,今天又开源了MiniCPM3-4B模型,真是端侧一路走到低。

这次MiniCPM3-4B也是在效果上有了巨大的提升,超过Phi-3.5-mini-Instruct模型,肩比Llama3.1-8B-Instruct、GLM-4-9B-Chat、Qwen2-7B-Instruct等一众模型,堪称小模型之王。

之前的MiniCPM-2B模型报告也是干活满满,详见:https://shengdinghu.notion.site/MiniCPM-c805a17c5c8046398914e47f0542095a

这里说一下哈,MiniCPM-2B是1.0版本模型,MiniCPM-1B是2.0版本模型,现在是3.0版本4B。

模型改进

下面是3个版本的模型结构(1->2->3)的区别:

  • 位置编码:RoPE->RoPE->RoPE
  • 注意力机制:MHA->GQA->MLA,MLA也是DeepSeek-V2的核心创新
  • 词表大小:123K->73K->73K
  • 模型层数:40->52->62
  • 隐藏层节点:2304->1536->2560
  • 最大长度:4k->4K->32k
  • 系统提示词:不支持->不支持->支持
  • 工具调用和代码解释器:不支持->不支持->支持

同时,还发布了RAG套件MiniCPM-Embedding模型和MiniCPM-Reranker模型,针对 RAG场景还发布了微调版MiniCPM3-RAG-LoRA模型。

模型效果

MiniCPM3-4B模型在中文英文遵循、数据推理、代码能力、工具调用上表现均很不错的效果。

其中,工具调用能力尤为突出,在Berkeley Function Calling Leaderboard上优于Llama3.1-8B-Instruct、GLM-4-9B-Chat、Qwen2-7B-Instruct等更大模型。

长文档的大海捞针也是全绿。

模型快速使用

PS:模型下载有困难的同学,详见我之前写的一篇文章《大模型下载使我痛苦》。

fromtransformersimportAutoModelForCausalLM,AutoTokenizer
importtorch

#模型加载
path="openbmb/MiniCPM3-4B"

tokenizer=AutoTokenizer.from_pretrained(path,trust_remote_code=True)
model=AutoModelForCausalLM.from_pretrained(path,torch_dtype=torch.bfloat16,device_map="cuda",trust_remote_code=True)

#输入构造
messages=[
{"role":"user","content":"你知道刘聪NLP是谁吗?"},
]
model_inputs=tokenizer.apply_chat_template(messages,return_tensors="pt").to("cuda")

#模型生成
model_outputs=model.generate(
model_inputs,
max_new_tokens=1024,
top_p=0.8,
temperature=0.9,
repetition_penalty=1.1
)

#模型解码
output_token_ids=[
model_outputs[i][len(model_inputs[i]):]foriinrange(len(model_inputs))
]

responses=tokenizer.batch_decode(output_token_ids,skip_special_tokens=True)[0]
print(responses)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ