Qwen2.5-7B-Instruct-AlpaCare-MedInstruct-QLoRA
medical language model
2 min readupdated
This model is a fine-tuned version of Qwen/Qwen2.5-7B-Instruct (7.62 billion parameters) trained on the cleaned lavita/AlpaCare-MedInstruct-52k medical instruction dataset. Fine-tuning was performed using QLoRA (efficient tuning of quantized models using small adapters) with loss masking applied only to assistant responses. The model is designed for medical research and educational tasks, including explaining clinical terms and working with educational medical texts.
Key features
- Built on the powerful Qwen2.5-7B-Instruct architecture.
- Trained on a filtered and cleaned dataset of medical instructions.
- Utilizes the QLoRA approach with NEFTune regularization to improve generation quality.
- Supports the standard ChatML chat format and prompt templates.
What you can do
- Run the model locally or on Google Colab for educational experiments.
- Explore answers to medical questions and simplified terminology.
- Perform benchmarking and comparison against the base model using ROUGE-L and perplexity metrics.
Example
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "p-sahas/Qwen2.5-7B-Instruct-AlpaCare-MedInstruct-QLoRA-r16-5k"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else torch.float16,
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a knowledgeable, empathetic medical AI assistant for educational purposes. Provide clear, accurate, evidence-based explanations."},
{"role": "user", "content": "Explain the difference between Type 1 and Type 2 diabetes in simple terms."},
]
inputs = tokenizer.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
outputs = model.generate(inputs, max_new_tokens=256, do_sample=False)
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
Read more
DetailsBenchmarks: validation perplexity dropped from 2.99 to 2.0, ROUGE-L F1 increased to 0.4134 (+0.1217).
Hardware requirements: GPU with BF16 support (such as an NVIDIA L4); training took about 52 minutes on 1x L4.
Limitations: the model is not a medical device, is not intended for real-world diagnosis or treatment, and operates in English only.










Comments