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

相关推荐
Pan Zonghui1 天前
GitHub Bug反馈与修复全流程指南
github·bug
初圣魔门首席弟子2 天前
bug 2026.05.15(以前能运行的java springboot项目突然间不能运行后台数据了)
java·开发语言·bug
Desenberg2 天前
【Claude Code】因为中途修改配置路径导致Claude Code 插件安装失败
windows·bug
QuestLab3 天前
维护 Hermes Agent CN 过程中的碎碎念,以及从bug上得到的一点点启发
bug
java修仙传3 天前
Java 实习日记:一次 Excel 导入校验 Bug 的定位与数据更新逻辑优化
java·数据库·bug·excel·后端开发
当战神遇到编程3 天前
软件测试基础入门:从 BUG 到测试用例设计完整指南
测试用例·bug
Bear on Toilet6 天前
3. BUG篇
bug
编程探索者小陈6 天前
【测试】之BUG篇
bug
棋宣6 天前
uni-app编译到微信小程序中,父传子props首次传递数据不接收的bug
微信小程序·uni-app·bug
wqdian_com6 天前
华为手机浏览器的一个bug
服务器·华为·bug