Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
mericalandintent opened this issue Feb 6, 2024 · 5 comments

Comments

@mericalandintent
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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
Copy link

I face the same issue, how can fix it ?

@KuijpersNick0
Copy link

Same issue

1 similar comment
@Y1ran
Copy link

Y1ran commented Apr 15, 2024

Same issue

@Y1ran
Copy link

Y1ran commented Apr 15, 2024

I fixed it by
pip uninstall sentence_transformers
then
conda install sentence_transformers

@ifdealer
Copy link

use this
conda install sentencepiece

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants