Skip to content

ModuleNotFoundError: No module named 'torch._utils' #321

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

Closed
tf13 opened this issue Nov 5, 2023 · 2 comments
Closed

ModuleNotFoundError: No module named 'torch._utils' #321

tf13 opened this issue Nov 5, 2023 · 2 comments

Comments

@tf13
Copy link

tf13 commented Nov 5, 2023

On Ubuntu 22.04.3 LTS. I've tried installing llm using pip and pipx and run into the same problems. This seems related to the problem with homebrew installs on Mac but I'm not sure I understand everything well enough. Also, running pipdeptree doesn't clearly show any dependency version problems.

Traceback below. I get similar if I run llm commands via python on the commandline. However, I can run llm embed -c 'This is some content' -m sentence-transformers/all-MiniLM-L6-v2 directly from the commandline without problem.

Python 3.11.5 (main, Oct 18 2023, 17:45:44) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import llm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/llm/__init__.py", line 18, in <module>
    from .plugins import pm
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/llm/plugins.py", line 17, in <module>
    pm.load_setuptools_entrypoints("llm")
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/pluggy/_manager.py", line 398, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/llm_sentence_transformers.py", line 2, in <module>
    from sentence_transformers import SentenceTransformer
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/sentence_transformers/__init__.py", line 3, in <module>
    from .datasets import SentencesDataset, ParallelSentencesDataset
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/sentence_transformers/datasets/__init__.py", line 1, in <module>
    from .DenoisingAutoEncoderDataset import DenoisingAutoEncoderDataset
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/sentence_transformers/datasets/DenoisingAutoEncoderDataset.py", line 1, in <module>
    from torch.utils.data import Dataset
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/__init__.py", line 26, in <module>
    from ._utils import _import_dotted_name, classproperty
ModuleNotFoundError: No module named 'torch._utils'
>>> 
@tf13
Copy link
Author

tf13 commented Nov 5, 2023

Following my assumption that this seems similar to the homebrew problem, I tried Simon's suggestion here: #315 (comment)

When I run llm install llm-python, I get what looks like the same ModuleNotFoundError: No module named 'torch._utils' error.

Traceback (most recent call last):
  File "/home/ubuntu/.pyenv/versions/3.11.5/bin/llm", line 5, in <module>
    from llm.cli import cli
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/llm/__init__.py", line 18, in <module>
    from .plugins import pm
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/llm/plugins.py", line 17, in <module>
    pm.load_setuptools_entrypoints("llm")
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/pluggy/_manager.py", line 398, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/llm_sentence_transformers.py", line 2, in <module>
    from sentence_transformers import SentenceTransformer
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/sentence_transformers/__init__.py", line 3, in <module>
    from .datasets import SentencesDataset, ParallelSentencesDataset
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/sentence_transformers/datasets/__init__.py", line 1, in <module>
    from .DenoisingAutoEncoderDataset import DenoisingAutoEncoderDataset
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/sentence_transformers/datasets/DenoisingAutoEncoderDataset.py", line 1, in <module>
    from torch.utils.data import Dataset
  File "/home/ubuntu/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/__init__.py", line 26, in <module>
    from ._utils import _import_dotted_name, classproperty
ModuleNotFoundError: No module named 'torch._utils'

@tf13
Copy link
Author

tf13 commented Nov 30, 2023

OK, I think the problem was absurdly simple. In case anyone else is similarly vexed, this seems to have fixed it:

pip uninstall torch
pip install torch==2.1.0

@tf13 tf13 closed this as completed Nov 30, 2023
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

1 participant