BUG TypeError: GPT2Model.forward() got an unexpected keyword argument ‘past’

TypeError: GPT2Model.forward() got an unexpected keyword argument 'past'

环境

shell 复制代码
transformers                  4.38.1

详情

这是由于新版的transformers 对GPT2Model.forward() 参数进行了改变导致的错误。具体是past名称改为了 past_key_values

解决方法

找到错误语句,将其中的past 参数改为past_key_values

例如

python 复制代码
model = GPT2Model(config)
# 旧
transformer_outputs = model(input_ids, past=past, token_type_ids=token_type_ids)

# 新
transformer_outputs = model(input_ids, past_key_values=past, token_type_ids=token_type_ids)

参考

https://github.com/liucongg/GPT2-NewsTitle/issues/34

相关推荐
ALGO阿狗1 天前
SimpleDateFormat(“YYYY-MM-dd“)格式化时间出现了bug?
bug
爱学习的小可爱卢2 天前
JavaSE基础-Java异常体系:Bug定位终极指南
java·bug·javase
GeekyGuru2 天前
代码诊疗室——疑难Bug破解战
bug
嵌入式×边缘AI:打怪升级日志5 天前
9.2.3 UART 驱动严重 Bug(保姆级讲解)
bug
qq_24218863327 天前
代码诊疗室——疑难Bug破解战
bug
Moshow郑锴9 天前
Java SpringBoot 疑难 Bug 排查思路解析:从“语法正确”到“行为相符”
java·spring boot·bug
人间花海9 天前
BUG终结者:挑战你的调试极限
bug
2401_858286119 天前
OS54.【Linux】System V 共享内存(3) “共享内存+管道“修bug记录
linux·运维·服务器·算法·bug
Kurbaneli10 天前
代码诊疗室——疑难Bug破解战
bug
Mr -老鬼12 天前
从 0 到 1 落地:Rust + Salvo 实现用户系统与 Bug 管理系统
开发语言·rust·bug