Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateError: Prompting with images is incompatible with system messages. #774

Open
1 of 2 tasks
hessaAlawwad opened this issue Nov 5, 2024 · 3 comments
Open
1 of 2 tasks
Assignees

Comments

@hessaAlawwad
Copy link

System Info

Hello,

I am trying the follwoing code and it throughs an error message:
TemplateError: Prompting with images is incompatible with system messages.

The code is (Ref):

# Load the standard llama 3.2 11B Vision Instruct model/folder
model = MllamaForConditionalGeneration.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
       device_map="auto",
    # attn_implementation="flash_attention_2", NOT AVAILABLE YET FOR MLLAMA CONDITIONALGENERATION
    local_files_only=True
)

processor = AutoProcessor.from_pretrained(model_id)

messages = [
    [
        {
            "role": "system",
            "content": "ALWAYS start your sentence with an emoji, no matter what. Even if it does not make sense. If you can, use a stop sign emoji."
        },
        {
            "role": "user", 
            "content": [
                {"type": "image"},
                {"type": "text", "text": "Do you see that person?"}
            ]
        }
    ],
]

text = processor.apply_chat_template(messages, add_generation_prompt=True)

image_path = "https://llava-vl.github.io/static/images/view.jpg" #URL
image = Image.open(requests.get(image_path, stream=True).raw)

inputs = processor(text=text, images=image, return_tensors="pt").to(model.device)

output = model.generate(**inputs, max_new_tokens=30)
print(processor.decode(output[0]))

Information

  • The official example scripts
  • My own modified scripts

🐛 Describe the bug

Not accepting the system role message when sending text+image

Error logs

TemplateError: Prompting with images is incompatible with system messages.

Expected behavior

as I am adding the image to the user role. it should work fine

@wukaixingxp
Copy link
Contributor

@TQA-task Thanks for this bug report. We have confirmed that it is a unexpected bug and will work with Hugging face team to get system role supported for our vision models. Will keep you updated once it is done.

@wukaixingxp wukaixingxp self-assigned this Nov 6, 2024
@yann-trustlab
Copy link

@wukaixingxp any update regarding this bug? I ran into the same problem with transformers==4.46.3. Thank you!

@AgatheBauer
Copy link

I get the same error message while using Llama-3.2-90b via Groq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants