MiniCPM-V是面向图文理解的端侧多模态大模型系列。该系列模型接受图像和文本输入,并提供高质量的文本输出。MiniCPM-Llama3-V 2.5的多模态综合性能超越 GPT-4V-1106、Gemini Pro、Claude 3、Qwen-VL-Max 等商用闭源模型,OCR 能力及指令跟随能力进一步提升,并支持超过30种语言的多模态交互。
本仓已经支持以下模型任务类型
模型 | 任务列表 | 是否支持 |
---|---|---|
MiniCPM-V | 全参微调 | ✔ |
MiniCPM-V | Lora微调 | ✔ |
MiniCPM-V | 在线推理 | ✔ |
参考实现:
url=https://github.com/OpenBMB/MiniCPM-V.git
commit_id=6a5f9a4d6556e47767e7b653a9279281d2ef7062
适配昇腾AI处理器的实现:
url=https://gitee.com/ascend/ModelZoo-PyTorch.git
code_path=PyTorch/built-in/mm/MiniCPM-V
git clone 远程仓
git clone https://gitee.com/ascend/ModelZoo-PyTorch.git
cd PyTorch/built-in/mm/MiniCPM-V
创建Python环境并且安装Python三方包
conda create -n MiniCPM-V python=3.10 -y
conda activate MiniCPM-V
pip install -r requirements.txt
环境准备指导
请参考《Pytorch框架训练环境准备》。
表 1 昇腾软件版本支持表
软件类型 | 支持版本 |
---|---|
FrameworkPTAdapter | 在研版本 |
CANN | 在研版本 |
昇腾NPU固件 | 在研版本 |
昇腾NPU驱动 | 在研版本 |
TextVQA
├── TextVQA_0.5.1_train.json
├── TextVQA_0.5.1_val.json
└── train_images
联网情况下,预训练模型会自动下载。
无网络时,用户可访问huggingface官网自行下载,文件namespace如下:
openbmb/MiniCPM-Llama3-V-2_5
预训练模型文件下载后,需替换部分文件,使用下面命令时注意修改安装环境的路径。
cp huggingface_modify/configuration_minicpm.py openbmb/MiniCPM-Llama3-V-2_5/configuration_minicpm.py
cp huggingface_modify/modeling_minicpmv.py openbmb/MiniCPM-Llama3-V-2_5/modeling_minicpmv.py
cp huggingface_modify/resampler.py openbmb/MiniCPM-Llama3-V-2_5/resampler.py
Lora微调时,可参考下面修改transformers库源代码,实现部分重计算,加快训练速度。使用下面命令时注意修改环境路径。
vim /path/to/transformers/models/idefics2/modeling_idefics2.py
找到Idefics2Encoder,替换以下代码
for encoder_layer in self.layers:
if output_hidden_states:
encoder_states = encoder_states + (hidden_states,)
if self.gradient_checkpointing and self.training:
替换为
for idx, encoder_layer in enumerate(self.layers):
if output_hidden_states:
encoder_states = encoder_states + (hidden_states,)
if self.gradient_checkpointing and self.training and idx % 3 != 0:
MODEL="openbmb/MiniCPM-Llama3-V-2_5" # MiniCPM-V权重路径
DATA="path/to/trainging_data" # 训练数据路径
EVAL_DATA="path/to/test_data" # 验证数据路径
"overlap_comm": false # 将overlap_comm从true修改为false
00.00.00.00
00.00.00.01
bash finetune/finetune_ds.sh # 单机8卡全参微调
bash finetune/finetune_lora.sh # 单机8卡Lora微调
bash finetune/finetune_ds_16p.sh # 双机16卡全参微调
bash finetune/finetune_lora_16p.sh # 双机16卡Lora微调
--finetune/output
路径下。表 2 训练结果展示
芯片 | 卡数 | 50-200步训练耗时(s) | batch_size | Data_Type | Torch_Version |
---|---|---|---|---|---|
竞品A-全参微调 | 8p | 847 | 12 | bf16 | 2.1 |
Atlas 800T A2-全参微调 | 8p | 1046 | 12 | bf16 | 2.1 |
竞品A-Lora微调 | 8p | 490 | 8 | bf16 | 2.1 |
Atlas 800T A2-Lora微调 | 8p | 603 | 8 | bf16 | 2.1 |
1.执行下面命令即可进行推理。注意手动修改权重路径、prompt和image路径。
python inference.py --model_path openbmb/MiniCPM-Llama3-V-2_5 --prompt 描述图片内容 --image /path/to/image.jpg
代码涉及公网地址参考 public_address_statement.md
2024.08.26: 首次发布
2024.08.29: 添加NPU适配代码
无
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。