【问题标题】:AttributeError: module transformers has no attribute TFGPTNeoForCausalLMAttributeError:模块转换器没有属性 TFGPTNeoForCausalLM
【发布时间】:2021-10-06 18:51:22
【问题描述】:

我克隆了这个存储库/文档https://huggingface.co/EleutherAI/gpt-neo-125M

无论我是在 google collab 上还是在本地运行它,我都会收到以下错误。我也用这个安装了变压器

pip install git+https://github.com/huggingface/transformers

并确保配置文件命名为 config.json

      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 环境结果:

  • 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?):未安装 (NA)
  • Jax 版本:未安装
  • JaxLib 版本:未安装
  • 在脚本中使用 GPU?:
  • 在脚本中使用分布式或并行设置?:

collab 和本地都有 TensorFlow 2.5.0 版本

【问题讨论】:

    标签: python pytorch huggingface-transformers gpt gpt-3


    【解决方案1】:

    尝试不使用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 检查点的路径。

    【讨论】:

    • 感谢您的回答。我通过克隆此存储库huggingface.co/EleutherAI/gpt-neo-125M 下载了模型,我想从该检查点加载模型,因此我使用了 from_tf 标志。注意,在 google collab 上,如果我不使用该标志,它可以正常工作,但在本地,如果我不使用该标志,它就不起作用。在协作和本地,如果我使用该标志,它会给出上述错误。
    • 错误的两个可能原因: (1) 可能是您的环境中没有安装tensorflow。 (2) 在那个仓库 huggingface.co/EleutherAI/gpt-neo-125M/tree/main 中没有 tensorflow 检查点。你能在本地机器上做transformers-cli env吗?
    • 我用 transformers-cli 环境结果更新了我的问题
    • 我也尝试在 collab 上使用 tensorflow-gpu 而不是普通的 tensorflow,但我得到了同样的错误
    • 我认为错误来自源代码中的错误。进行一些更改后,我收到此错误,(打开 github 问题)github.com/EleutherAI/gpt-neo/issues/236
    【解决方案2】:

    我的解决方案是首先编辑源代码以删除在包前面添加“TF”的行,因为正确的转换器模块是 GPTNeoForCausalLM ,但是在源代码的某个地方它手动在它前面添加了一个“TF”。

    其次,在克隆存储库之前,必须运行

     git lfs install. 
    

    这个链接帮助我正确安装了 git lfs https://askubuntu.com/questions/799341/how-to-install-git-lfs-on-ubuntu-16-04

    【讨论】:

    • TF 在最佳猜测中指的是 tensorflow。当您设置 from_tf=True 时,它会被启用。
    • 是有道理的,虽然我认为它在我尝试其他标志时也被触发了,但我现在不记得了,因为它起作用了:p
    猜你喜欢
    • 2021-01-28
    • 2018-04-14
    • 2019-02-18
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 2020-01-01
    • 2019-07-20
    相关资源
    最近更新 更多