解决方案TypeError: register_buffer() got an unexpected keyword argument ‘persistent‘

文章讲述了在使用PyTorch1.4.0运行BERT-mini时遇到关于register_buffer的TypeError,经调查发现需要1.5.0及以上版本的torch支持persistent参数。尝试升级和锁定特定版本后,找到解决方案为安装torch>=1.6.0。
摘要由CSDN通过智能技术生成


一、现象:

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/

在这里插入图片描述


数据代码参考:阿里云天池
解决方案:网上各种资料尝试一番

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值