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

add minicpmv support #972

Merged
merged 1 commit into from
Nov 5, 2024
Merged

Conversation

eaidova
Copy link
Collaborator

@eaidova eaidova commented Oct 24, 2024

What does this PR do?

support of minicpmv

from optimum.intel.openvino import OVModelForVisualCausalLM
from transformers import AutoProcessor
from PIL import Image
import requests

model_id = "openbmb/MiniCPM-V-2_6"

processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)

prompt= "<|im_start|>user\n(<image>./</image>)\nWhat is unusual on this image?<|im_end|>\n<|im_start|>assistant\n"
image = Image.open(requests.get("https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11", stream=True).raw).convert('RGB')

model = OVModelForVisualCausalLM.from_pretrained(model_dir, trust_remote_code=True)

inputs = processor([prompt], [image], return_tensors="pt")

result  = model.generate(**inputs, max_new_tokens=20)

print(processor.tokenizer.batch_decode(result[:, inputs["input_ids"].shape[1]:]))

changes were already reviewed as part of #928 (I just moved all things relevant to others models support in separated PRs)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

return None
return AutoModelForCausalLM

def gen_inputs(self, model_arch, base_text_prompt, image=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be possible to expose a method like this as a part of an API for working with OVModelForVisualCausalLMs?

It would simplify the demo examples and usage in general. Also, it will come helpful during dataset collection for data-aware compression.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking that it could help for demos, optimization and validation purposes. No problem if we do it in the follow-up PR.

@AlexKoff88 AlexKoff88 merged commit 54a9727 into huggingface:main Nov 5, 2024
15 of 17 checks passed
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

Successfully merging this pull request may close these issues.

4 participants