huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
132.74k stars 26.45k forks source link

ImportError: AutoModel requires the PyTorch library but it was not found in your environment #28282

Closed Marwen94 closed 7 months ago

Marwen94 commented 9 months ago

System Info

I'm trying to load a AutoModel pre-trained model. However, I receiving the following error :

ImportError: 
AutoModel requires the PyTorch library but it was not found in your environment.
However, we were able to find a TensorFlow installation. TensorFlow classes begin
with "TF", but are otherwise identically named to our PyTorch classes. This
means that the TF equivalent of the class you tried to import would be "TFAutoModel".
If you want to use TensorFlow, please use TF classes instead!

I do have Pytorch installed :

torch==2.0.0
torchvision==0.16.2

transformers-cli env :

- `transformers` version: 4.36.2
- Platform: macOS-14.2.1-x86_64-i386-64bit
- Python version: 3.11.7
- Huggingface_hub version: 0.20.1
- Safetensors version: 0.4.1
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): 2.0.0 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

Thanks a lot!

Who can help?

@gante and @Rocketknight1

Information

Tasks

Reproduction

1 . Create an activate a virtual env using this poetry file :

[tool.poetry]
name = "test"
version = "1.0.0"
authors = ["Marwen Taleb"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
transformers="4.36.2"
scikit-learn = "^1.3.2"
pandas = "2.0.0"
torch = "2.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

2 . Run this python script :

from transformers import AutoModel
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-en', trust_remote_code=True)
  1. You should received the above described error.

Expected behavior

I expect to be able to instantiate an AutoModel from a pretrained model when having Pytorch installed.

Rocketknight1 commented 8 months ago

Hi @marwen94, I'm struggling to reproduce this here. I'm not familiar with the Poetry dependency manager, but I tried reproducing those package versions in a Python 3.9 env with pip and the model loaded fine - the issue seems to be very specific to the environment you're using.

Can you figure out a list of package versions that I can install with conda or pip that reproduces the issue? Once I can reproduce it here I can work on diagnosing and fixing it!

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.