首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >下载模型时发生的类'src.transformers.modeling_tf_bert.TFBertMainLayer'>已经注册到< Custom>TFBertMainLayer

下载模型时发生的类'src.transformers.modeling_tf_bert.TFBertMainLayer'>已经注册到< Custom>TFBertMainLayer
EN

Stack Overflow用户
提问于 2020-04-23 16:42:41
回答 1查看 618关注 0票数 1

我一直在尝试使用PYTORCH-TRANSFORMERS预训练模型。使用collab模板中默认的所有内容,使用从huggingface/pytorch-transformersbert-base-uncasedtorch.hub.load()作为“模型”

代码示例

代码语言:javascript
复制
import torch
model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'bert-base-uncased')    # Download model and configuration from S3 and cache.

我看到了这个错误

代码语言:javascript
复制
Using cache found in /root/.cache/torch/hub/huggingface_pytorch-transformers_master
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-19-ad22a1a34951> in <module>()
      1 import torch
----> 2 model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'somethingelse')    # Download model and configuration from S3 and cache.
      3 model = torch.hub.load('huggingface/pytorch-transformers', 'model', './test/bert_model/')  # E.g. model was saved using `save_pretrained('./test/saved_model/')`
      4 model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'bert-base-uncased', output_attentions=True)  # Update configuration during loading
      5 assert model.config.output_attentions == True

13 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py in decorator(arg)
    177       raise ValueError(
    178           '%s has already been registered to %s' %
--> 179           (registered_name, _GLOBAL_CUSTOM_OBJECTS[registered_name]))
    180 
    181     if arg in _GLOBAL_CUSTOM_NAMES:

ValueError: Custom>TFBertMainLayer has already been registered to <class 'src.transformers.modeling_tf_bert.TFBertMainLayer'>

我不太明白到底是怎么回事。

EN

回答 1

Stack Overflow用户

发布于 2020-11-23 00:35:45

如果您只想使用PyTorch版本的转换器,要解决这个问题,您可以从环境中卸载TensorFlow,或者注释掉转换器源代码中_init_.py中的TensorFlow part (以If is_tf_available()开头:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61382917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档