LAVIS icon indicating copy to clipboard operation
LAVIS copied to clipboard

Got the AssertionError message.

Open iceleaf97tech opened this issue 2 years ago • 5 comments

AssertionError: BLIP models are not compatible with transformers>=4.27, run pip install transformers==4.25 to downgrade

GPU: RTX A6000 CUDA version: 11.7 conda version: 23.3.1

iceleaf97tech avatar May 19 '23 09:05 iceleaf97tech

Same issue

Reex11 avatar May 20 '23 17:05 Reex11

Please downgrade transformers if you use BLIP models.

LiJunnan1992 avatar May 20 '23 23:05 LiJunnan1992

When the version of transformer is downgradeed, but this message appears:

pip install transformers==4.25

======================[ERROR message]====================== ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. salesforce-lavis 1.0.1 requires transformers>=4.28.0, but you have transformers 4.25.0 which is incompatible. ========================================================

However, the following code does work.

import torch
from PIL import Image
from lavis.models import load_model_and_preprocess
# setup device to use
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# load sample image
raw_image = Image.open("library/LAVIS/docs/_static/merlion.png").convert("RGB")

# loads BLIP caption base model, with finetuned checkpoints on MSCOCO captioning dataset.
# this also loads the associated image processors
model, vis_processors, _ = load_model_and_preprocess(name="blip_caption", model_type="base_coco", is_eval=True, device=device)

# preprocess the image
# vis_processors stores image transforms for "train" and "eval" (validation / testing / inference)
image = vis_processors["eval"](raw_image).unsqueeze(0).to(device)
# generate caption
print(model.generate({"image": image}))
# ['a large fountain spewing water into the air']

Output

['a large fountain spewing water into the air']

iceleaf97tech avatar May 22 '23 02:05 iceleaf97tech

when i'am run bash run_scripts/run_demo.sh, the error is same with you,how do you fix it?

chengyangfeng avatar May 24 '23 08:05 chengyangfeng

@chengyangfeng I ran my code mentioned above with python rather than run_demo.sh.

iceleaf97tech avatar May 26 '23 09:05 iceleaf97tech

BLIP is still interesting, so I would suggest including this issue in the repo. Some options are:

  • Downgrade transformers in the requirements.txt (I just tested with BLIP2 and it works, don't know about the rest)
  • Include a separate requirerements-BLIP.txt (in the root folder or create a requirements folder)
  • Include !pip install transformers==4.25 in the BLIP example notebooks and duplicate the demo script (one will install transformers 4.25 in the current environment)

joaquincabezas avatar Oct 13 '23 06:10 joaquincabezas