首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RuntimeError:由于以下错误(查找其跟踪)未能导入transformers.pipelines :初始化失败

RuntimeError:由于以下错误(查找其跟踪)未能导入transformers.pipelines :初始化失败
EN

Stack Overflow用户
提问于 2022-08-05 09:56:01
回答 1查看 3.3K关注 0票数 0

目标:运行一个GPT-2模型实例。

我正在使用最新的Tensorflow和拥抱面部变形金刚。

2.9.1

  • Transformers -
  • Tensorflow - 4.21.1

笔记本:

代码语言:javascript
运行
复制
pip install tensorflow
代码语言:javascript
运行
复制
pip install transformers
代码语言:javascript
运行
复制
from transformers import pipeline, set_seed

generator = pipeline('text-generation', model='gpt2')
set_seed(42)
代码语言:javascript
运行
复制
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

SystemError                               Traceback (most recent call last)
SystemError: <built-in method __contains__ of dict object at 0x7f5b58a64d00> returned a result with an error set

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/utils/import_utils.py in _get_module(self, module_name)
   1001         try:
-> 1002             return importlib.import_module("." + module_name, self.__name__)
   1003         except Exception as e:

~/anaconda3/envs/python3/lib/python3.8/importlib/__init__.py in import_module(name, package)
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap.py in _find_and_load(name, import_)

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap.py in _load_unlocked(spec)

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap_external.py in exec_module(self, module)

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/pipelines/__init__.py in <module>
     36 from ..utils import HUGGINGFACE_CO_RESOLVE_ENDPOINT, http_get, is_tf_available, is_torch_available, logging
---> 37 from .audio_classification import AudioClassificationPipeline
     38 from .automatic_speech_recognition import AutomaticSpeechRecognitionPipeline

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/pipelines/audio_classification.py in <module>
     19 from ..utils import add_end_docstrings, is_torch_available, logging
---> 20 from .base import PIPELINE_INIT_ARGS, Pipeline
     21 

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/pipelines/base.py in <module>
     33 from ..feature_extraction_utils import PreTrainedFeatureExtractor
---> 34 from ..modelcard import ModelCard
     35 from ..models.auto.configuration_auto import AutoConfig

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/modelcard.py in <module>
     43 )
---> 44 from .training_args import ParallelMode
     45 from .utils import (

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/training_args.py in <module>
     25 from .debug_utils import DebugOption
---> 26 from .trainer_utils import (
     27     EvaluationStrategy,

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/trainer_utils.py in <module>
     46 if is_tf_available():
---> 47     import tensorflow as tf
     48 

~/anaconda3/envs/python3/lib/python3.8/site-packages/tensorflow/__init__.py in <module>
     36 
---> 37 from tensorflow.python.tools import module_util as _module_util
     38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader

~/anaconda3/envs/python3/lib/python3.8/site-packages/tensorflow/python/__init__.py in <module>
     36 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
---> 37 from tensorflow.python.eager import context
     38 

~/anaconda3/envs/python3/lib/python3.8/site-packages/tensorflow/python/eager/context.py in <module>
     34 from tensorflow.python import tf2
---> 35 from tensorflow.python.client import pywrap_tf_session
     36 from tensorflow.python.eager import executor

~/anaconda3/envs/python3/lib/python3.8/site-packages/tensorflow/python/client/pywrap_tf_session.py in <module>
     18 from tensorflow.python import pywrap_tensorflow
---> 19 from tensorflow.python.client._pywrap_tf_session import *
     20 from tensorflow.python.client._pywrap_tf_session import _TF_SetTarget

ImportError: initialization failed

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_4924/2487422996.py in <cell line: 1>()
----> 1 from transformers import pipeline, set_seed
      2 
      3 generator = pipeline('text-generation', model='gpt2')
      4 set_seed(42)

~/anaconda3/envs/python3/lib/python3.8/importlib/_bootstrap.py in _handle_fromlist(module, fromlist, import_, recursive)

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/utils/import_utils.py in __getattr__(self, name)
    990             value = self._get_module(name)
    991         elif name in self._class_to_module.keys():
--> 992             module = self._get_module(self._class_to_module[name])
    993             value = getattr(module, name)
    994         else:

~/anaconda3/envs/python3/lib/python3.8/site-packages/transformers/utils/import_utils.py in _get_module(self, module_name)
   1002             return importlib.import_module("." + module_name, self.__name__)
   1003         except Exception as e:
-> 1004             raise RuntimeError(
   1005                 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1006                 f" traceback):\n{e}"

RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
initialization failed
代码语言:javascript
运行
复制
def query(payload, multiple, min_tokens, max_tokens):
    nlp_setup()
    list_dict = generator(payload, min_length=min_tokens, max_new_tokens=max_tokens, num_return_sequences=multiple)
    return [d['generated_text'].split(payload)[1].strip() for d in list_dict
代码语言:javascript
运行
复制
output = query("Banking customer's needs:", 3000, 50, 50)

RunTime、SystemError和ImportError都发生在变压器的进口过程中:

RuntimeError:由于以下错误(查找其跟踪)未能导入transformers.pipelines :初始化失败

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-05 10:12:18

更改内核:conda_tensorflow2_p38

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

https://stackoverflow.com/questions/73247922

复制
相关文章

相似问题

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