bert无法加载模型,报oserror,请问怎么解决?

model = BertForSequenceClassification.from_pretrained('./models/bert-base-chinese/', num_labels=13)

state = torch.load('./models/bert.pth',map_location=torch.device('cpu'))
    
model.load_state_dict(state["state_dict"])
model.to(device)
    

我将bert-base-chines下载到了本地直接读取,但是第一行发生了下述的错误

OSError: Unable to load weights from pytorch checkpoint file for './models/bert-base-chinese/' at './models/bert-base-chinese/pytorch_model.bin'If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. 

我以前一直是通过联网直接加载的,但是部署的平台没办法联网

谁知道可以怎么解决吗 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

torch._C._cuda_init()

RuntimeError: No CUDA GPUs are available
怎么解决

解决办法:把C:\Users\Administrator\.cache\huggingface\transformers下的文件删除后,重新下载加载就可以用。如果不行,应该是版本问题。

参考OSError: Unable to load weights from pytorch checkpoint file. If you tried to load a PyTorch_A_zhangpengjie的博客-CSDN博客