问题描述
我克隆了此存储库/文档 https://huggingface.co/EleutherAI/gpt-neo-125M
无论是在 google collab 上还是在本地运行,都会出现以下错误。我也用这个安装了变压器
pip install git+https://github.com/huggingface/transformers
5 tokenizer = AutoTokenizer.from_pretrained("gpt-neo-125M/",from_tf=True)
----> 6 model = AutoModelForCausalLM.from_pretrained("gpt-neo-125M",from_tf=True)
7
8
3 frames
/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py in __getattr__(self,name)
AttributeError: module transformers has no attribute TFGPTNeoForCausalLM
完整代码:
from transformers import AutoTokenizer,AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-125M",from_tf=True)
model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-125M",from_tf=True)
transformers-cli env 结果:
-
transformers
版本:4.10.0.dev0 - 平台:Linux-4.4.0-19041-Microsoft-x86_64-with-glibc2.29
- Python 版本:3.8.5
- PyTorch 版本(GPU?):1.9.0+cpu(错误)
- Tensorflow 版本(GPU?):2.5.0(错误)
- Flax 版本(cpu?/GPU?/TPU?):未安装(不适用)
- Jax 版本:未安装
- JaxLib 版本:未安装
- 在脚本中使用 GPU?:
- 在脚本中使用分布式或并行设置?:
协作和本地都有 TensorFlow 2.5.0 版本
解决方法
尝试不使用 from_tf=True
标志,如下所示:
from transformers import AutoTokenizer,AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-125M")
model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-125M")
from_tf
期望 pretrained_model_name_or_path
(即第一个参数)是加载已保存的 Tensorflow 检查点的路径。
我的解决方案是首先编辑源代码以删除在包前面添加“TF”的行,因为正确的转换器模块是 GPTNeoForCausalLM ,但在源代码的某处手动添加了一个“TF”。
其次,在克隆存储库之前,必须运行
git lfs install.
此链接帮助我正确安装了 git lfs https://askubuntu.com/questions/799341/how-to-install-git-lfs-on-ubuntu-16-04