Instructions to use convaiinnovations/medgemma-4b-ecginstruct-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use convaiinnovations/medgemma-4b-ecginstruct-lora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="convaiinnovations/medgemma-4b-ecginstruct-lora") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("convaiinnovations/medgemma-4b-ecginstruct-lora", device_map="auto") - PEFT
How to use convaiinnovations/medgemma-4b-ecginstruct-lora with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use convaiinnovations/medgemma-4b-ecginstruct-lora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "convaiinnovations/medgemma-4b-ecginstruct-lora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "convaiinnovations/medgemma-4b-ecginstruct-lora", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/convaiinnovations/medgemma-4b-ecginstruct-lora
- SGLang
How to use convaiinnovations/medgemma-4b-ecginstruct-lora with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "convaiinnovations/medgemma-4b-ecginstruct-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "convaiinnovations/medgemma-4b-ecginstruct-lora", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "convaiinnovations/medgemma-4b-ecginstruct-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "convaiinnovations/medgemma-4b-ecginstruct-lora", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use convaiinnovations/medgemma-4b-ecginstruct-lora with Docker Model Runner:
docker model run hf.co/convaiinnovations/medgemma-4b-ecginstruct-lora
MedGemma-4B ECGInstruct LoRA
Fine-tuned LoRA adapter for Google's MedGemma-4B-it model on the ECGInstruct dataset for automated ECG interpretation.
Model Description
This is a LoRA (Low-Rank Adaptation) fine-tuned version of google/medgemma-4b-it trained on the PULSE-ECG/ECGInstruct dataset containing 1.15M ECG instruction-following examples.
Developed by: convaiinnovations
Base Model: google/medgemma-4b-it
Training Infrastructure: AIRAWAT (C-DAC) - 8x NVIDIA A100 40GB GPUs
Training Duration: ~40 hours (1 epoch)
Final Token Accuracy: 88.23%
Training Details
Training Data
- Dataset: PULSE-ECG/ECGInstruct
- Samples: 1,154,110 training examples
- Image Sources: MIMIC-IV-ECG, PTB-XL, CODE-15%, and other ECG datasets
- Task: Vision-language instruction following for ECG interpretation
Training Procedure
Hardware:
- 8x NVIDIA A100 40GB GPUs (AIRAWAT supercomputer)
- Distributed training with PyTorch DDP
Hyperparameters:
- LoRA rank (r): 32
- LoRA alpha: 64
- LoRA dropout: 0.05
- Learning rate: 2e-4
- Batch size: 128 (effective)
- Optimizer: AdamW (fused)
- LR scheduler: Cosine with warmup
- Precision: bfloat16
- Gradient checkpointing: Enabled
Training Metrics:
- Final training loss: 10.997
- Mean token accuracy: 88.23%
- Entropy: 1.796
- Total tokens processed: 253,325,537
Usage
Installation
pip install transformers peft pillow torch
Loading the Model
from transformers import AutoModelForImageTextToText, AutoProcessor
from peft import PeftModel
from PIL import Image
# Load base model
base_model_id = "google/medgemma-4b-it"
model = AutoModelForImageTextToText.from_pretrained(
base_model_id,
torch_dtype="auto",
device_map="auto"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(
model,
"convaiinnovations/medgemma-4b-ecginstruct-lora"
)
# Load processor
processor = AutoProcessor.from_pretrained(base_model_id)
Inference Example
# Load ECG image
image = Image.open("ecg_image.png").convert("RGB")
# Prepare prompt
messages = [
{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": "Analyze this ECG and provide a detailed interpretation."}
]
}
]
# Process input
text = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
inputs = processor(text=[text], images=[[image]], return_tensors="pt", padding=True)
inputs = {k: v.to(model.device) for k, v in inputs.items()}
# Generate
outputs = model.generate(
**inputs,
max_new_tokens=512,
do_sample=False,
temperature=None,
top_p=None
)
# Decode
response = processor.decode(outputs[0], skip_special_tokens=True)
print(response)
Model Capabilities
This model can:
- ✅ Interpret 12-lead ECG images
- ✅ Identify cardiac abnormalities (arrhythmias, ischemia, hypertrophy, etc.)
- ✅ Generate detailed clinical reports
- ✅ Answer questions about ECG findings
- ✅ Provide diagnostic suggestions
Limitations
- Trained primarily on adult ECG data
- Should not replace professional medical diagnosis
- Performance may vary on ECG formats not seen during training
- Requires high-quality ECG images for optimal results
Ethical Considerations
⚠️ Medical Disclaimer: This model is intended for research and educational purposes only. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult qualified healthcare professionals for medical decisions.
Citation
If you use this model, please cite:
@misc{medgemma-ecginstruct-lora,
author = {convaiinnovations},
title = {MedGemma-4B ECGInstruct LoRA},
year = {2025},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/convaiinnovations/medgemma-4b-ecginstruct-lora}}
}
Acknowledgments
- Base Model: Google's MedGemma team
- Dataset: PULSE-ECG/ECGInstruct
- Infrastructure: AIRAWAT AI Innovation Challenge (C-DAC)
- Training Framework: HuggingFace Transformers, PEFT, TRL
License
Apache 2.0 (following base model license)