transformers: Failed to import transformers.pipelines because of the following error (look up to see its traceback): cannot import name 'PartialState' from 'accelerate'
System Info
I am trying to import Segment Anything Model (SAM) using transformers pipeline. But this gives the following error : " 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)"
What i am trying to do : " from transformers import pipeline generator = pipeline(“mask-generation”, model=“facebook/sam-vit-huge”, device=0) "
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examples
folder (such as GLUE/SQuAD, …) - My own task or dataset (give details below)
Reproduction
import this line:
from transformers import pipeline generator = pipeline(“mask-generation”, model=“facebook/sam-vit-huge”, device=0)
Expected behavior
The model should import as per this notebook in official tutorials: https://github.com/huggingface/notebooks/blob/main/examples/automatic_mask_generation.ipynb
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 39
Hi @MitchellMonaghan, @Abhranta,
Could you try upgrading the installed version of accelerate in your env:
pip install -U accelerate
?You need a more recent version of Accelerate @AzzedineAftiss:
pip install --upgrade accelerate
.Thanks this resolved this error thanks. It upgraded the accelerate package from.
Thank you 🤗 so much for the amazing work, making it so easy to try and learn about the best models in the world. 🙏
Ref: https://huggingface.co/blog/falcon
Got the same error as this issue while running the Falcon tutorial by HuggingFace on Kaggle. Came across this thread via a Google search (not from an LLM yet 😉) and had to make the following changes to get the Falcon tutorial to work on Kaggle notebooks:
accelerate
needs to be upgraded as mentioned in this thread.einops
andxformers
needs to be installed as well.My Notebook on Kaggle: https://www.kaggle.com/bkowshik/llms-models-falcon
NOTE: Had to rerun a couple of times given memory issues on Kaggle, so one needs to keep 🤞
@sgugger @amyeroberts Should we can close this issue then?
Complete logs with warning messages printed as part of the output for reference.
This Error suddenly pops up in kaggle. Any IDEA!!! I already tried installing accelerate, transformers and datasets as the first line to execute in each notebooks.
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) File <timed exec>:2
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)
Thanks, will try that. Didn’t try that because i wasn’t using xformers directly. But i guess its used by some other dependecy.
@sgugger @amyeroberts as annoying as it is, but pipeline in kaggle is not working as seen in screenshot above.
It didn’t work even when i did this:
!pip install transformers tokenizers datasets huggingface_hub --upgrade -q
!pip install accelerator --upgrade -q
Thanks @bkowshik it worked!