gpt4 book ai didi

python - 导入错误 : cannot import name 'AutoModelWithLMHead' from 'transformers'

转载 作者:行者123 更新时间:2023-12-04 13:34:17 25 4
gpt4 key购买 nike

这实际上是我试图运行的所有代码:

from transformers import AutoModelWithLMHead, AutoTokenizer
import torch

tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
model = AutoModelWithLMHead.from_pretrained("microsoft/DialoGPT-small")
我收到此错误:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-14-aad2e7a08a74> in <module>
----> 1 from transformers import AutoModelWithLMHead, AutoTokenizer
2 import torch
3
4 tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
5 model = AutoModelWithLMHead.from_pretrained("microsoft/DialoGPT-small")

ImportError: cannot import name 'AutoModelWithLMHead' from 'transformers' (c:\python38\lib\site-packages\transformers\__init__.py)
我该怎么办?

最佳答案

我解决了!显然 AutoModelWithLMHead 在我的版本中被删除了。
现在你需要使用 AutoModelForCausalLM对于因果语言模型,AutoModelForMaskedLM用于屏蔽语言模型和 AutoModelForSeq2SeqLM用于编码器-解码器模型。
所以在我的情况下,代码如下所示:

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-small")

关于python - 导入错误 : cannot import name 'AutoModelWithLMHead' from 'transformers' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63141267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com