When import pipeline from Huggingface on Kaggle notebook,
from transformers import pipeline
it throws this error:
/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/__init__.py:98: UserWarning: unable to load libtensorflow_io_plugins.so: unable to open file: libtensorflow_io_plugins.so, from paths: ['/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/libtensorflow_io_plugins.so']
caused by: ['/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/libtensorflow_io_plugins.so: undefined symbol: _ZN3tsl6StatusC1EN10tensorflow5error4CodeESt17basic_string_viewIcSt11char_traitsIcEENS_14SourceLocationE']
warnings.warn(f"unable to load libtensorflow_io_plugins.so: {e}")
/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/__init__.py:104: UserWarning: file system plugins are not loaded: unable to open file: libtensorflow_io.so, from paths: ['/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/libtensorflow_io.so']
caused by: ['/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/libtensorflow_io.so: undefined symbol: _ZTVN10tensorflow13GcsFileSystemE']
warnings.warn(f"file system plugins are not loaded: {e}")
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/transformers/utils/import_utils.py:1172, in _LazyModule._get_module(self, module_name)
1171 try:
-> 1172 return importlib.import_module("." + module_name, self.__name__)
1173 except Exception as e:
File /opt/conda/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:1006, in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:688, in _load_unlocked(spec)
File <frozen importlib._bootstrap_external>:883, in exec_module(self, module)
File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f, *args, **kwds)
File /opt/conda/lib/python3.10/site-packages/transformers/pipelines/__init__.py:44
35 from ..utils import (
36 HUGGINGFACE_CO_RESOLVE_ENDPOINT,
37 is_kenlm_available,
(...)
42 logging,
43 )
---> 44 from .audio_classification import AudioClassificationPipeline
45 from .automatic_speech_recognition import AutomaticSpeechRecognitionPipeline
File /opt/conda/lib/python3.10/site-packages/transformers/pipelines/audio_classification.py:21
20 from ..utils import add_end_docstrings, is_torch_available, logging
---> 21 from .base import PIPELINE_INIT_ARGS, Pipeline
24 if is_torch_available():
File /opt/conda/lib/python3.10/site-packages/transformers/pipelines/base.py:36
35 from ..image_processing_utils import BaseImageProcessor
---> 36 from ..modelcard import ModelCard
37 from ..models.auto.configuration_auto import AutoConfig
File /opt/conda/lib/python3.10/site-packages/transformers/modelcard.py:48
32 from .models.auto.modeling_auto import (
33 MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES,
34 MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,
(...)
46 MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES,
47 )
---> 48 from .training_args import ParallelMode
49 from .utils import (
50 MODEL_CARD_NAME,
51 cached_file,
(...)
57 logging,
58 )
File /opt/conda/lib/python3.10/site-packages/transformers/training_args.py:67
66 if is_accelerate_available():
---> 67 from accelerate import PartialState
68 from accelerate.utils import DistributedType
ImportError: cannot import name 'PartialState' from 'accelerate' (/opt/conda/lib/python3.10/site-packages/accelerate/__init__.py)
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
Cell In[1], line 2
1 from transformers import AutoModelForSequenceClassification, AutoTokenizer
----> 2 from transformers import pipeline
File <frozen importlib._bootstrap>:1075, in _handle_fromlist(module, fromlist, import_, recursive)
File /opt/conda/lib/python3.10/site-packages/transformers/utils/import_utils.py:1162, in _LazyModule.__getattr__(self, name)
1160 value = self._get_module(name)
1161 elif name in self._class_to_module.keys():
-> 1162 module = self._get_module(self._class_to_module[name])
1163 value = getattr(module, name)
1164 else:
File /opt/conda/lib/python3.10/site-packages/transformers/utils/import_utils.py:1174, in _LazyModule._get_module(self, module_name)
1172 return importlib.import_module("." + module_name, self.__name__)
1173 except Exception as e:
-> 1174 raise RuntimeError(
1175 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
1176 f" traceback):\n{e}"
1177 ) from e
RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
cannot import name 'PartialState' from 'accelerate' (/opt/conda/lib/python3.10/site-packages/accelerate/__init__.py)
How do I resolve this error?
If you're seeing this error inside Kaggle notebooks, try installing from source,
! pip install -U git+https://github.com/huggingface/transformers.git
! pip install -U git+https://github.com/huggingface/accelerate.git
Then restart the kernel by clicking "Restart and clear cell outputs" ,
Now the imports will work without the error.
Kaggle containers struggle to balance being up-to-date and compatibility on lots (.) of libraries. Upgrade minimalistically accelerate
(don't upgrade the whole transformers
module) and prefer stable pip releases over git sources (to not catch some unmature code, unless for a good reason). Don't need to restart the notebook. This line does the job:
!pip install -U accelerate --quiet
from transformers import pipeline
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.