huggingface / transformers

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

Xformers is not installed correctly. #24903

Closed david-waterworth closed 1 year ago

david-waterworth commented 1 year ago

System Info

Who can help?

No response

Information

Tasks

Reproduction

from transformers import pipeline
pipe = pipeline("text-classification", model="roberta-base", device=0)

Edit: I know this model isn't trained for the "text-classification" task, I get the same problem with a private model I fine tuned.

Results in the message

...
Xformers is not installed correctly. If you want to use memory_efficient_attention to accelerate training use the following command to install Xformers
pip install xformers.

But I'm using torch==2.0.1 and memory-efficient-attention states "If you have PyTorch 2.0 installed, you shouldn’t use xFormers!"

The message is confusing - I have torch 2.0 installed and pipeline is for inference. This message doesn't occur if I use AutoModelForSequenceClassification.from_pretrained

Expected behavior

The documentation or the warning message are inconsistent.

sgugger commented 1 year ago

It looks like the pipeline is back to importing every model (this message comes from trying to access an unrelated model). I'll have a look later this week. You can ignore that warning in the meantime, it's irrelevant.

sgugger commented 1 year ago

Should be fixed by the PR linked above.

engageintellect commented 1 year ago

same issue for me on this basic example:

import argparse
from transformers import pipeline

# Create the parser
parser = argparse.ArgumentParser(description="Perform sentiment analysis")

# Add an argument
parser.add_argument('Text', type=str, help="the text to analyze")

# Parse the argument
args = parser.parse_args()

# Load the classifier
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

# Perform sentiment analysis
res = classifier(args.Text)

# Print the result
print(res)

Reinstalled transformers, using v.4.31.0

sgugger commented 1 year ago

The fix is not in v4.31.0, you will need to use a source install.