TypeError: forward() got an unexpected keyword argument 'num_logits_to_keep'

#51
by shajiu - opened

transformers-4.45.0.dev0

model_id = "/root/paddlejob/workspace/env_run/output/per_models/llava-1.5-7b-hf"
image_file = "ai2d-demo.jpg"

import requests
from PIL import Image

import torch
from transformers import AutoProcessor, LlavaForConditionalGeneration
from transformers import LlavaForConditionalGeneration
model = LlavaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
).to(0)

processor = AutoProcessor.from_pretrained(model_id)

Define a chat histiry and use apply_chat_template to get correctly formatted prompt

Each value in "content" has to be a list of dicts with types ("text", "image")

conversation = [
{

  "role": "user",
  "content": [
      {"type": "text", "text": "What are these?"},
      {"type": "image"},
    ],
},

]
#prompt = processor.apply_chat_template(conversation,add_generation_prompt=True)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
prompt = "USER: \nwhat is the image about\nASSISTANT:"
raw_image = Image.open("./ai2d-demo.jpg")
inputs = processor(prompt, raw_image, return_tensors="pt").to(device, torch.float16)
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
print(processor.decode(output[0][2:], skip_special_tokens=True))

Sign up or log in to comment