Unable to load weights from pytorch checkpoint file for ‘bert-base-uncased‘ at ...

OSError: Unable to load weights from pytorch checkpoint file for ‘bert-base-uncased’ at …

方案一

使用huggingface的bert时遇到预训练模型加载失败的问题,具体终端报错为:

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

尝试过删除缓存文件,但又报同样错误。
最终解决方案:将torch1.8——cudnn11.3版本卸载,安装cuda10.2版本torch,不再报错。

方案二

将官方代码中加载模型的参数from_tf值置为True,具体如下(模型名称任意):

model = AutoModelForSeq2SeqLM.from_pretrained(
            args.model_name_or_path,
            # from_tf=bool(".ckpt" in args.model_name_or_path),
            config=config,
            from_tf=True,
        )

模型机可以正常运行,不再报错。

你可能感兴趣的:(Pytorch,深度学习,pytorch)