导入错误:无法在拥抱面变压器中导入名称"hf_bucket_url"



所以我在Google Colab上安装了最新版本的变压器

!pip install transformers 

尝试使用

!python /usr/local/lib/python3.6/dist-packages/transformers/convert_pytorch_checkpoint_to_tf2.py .py --help  

或尝试使用

from transformers.file_utils import hf_bucket_url.                                 // works 
from transformers.convert_pytorch_checkpoint_to_tf2 import *.                      // fails
convert_pytorch_checkpoint_to_tf("gpt2", pytorch_file, config_file, tf_file).      

我收到此错误

ImportError                               Traceback (most recent call last)
<ipython-input-3-dadaf83ecea0> in <module>()
1 from transformers.file_utils import hf_bucket_url
----> 2 from transformers.convert_pytorch_checkpoint_to_tf2 import *
3 
4 convert_pytorch_checkpoint_to_tf("gpt2", pytorch_file, config_file, tf_file)
/usr/local/lib/python3.6/dist-packages/transformers/convert_pytorch_checkpoint_to_tf2.py in <module>()
20 import os
21 
---> 22 from transformers import (
23     ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
24     BERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
ImportError: cannot import name 'hf_bucket_url'

这是怎么回事?

原来这是一个错误。此 PR 通过正确导入函数hf_bucket_url来解决此问题。

最新更新