CoolFace
Modelpublic

aakthepaak/clinical-llm-r32

sourceHugging Faceotherupdated 7mo agoView on Hugging Face
0likes
Model Card

Clinical LLM — QLoRA Fine-Tune on MedQA (Llama 3.2 3B)

A QLoRA fine-tune of Meta's Llama 3.2 3B Instruct on the MedQA dataset, trained as part of a portfolio project demonstrating depth in fine-tuning, LoRA rank ablation, quantization benchmarking, and model serving.


Model Details

  • —Base model: meta-llama/Llama-3.2-3B-Instruct
  • —Fine-tuning method: QLoRA via Unsloth + PEFT + TRL
  • —Dataset: medalpaca/medicalmeadowmedqa (2,500 samples — 2,250 train / 250 val)
  • —Task: Multiple-choice clinical question answering (MedQA / USMLE-style)
  • —Hardware: Google Colab L4 GPU (23.7 GB VRAM)
  • —Unsloth version: 2026.3.4 | Transformers: 5.2.0

Training Configuration

ParameterValue
LoRA rank (r)32 (best checkpoint)
lora_alpha64
Target modulesqproj, kproj, vproj, oproj, gateproj, upproj, down_proj
lora_dropout0
Quantization4-bit (nf4) during training
Epochs3
Batch size2
Gradient accumulation8 (effective batch size 16)
Learning rate2e-4
Warmup steps50
Max sequence length2048

LoRA Rank Ablation Study

All runs trained on identical data and hyperparameters, varying only rank and loraalpha (convention: loraalpha = 2 × r).

Ranklora_alphaTrainable ParamsTrain LossAccuracyROUGE-L
Base (no fine-tune)———0.1000.128
r=486,078,464 (0.19%)1.16890.5600.319
r=81612,156,928 (0.38%)1.13890.5760.356
r=163224,313,856 (0.75%)1.10130.5600.342
r=3264~48M (1.50%)1.04960.5920.355

Key finding: r=32 fine-tune is ~6x more accurate than the base model. The base model's low score is largely a format compliance issue — it generates verbose explanations rather than the concise single-letter answer the benchmark expects.

Best checkpoint: r=32 → used for deployment.


Quantization Benchmark (merged r=32, L4 GPU)

QuantizationAvg LatencyAccuracy
4-bit0.458s0.588
fp160.583s0.596

4-bit is 27% faster with negligible accuracy loss — strong production argument for quantization.


Inference

python
from unsloth import FastLanguageModel
import torch

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="aakthepaak/clinical-llm-r32",
    max_seq_length=2048,
    load_in_4bit=True,
)
FastLanguageModel.for_inference(model)

prompt = """<|system|> You are a clinical medical assistant, answer the following question.
<|user|> {instruction}\n{question}
<|assistant|>"""

inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=30)
response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
print(response)

License

This model is a fine-tune of Meta's Llama 3.2 3B Instruct and is subject to the Llama 3.2 Community License. Use is permitted for research and commercial purposes under those terms.


Links

  • —WandB experiment tracking: https://wandb.ai/aakarsh3110-stevens-institute-of-technology/clinical-llm
  • —Base model: https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct
  • —Dataset: https://huggingface.co/datasets/medalpaca/medicalmeadowmedqa