news 2026/3/27 22:49:10

KeyError: ‘sdpa‘

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
KeyError: ‘sdpa‘

问题描述

model=AutoModelForCausalLM.from_pretrained(^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\AppData\Roaming\Python\Python312\site-packages\transformers\models\auto\auto_factory.py",line597,infrom_pretrainedreturnmodel_class.from_pretrained(^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\AppData\Roaming\Python\Python312\site-packages\transformers\modeling_utils.py",line277,in_wrapperreturnfunc(*args,**kwargs)^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\AppData\Roaming\Python\Python312\site-packages\transformers\modeling_utils.py",line4971,infrom_pretrained model=cls(config,*model_args,**model_kwargs)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\.cache\huggingface\modules\transformers_modules\Youtu_hyphen_VL_hyphen_4B_hyphen_Instruct\modeling_youtu_vl.py",line1173,in__init__ self.siglip2=Siglip2VisionModel._from_config(config.vision_config)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\AppData\Roaming\Python\Python312\site-packages\transformers\modeling_utils.py",line277,in_wrapperreturnfunc(*args,**kwargs)^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\AppData\Roaming\Python\Python312\site-packages\transformers\modeling_utils.py",line2311,in_from_config model=cls(config,**kwargs)^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\.cache\huggingface\modules\transformers_modules\Youtu_hyphen_VL_hyphen_4B_hyphen_Instruct\modeling_siglip2.py",line1284,in__init__ self.vision_model=Siglip2VisionTransformer(config)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\.cache\huggingface\modules\transformers_modules\Youtu_hyphen_VL_hyphen_4B_hyphen_Instruct\modeling_siglip2.py",line817,in__init__ self.encoder=Siglip2Encoder(config)^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\.cache\huggingface\modules\transformers_modules\Youtu_hyphen_VL_hyphen_4B_hyphen_Instruct\modeling_siglip2.py",line604,in__init__ self.layers=nn.ModuleList([Siglip2EncoderLayer(config)for_inrange(config.num_hidden_layers)])^^^^^^^^^^^^^^^^^^^^^^^^^^^File"C:\Users\wh109\.cache\huggingface\modules\transformers_modules\Youtu_hyphen_VL_hyphen_4B_hyphen_Instruct\modeling_siglip2.py",line534,in__init__ self.self_attn=VISION_ATTENTION_CLASSES[config._attn_implementation](config=config)~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^KeyError:'sdpa'

解决方法

将attn_implementation设置为eager,

attn_implementation="eager",# 关键参数

代码如下:

fromtransformersimportAutoModelForCausalLM,AutoProcessor,AutoConfigimporttorch# 方法1:通过 config 设置config=AutoConfig.from_pretrained("Youtu-VL-4B-Instruct")config._attn_implementation="eager"# 使用标准注意力机制model=AutoModelForCausalLM.from_pretrained("Youtu-VL-4B-Instruct",config=config,torch_dtype=torch.bfloat16,# 或者 torch.float16device_map="auto")# 方法2:在 from_pretrained 中直接指定model=AutoModelForCausalLM.from_pretrained("Youtu-VL-4B-Instruct",torch_dtype=torch.bfloat16,attn_implementation="eager",# 关键参数device_map="auto")
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/19 7:27:39

2026毕设ssm+vue农家乐订购系统论文+程序

本系统(程序源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。 系统程序文件列表 开题报告内容 选题背景 关于旅游信息化管理问题的研究,现有研究主要以传统酒店管理系统和单一景点门票系统为主,专门针对民…

作者头像 李华
网站建设 2026/3/24 16:58:55

2026毕设ssm+vue农副产品网上预订系统论文+程序

本系统(程序源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容选题背景关于区域电子商务与本地生活服务平台的研究,现有研究主要以大型综合电商平台(如淘宝、京东)的商…

作者头像 李华
网站建设 2026/3/21 8:45:08

主流小程序平台客观对比与企业选型参考指南

当今之时,数字化转型已然成了企业里普遍存在的标配情形,在此状况下,小程序变成了连接线上跟线下的十分关键的桥梁。商家面对市场之上数量众多的小程序开发平台,于选择之际常常会感觉到自己十分困扰迷茫。各个不一样的平台&#xf…

作者头像 李华
网站建设 2026/3/24 17:26:48

ModOrganizer2游戏报错怎么办?快速解决MO2运行失败的实用指南

ModOrganizer2游戏报错怎么办?快速解决MO2运行失败的实用指南 【免费下载链接】modorganizer Mod manager for various PC games. Discord Server: https://discord.gg/ewUVAqyrQX if you would like to be more involved 项目地址: https://gitcode.com/gh_mirr…

作者头像 李华