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 Phi-3.5-vision-instruct model #2385

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions notebooks/phi-3-vision/gradio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@


def make_demo(model, processor):
model_name = Path(model.config._name_or_path).parent.name

example_image_urls = [
("https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/dd5105d6-6a64-4935-8a34-3058a82c8d5d", "small.png"),
("https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/1221e2a8-a6da-413a-9af6-f04d56af3754", "chart.png"),
Expand Down Expand Up @@ -92,12 +94,12 @@ def bot_streaming(message, history):

demo = gr.ChatInterface(
fn=bot_streaming,
title="Phi3 Vision 128K Instruct with OpenVINO",
title=f"{model_name} with OpenVINO",
examples=[
{"text": "What is the text saying?", "files": ["./small.png"]},
{"text": "What does the chart display?", "files": ["./chart.png"]},
],
description="Try the [Phi3-Vision model](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct) from Microsoft wiht OpenVINO. Upload an image and start chatting about it, or simply try one of the examples below. If you won't upload an image, you will receive an error.",
description=f"Try the [{model_name} model](https://huggingface.co/microsoft/{model_name}) from Microsoft with OpenVINO. Upload an image and start chatting about it, or simply try one of the examples below. If you won't upload an image, you will receive an error.",
stop_btn="Stop Generation",
multimodal=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def cleanup_torchscript_cache():


def convert_phi3_model(model_id, output_dir, quantization_config):
model_name = Path(model_id).name
output_dir = Path(output_dir)

lang_model_path = output_dir / "language_model.xml"
Expand All @@ -207,9 +208,9 @@ def convert_phi3_model(model_id, output_dir, quantization_config):
embed_token_path.exists(),
]
):
print(f"✅ Phi-3-vision model already converted. You can find results in {output_dir}")
print(f"✅ {model_name} model already converted. You can find results in {output_dir}")
return
print("⌛ Phi-3-vision conversion started. Be patient, it may takes some time.")
print(f"⌛ {model_name} conversion started. Be patient, it may takes some time.")
print("⌛ Load Original model")
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, _attn_implementation="eager")
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
Expand Down Expand Up @@ -313,7 +314,7 @@ def forward_wrap(
cleanup_torchscript_cache()
del model
gc.collect()
print(f"✅ Phi-3-vision model conversion finished. You can find results in {output_dir}")
print(f"✅ {model_name} model conversion finished. You can find results in {output_dir}")


class OvPhi3Vision(GenerationMixin):
Expand Down
Loading