OpenBMB / MiniCPM

MiniCPM3-4B: An edge-side LLM that surpasses GPT-3.5-Turbo.
Apache License 2.0
6.95k stars 440 forks source link

[Bug]: 出现报错_pickle.UnpicklingError: Weights only load failed. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. #185

Closed weiruijinglu closed 1 week ago

weiruijinglu commented 1 month ago

Is there an existing issue ? / 是否已有相关的 issue ?

Describe the bug / 描述这个 bug

按照https://modelbest.feishu.cn/wiki/Sd6pwKkLni4YNgkeWB9cm3XInTb这篇文档的指导,在GPU服务器上下载了miniCPM-bf16这个模型。尝试运行MiniCPM/demo/hf_based_demo.py脚本时出现如下报错: Traceback (most recent call last): File "/home/xxx/miniconda3/lib/python3.8/site-packages/transformers/modeling_utils.py", line 575, in load_state_dict return torch.load( File "/home/xxx/miniconda3/lib/python3.8/site-packages/torch/serialization.py", line 1113, in load raise pickle.UnpicklingError(_get_wo_message(str(e))) from None _pickle.UnpicklingError: Weights only load failed. Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. Please file an issue with the following so that we can make weights_only=True compatible with your use case: WeightsUnpickler error: Unsupported operand 118

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

To Reproduce / 如何复现

在Linux系统下依次用git clone https://github.com/OpenBMB/MiniCPM.git指令安装MiniCPM、用git clone https://www.modelscope.cn/OpenBMB/miniCPM-bf16.git安装miniCPM-bf16。修改MiniCPM/demo/hf_based_demo.py中第18行为parser.add_argument("--torch_dtype", type=str, default="float16", choices=["float32", "bfloat16", "float16"])。然后运行该脚本出现报错。 使用的Python解释器版本是Python 3.8.5,不知道是不是版本的问题?

Expected behavior / 期望的结果

正确结果

Screenshots / 截图

No response

Environment / 环境

- OS: [Ubuntu 20.04.6]
- Pytorch: [torch 2.4.0]
- CUDA: [CUDA 12.1]
- Device: [RTX3090]

Additional context / 其他信息

No response

weiruijinglu commented 1 month ago

我已经解决了这个问题,抱歉这里占用了公共资源。 原因是我没有正确安装git-lfs,所以模型里的大文件不能正常下载,导致权重加载时出现错误。 我用的python环境是Python3.10