ImportError: cannot import name 'PaliGemmaForConditionalGeneration' from 'transformers'

#2
by mdeniz1 - opened

hi,
I have used the following code which is provided on the model card

although I already installed transformers, I get import error for PaliGemmaForConditionalGeneration.
I upgraded the install then uninstalled it and re-installed it but it did not work. What can be the problem?

from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from PIL import Image
import requests
import torch

model_id = "google/paligemma-3b-mix-224"
device = "cuda:0"
dtype = torch.bfloat16

url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)

model = PaliGemmaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=dtype,
device_map=device,
revision="bfloat16",
).eval()
processor = AutoProcessor.from_pretrained(model_id)

Hi,

I had the same issue and after accepting the permission it worked. make sure to have the latest version 4.40.2

Same problem here! how do you manage to solve it? I do have the permission. I have the 4.40.2 version

You need to login to your hugging face using the huggingface-cli and provide the access token. https://huggingface.co/docs/hub/en/security-tokens

I already do that but not working :(
image.png

@joselobenitezg what error are you getting?

Google org

@mdeniz1 we have merged the PaliGemma changes to main. please pull the latest main branch of transformers when doing pip installs and make sure your env is using it.

I had to do this: pip install git+https://github.com/huggingface/transformers.git for the error to be solved.

Thank you everyone who came here for help. usr256's suggesstion solved my problem.

I had to do this: pip install git+https://github.com/huggingface/transformers.git for the error to be solved.

mdeniz1 changed discussion status to closed
mdeniz1 changed discussion status to open

well. unfortunately it only seemed to solve the problem. usr256's suggestion only erased the red underlining by pycharm on the import statement. when I execute the code I still get the error :

ImportError: cannot import name 'PaliGemmaForConditionalGeneration' from 'transformers'

@merve I have uninstalled and re-installed transformers. would that follow your suggestion? if so, it did not solve the problem.

Hey all! PaliGemma was merged 12 hours ago, hence you need to pip install from main https://github.com/huggingface/transformers/pull/30814.

We'll do a transformers release soon. Also make sure to log-in into your accocunt.

@mdeniz1
I tried running your script on my environment with RTX 3090, Python 3.11.4 and Ubuntu 20.04 but it ran without error. It didn't output anything, but I guess that's expected. Maybe there is something wrong with Pycharm? Restart Pycharm or maybe try rebooting the computer just in case. I just tested using this command: python3 paligemma-script.py Also, maybe you can try running your script from the command line like that. Hope you get it working.

@mdeniz1 but did you install it from the main branch like I said above? pip install git+https://github.com/huggingface/transformers.git
maybe check that the imported transformers is this one in your environment. also restart your kernel after installation if you're using a notebook.

@mdeniz1 but did you install it from the main branch like I said above? pip install git+https://github.com/huggingface/transformers.git
maybe check that the imported transformers is this one in your environment. also restart your kernel after installation if you're using a notebook.

yes. now it is all good. thank you very much again

mdeniz1 changed discussion status to closed

Sign up or log in to comment