THUDM / ChatGLM2-6B

ChatGLM2-6B: An Open Bilingual Chat LLM | 开源双语对话语言模型
Other
15.65k stars 1.85k forks source link

[BUG/Help] cannot import name '_sentencepiece' from partially initialized module 'sentencepiece' #662

Open mericalandintent opened 5 months ago

mericalandintent commented 5 months ago

Is there an existing issue for this?

Current Behavior

C:\Users\Lee\source\ChatGLM2-6B\web_demo.py:46: SyntaxWarning: invalid escape sequence '`' line = line.replace("", "\") Traceback (most recent call last): File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\utils\import_utils.py", line 1086, in _get_module return importlib.import_module("." + module_name, self.name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\importlib__init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1381, in _gcd_import File "", line 1354, in _find_and_load File "", line 1304, in _find_and_load_unlocked File "", line 488, in _call_with_frames_removed File "", line 1381, in _gcd_import File "", line 1354, in _find_and_load File "", line 1325, in _find_and_load_unlocked File "", line 929, in _load_unlocked File "", line 994, in exec_module File "", line 488, in _call_with_frames_removed File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\models\init.py", line 15, in from . import ( File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\models\mt5\init.py", line 29, in from ..t5.tokenization_t5 import T5Tokenizer File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\models\t5\tokenization_t5.py", line 24, in import sentencepiece as spm File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\sentencepiece\init.py", line 13, in from . import _sentencepiece ImportError: cannot import name '_sentencepiece' from partially initialized module 'sentencepiece' (most likely due to a circular import) (C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\sentencepiece\init__.py)

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

Traceback (most recent call last): File "C:\Users\Lee\source\ChatGLM2-6B\web_demo.py", line 1, in from transformers import AutoModel, AutoTokenizer File "", line 1406, in _handle_fromlist File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\utils\import_utils.py", line 1076, in getattr module = self._get_module(self._class_to_module[name]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\utils\import_utils.py", line 1088, in _get_module raise RuntimeError( RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback): cannot import name '_sentencepiece' from partially initialized module 'sentencepiece' (most likely due to a circular import) (C:\Users\Lee\AppData\Local\Programs\Python\Python312\Lib\site-packages\sentencepiece__init__.py)

Expected Behavior

No response

Steps To Reproduce

in windows 11 run web_demo.py

Environment

- OS: windows 11
- Python: 3.12
- Transformers: 4.30.2
- PyTorch: 2.2.0+cu121
- CUDA Support (`python -c "import torch; print(torch.cuda.is_available())"`) : True

Anything else?

No response

Goku-xym commented 4 months ago

I face the same issue, how can fix it ?

KuijpersNick0 commented 3 months ago

Same issue

Y1ran commented 3 months ago

Same issue

Y1ran commented 3 months ago

I fixed it by pip uninstall sentence_transformers then conda install sentence_transformers

ifdealer commented 1 month ago

use this conda install sentencepiece