MiniCPM-V icon indicating copy to clipboard operation
MiniCPM-V copied to clipboard

Lora微调后要怎么加载测试呢?

Open qazqaz12378 opened this issue 1 year ago • 9 comments

finetune/readme.md下面写的加载lora方法的方法只有一部分,请问具体要怎么加载测试呢?

qazqaz12378 avatar Jun 26 '24 07:06 qazqaz12378

问的太对了哥,给我愁死了,这readme写的八成是写错了,那个msg应该是model

White65534 avatar Jun 26 '24 08:06 White65534

我也是很疑惑

y-x-x123 avatar Jun 26 '24 08:06 y-x-x123

先对模型进行合并,就可以推理了

lyc728 avatar Jun 28 '24 09:06 lyc728

怎么合并呢?哪里有示例或者demo吗

On Fri, 28 Jun 2024 at 7:53 PM, lyc728 @.***> wrote:

先对模型进行合并,就可以推理了

— Reply to this email directly, view it on GitHub https://github.com/OpenBMB/MiniCPM-V/issues/298#issuecomment-2196538074, or unsubscribe https://github.com/notifications/unsubscribe-auth/A26FH73GSP2KYPQ3CFOQXW3ZJUXBVAVCNFSM6AAAAABJ5H5MTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJWGUZTQMBXGQ . You are receiving this because you commented.Message ID: @.***>

White65534 avatar Jun 28 '24 09:06 White65534

先对模型进行合并,就可以推理了

谢谢 昨天在issues看到了合并的方法 就可以用了

y-x-x123 avatar Jun 28 '24 10:06 y-x-x123

怎么合并呢?哪里有示例或者demo吗 On Fri, 28 Jun 2024 at 7:53 PM, lyc728 @.> wrote: 先对模型进行合并,就可以推理了 — Reply to this email directly, view it on GitHub <#298 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A26FH73GSP2KYPQ3CFOQXW3ZJUXBVAVCNFSM6AAAAABJ5H5MTSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJWGUZTQMBXGQ . You are receiving this because you commented.Message ID: @.>

这个链接里面有个合并模型https://www.chenxublog.com/2024/04/23/single-card-fine-tuning-minicpm-merging-lora-and-converting-to-gguf-for-llama-cpp.html

y-x-x123 avatar Jun 28 '24 10:06 y-x-x123

先对模型进行合并,就可以推理了

谢谢 昨天在issues看到了合并的方法 就可以用了

合并后的模型和基础模型对比,效果明显么

todaydeath avatar Jun 29 '24 05:06 todaydeath

问的太对了哥,给我愁死了,这readme写的八成是写错了,那个msg应该是model

写成model会报错,就用msg就好了,不用管返回值。但是在运行的时候,显存占多少啊?我这里24G显存不够用,多显卡运行又报错

todaydeath avatar Jun 29 '24 09:06 todaydeath

有没有运行全量微调后加载测试的,我使用官方提供的lora微调的加载测试的会报错

limllzu avatar Jun 30 '24 07:06 limllzu

有没有运行全量微调后加载测试的,我使用官方提供的lora微调的加载测试的会报错

Lora finetune后,用官方代码调试,device='auto' 改成自己的device, 比如cpu or gpu(否则报错:‘NotImplementedError: Cannot copy out of meta tensor; no data!’),测试通过,结果正常。

MonkeyNi avatar Jul 03 '24 06:07 MonkeyNi

有没有运行全量微调后加载测试的,我使用官方提供的lora微调的加载测试的会报错

Lora finetune后,用官方代码调试,device='auto' 改成自己的device, 比如cpu or gpu(否则报错:‘NotImplementedError: Cannot copy out of meta tensor; no data!’),测试通过,结果正常。

@MonkeyNi 您好,请问用官方代码加载lora,到了msg = model.load_state_dict(vpm_resampler_embedtokens_weight, strict=False),之后具体怎么进行测试啊

MuDong612 avatar Jul 03 '24 07:07 MuDong612

参考chat代码就行

lyc728 avatar Jul 03 '24 07:07 lyc728

有没有运行全量微调后加载测试的,我使用官方提供的lora微调的加载测试的会报错

Lora finetune后,用官方代码调试,device='auto' 改成自己的device, 比如cpu or gpu(否则报错:‘NotImplementedError: Cannot copy out of meta tensor; no data!’),测试通过,结果正常。

更新最新代码再试下

lyc728 avatar Jul 03 '24 07:07 lyc728

参考chat代码就行

from chat import MiniCPMVChat, img2base64 import torch import json

torch.manual_seed(0)

from peft import AutoPeftModelForCausalLM

model = AutoPeftModelForCausalLM.from_pretrained( # path to the output directory path_to_adapter, device_map="auto", trust_remote_code=True ).eval()

vpm_resampler_embedtokens_weight = torch.load(f"{path_to_adapter}/vpm_resampler_embedtokens.pt")

msg = model.load_state_dict(vpm_resampler_embedtokens_weight, strict=False)

im_64 = img2base64('./assets/airplane.jpeg')

msgs = [{"role": "user", "content": "Tell me the model of this aircraft."}]

inputs = {"image": im_64, "question": json.dumps(msgs)} answer = chat_model.chat(inputs) print(answer) 请问是这样吗

MuDong612 avatar Jul 03 '24 07:07 MuDong612

这看起来是对的

LDLINGLINGLING avatar Jul 03 '24 12:07 LDLINGLINGLING

微调之后,能不能用自定义的数据集,对模型进行测试?能的话咋搞

Fai-yong avatar Jul 03 '24 15:07 Fai-yong

from peft import AutoPeftModelForCausalLM import torch from chat import MiniCPMVChat, img2base64 import json

path_to_adapter="xxxxxx/output_minicpmv2_lora/checkpoint-200" model = AutoPeftModelForCausalLM.from_pretrained( # path to the output directory path_to_adapter, device_map="cuda:0", trust_remote_code=True ).eval()

vpm_resampler_embedtokens_weight = torch.load(f"{path_to_adapter}/vpm_resampler_embedtokens.pt")

model.load_state_dict(vpm_resampler_embedtokens_weight, strict=False)

im_64 = img2base64('xxxxxxxxxx')

msgs = [{"role": "user", "content": "What is the car mileage?"}]

inputs = {"image": im_64, "question": json.dumps(msgs)} answer = model.chat(inputs) print(answer)

Traceback (most recent call last): File "/home/matthew_kwok_tictag_io/minicpm/MiniCPM-V/predict.py", line 25, in answer = model.chat(inputs) TypeError: MiniCPMV.chat() missing 2 required positional arguments: 'msgs' and 'tokenizer'

wailokkwok avatar Jul 04 '24 06:07 wailokkwok

试试改成model.chat(mage=im_64, msgs=json.dumps(msgs),tokenizer=tokenizer)

LDLINGLINGLING avatar Jul 04 '24 08:07 LDLINGLINGLING

mark

Single430 avatar Jul 09 '24 09:07 Single430

您好 我们这边更新的了lora微调的方式,可以重新尝试一下

qyc-98 avatar Jul 15 '24 05:07 qyc-98

lora加载的方式也更新了具体请看finetune文件下的readme

qyc-98 avatar Jul 15 '24 05:07 qyc-98