Downloads · 30 days
17
16% of all-time downloads
vishnu0967/medgemma-1.5-4b-it-openvino-int4
medgemma-1.5-4b-it-openvino-int4 is a image-text-to-text model from vishnu0967. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for optimum. The card lists the license as gemma.
This repository contains a highly optimized, 4-bit quantized OpenVINO Intermediate Representation (IR) version of Google's MedGemma-1.5-4b-it.
Downloads · 30 days
17
16% of all-time downloads
All-time downloads
109
Public
Repo size
3.5 GB
Likes
0
Public
Click a slice to open those files.
.bin3.4 GB · 99%
From the Hugging Face model README
This repository contains a highly optimized, 4-bit quantized OpenVINO Intermediate Representation (IR) version of Google's MedGemma-1.5-4b-it.
It was quantized using Intel's Neural Network Compression Framework (NNCF) via Hugging Face optimum-intel to enable ultra-lightweight local deployment exclusively on CPUs. By leveraging OpenVINO, this version drastically minimizes RAM footprints and executes inference smoothly on modern CPU architectures without risking Out-Of-Memory (OOM) memory crashes.
int4_asym): Offers a fantastic balance between medical description correctness and token generation latency.Before using the model, ensure your Python environment has the optimized CPU runtimes installed. It is highly recommended to run this setup in a fresh block to prevent memory collision issues:
pip install --upgrade huggingface_hub optimum[intel] openvino nncf pillow --quiet
The following example demonstrates how to run medical image analysis locally using the quantized OpenVINO INT4 model on CPU.
from PIL import Image
import torch
from optimum.intel.openvino import OVModelForVisualCausalLM
from transformers import AutoProcessor, TextStreamer
MODEL_ID = "vishnu0967/medgemma-1.5-4b-it-openvino-int4"
print("Loading optimized 4-bit OpenVINO model directly from Hugging Face Hub...")
# Load model directly from Hugging Face onto CPU
model = OVModelForVisualCausalLM.from_pretrained(
MODEL_ID,
device="CPU",
ov_config={
"PERFORMANCE_HINT": "LATENCY",
"INFERENCE_NUM_THREADS": ""
}
)
# Load processor
processor = AutoProcessor.from_pretrained(MODEL_ID)
image = Image.open("/content/input.png").convert("RGB")
messages = [
{
"role": "system",
"content": [
{
"type": "text",
"text": "You are an expert radiologist."
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Analyze this medical image and explain any abnormalities."
},
{
"type": "image",
"image": image
}
]
}
]
prompt = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=False
)
inputs = processor(
text=prompt,
images=image,
return_tensors="pt"
)
streamer = TextStreamer(
processor,
skip_prompt=True,
skip_special_tokens=True
)
print("\nGenerating response on CPU...")
print("--- Radiologist Report ---")
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=520,
do_sample=False,
streamer=streamer
)
response = processor.decode(
outputs[0][inputs["input_ids"].shape[-1]:],
skip_special_tokens=True
)
print("\n--- Inference Finished ---")
int4_asym) generated with NNCF.PERFORMANCE_HINT="LATENCY" is recommended for interactive usage.max_new_tokens for longer medical reports.pip install --upgrade huggingface_hub optimum[intel] openvino nncf pillow transformers --quiet
from optimum.intel.openvino import OVModelForVisualCausalLM
from transformers import AutoProcessor
model = OVModelForVisualCausalLM.from_pretrained(
"vishnu0967/medgemma-1.5-4b-it-openvino-int4",
device="CPU"
)
processor = AutoProcessor.from_pretrained(
"vishnu0967/medgemma-1.5-4b-it-openvino-int4"
)