[!WARNING] Research prototype, not a medical device. This adapter has not been clinically validated. Do not use it to inform patient care.
MedReason is a LoRA adapter for Qwen2.5-3B-Instruct fine-tuned on medical-o1-reasoning-SFT. Given a patient vignette, it writes its reasoning inside <think> tags and then commits to a concise clinical answer.
| Base model | Qwen2.5-3B-Instruct, 4-bit |
| Method | QLoRA, rank 16, alpha 16, dropout 0.05 |
| Status | Converged at Epoch 0.97 (early stop on plateau) |
Evaluated on a sealed test set of 1,954 unseen rows.
| Model | Sealed Test Loss | Improvement |
|---|---|---|
| Base Qwen2.5-3B | 1.9360 | Baseline |
| MedReason LoRA | 1.4092 | -0.5268 (27% drop) |
Colab disconnects frequently. We implemented a custom resumption protocol (hub_strategy="every_save", explicit force-push) to restore optimizer state.
TrainerCallback)A custom callback gracefully halts training at 105 minutes.
Patched the tokenizer with {% generation %} tags to ensure loss is only calculated on the <think> trace.
Rigorous 80/10/10 split with zero exact-match or semantic overlap.
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = AutoModelForCausalLM.from_pretrained("unsloth/Qwen2.5-3B-Instruct-bnb-4bit", device_map="auto")
tok = AutoTokenizer.from_pretrained("unsloth/Qwen2.5-3B-Instruct-bnb-4bit")
model = PeftModel.from_pretrained(base, "Varun95/medical-qwen-lora")
SYSTEM = ("You are a Clinical Decision Support AI. Analyze the patient information "
"methodically before providing a structured clinical summary.")
messages = [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": "A 45-year-old male presents with sudden chest pain..."},
]
ids = tok.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
out = model.generate(input_ids=ids, max_new_tokens=1500, temperature=0.7, top_p=0.9, do_sample=True)
text = tok.decode(out[0][ids.shape[1]:], skip_special_tokens=True)
reasoning, _, answer = text.partition("</think>")
print(answer.strip())
| Day / Step | Eval Loss | Drop | Qualitative Evolution |
|---|---|---|---|
| Day 1 (570) | 1.4324 |
Baseline | Learned the structure. Began outputting <think> tags. |
| Day 2 (1,038) | 1.4116 |
-0.0208 | Learned differential diagnosis. |
| Day 3 (1,529) | 1.3987 |
-0.0129 | Deepened clinical accuracy. |
| Day 4 (1,900) | 1.3899 |
-0.0088 | Reached Optimal Fit. Early stopped as loss rose. |
The Law of Diminishing Returns: Stopping at step 1,900 prevented catastrophic overfitting.
19,526 examples remained after cleaning. Split 80/10/10: 15,620 train / 1,952 val / 1,954 test. Test split untouched.
adapter_model.safetensors 120 MBcheckpoint-1038/adapter_model.safetensors 120 MBlast-checkpoint/adapter_model.safetensors 120 MBcheckpoint-1038/optimizer.pt 63 MBlast-checkpoint/optimizer.pt 63 MBcheckpoint-1038/rng_state.pth 14.6 kBlast-checkpoint/rng_state.pth 14.6 kBcheckpoint-1038/training_args.bin 6.2 kBlast-checkpoint/training_args.bin 6.2 kBtraining_args.bin 6.2 kBcheckpoint-1038/scheduler.pt 1.5 kBlast-checkpoint/scheduler.pt 1.5 kBcheckpoint-1038/scaler.pt 1.4 kBlast-checkpoint/scaler.pt 1.4 kBunsloth/Qwen2.5-3B-Instruct-bnb-4bit