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)