一、现象:
PyTorch深度学习框架,运行bert-mini,本地环境是torch-gpu,1.4.0,发现报错显示:TypeError: register_buffer() got an unexpected keyword argument ‘persistent’
后面经过各种网上找答案,后面发现是torch版本问题
First, ensure that you’re using a version of PyTorch that supports the persistent keyword argument in register_buffer(). This argument was introduced in a later version of PyTorch (1.5.0), so if you’re using an older version, this could be the source of the error.
发现torch版本需要>=1.5.0,
查看当前环境torch版本
import torch
print(torch.__version__)
# 1.1.0
执行更新语句
pip install --upgrade torch https://pypi.tuna.tsinghua.edu.cn/simple/
程序自动更新(本地环境是torch-gpu,1.4.0)到1.4.0,显然不>=1.5.0,不是自己想要的
二、解决方案
限定torch版本号1.5.0,也不行
pip install torch==1.5.0 -i https://pypi.mirrors.ustc.edu.cn/simple/
限定torch版本号1.6.0,再运行程序代码,这块就不会再报错了
pip install torch==1.6.0 -i https://pypi.mirrors.ustc.edu.cn/simple/
数据代码参考:阿里云天池
解决方案:网上各种资料尝试一番