CoolFace
Modelpublic

BrainHealthAI/MedQA-Llama3.1-8B-SFT-Big

sourceHugging Facellama3.1updated 5mo agoView on Hugging Face
0likes6downloads
Model Card

MedQA-Llama3.1-8B-SFT-Big

QLoRA fine-tune of Llama-3.1-8B-Instruct on 50,000 trilingual medical Q&A (EN, FR, Moroccan Darija) augmented with the Dorosz Causal Knowledge Graph. Part of the BRAIN HEALTH / Operation HELIX-FT project.

Output format: model wraps the final answer in <answer>...</answer> and replies in the same language as the question (EN, FR, or Darija).

Training data

ItemValue
Source`Williamsanderson/MedQA-Darija-MultiLingual`
Total trilingual-complete rows102,057
Training subset (this run)50,000 stratified by specialty_id
Specialties covered57 (~877 samples / specialty, balanced)
Held-out eval split1,000 (random 2%)
LanguagesEnglish, French, Moroccan Darija (round-robin per row)
KG augmentationDorosz Causal KG — 348 drug terms, 34,344 edges (route, indication, contraindication, dosage) prepended to user message when drug mentions are detected in the gold answer

Training recipe (QLoRA)

SettingValue
Base modelmeta-llama/Llama-3.1-8B-Instruct
Quantization4-bit NF4 + double quant (Dettmers et al. 2023)
Compute dtypebfloat16
LoRA rank64
LoRA α / dropout128 / 0.1
LoRA target modulesqproj, kproj, vproj, oproj, gateproj, upproj, down_proj
Trainable parameters167,772,160 / 8,198,033,408 (2.05%)
Effective batch size16 (perdevice 2 × gradaccum 8)
Learning rate2e-4, cosine schedule
Warmup ratio0.03
Max gradient norm1.0
Optimizerpagedadamw8bit
Max sequence length2048
Epochs (planned / actual)3 / 2.20 (early-stopped on eval_loss patience=3)
HardwareRunPod L40S 48 GB (Ada, 18176 CUDA cores)
Total training time13.86 hours (49895s)
Throughput2.95 samples/sec, 0.184 steps/sec
Total FLOPs2.41e+18

Training metrics

MetricValue
Train samples seen49,000
Eval samples (held-out)1,000
Best eval loss ⭐0.7685 (epoch 1.96, step ~5860)
Final eval loss0.8210 (overfit indicator)
Final train loss0.4443
Average train loss0.7405
Final epoch reached2.20 / 3 (early stop)
Total optimizer steps6750

The eval loss reached its minimum around step 5860 (epoch 1.96) at 0.7685. Beyond epoch 2.0 the model showed gradual overfitting (evalloss ↑ to 0.82 at epoch 2.20). The `loadbestmodelat_end=True` callback ensures the published adapter is the best checkpoint, not the final one.

Training curves

Training curves (loss / lr / grad_norm)

Evaluation metrics over training

GPU utilization & memory

Usage

python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch

base = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-3.1-8B-Instruct",
    torch_dtype=torch.bfloat16, device_map="auto",
)
model = PeftModel.from_pretrained(base, "BrainHealthAI/MedQA-Llama3.1-8B-SFT-Big")
tok = AutoTokenizer.from_pretrained("BrainHealthAI/MedQA-Llama3.1-8B-SFT-Big")

SYSTEM_FR = (
    "Vous êtes un assistant médical rigoureux. Répondez TOUJOURS en français. "
    "Raisonnez d'abord entre <think>...</think>, puis donnez la réponse finale "
    "entre <answer>...</answer>."
)

msgs = [
    {"role": "system", "content": SYSTEM_FR},
    {"role": "user",   "content": "Question : Quels sont les symptômes du diabète de type 2 ?"},
]
inputs = tok.apply_chat_template(msgs, return_tensors="pt", add_generation_prompt=True).to(model.device)
out = model.generate(inputs, max_new_tokens=512, do_sample=False)
print(tok.decode(out[0], skip_special_tokens=True))

For Darija (Arabic-script) questions, the model replies in Arabic-script Darija. For English questions, in English. The system prompt MUST instruct the language explicitly to avoid drift.

Companion model

For comparison, see `Williamsanderson/MedQA-Llama3.1-8B-SFT-Small` — trained on a different (smaller, single-language) corpus without KG augmentation.

Limitations

  • —Prototype R&D only — not a certified medical device. Always defer to a qualified physician.
  • —Possible hallucinations despite fine-tuning. Confidence calibration not yet evaluated.
  • —Darija outputs use Arabic script. Quality is uneven across the long tail of rare specialties (only ~877 trilingual samples / specialty).
  • —Training stopped at 2.20 epochs (early stop). A full 3-epoch run might marginally improve eval performance.

References

  • —QLoRA: Dettmers, T., Pagnoni, A., Holtzman, A., & Zettlemoyer, L. (2023). QLoRA: Efficient Finetuning of Quantized LLMs. NeurIPS 2023. arXiv:2305.14314
  • —LoRA: Hu et al. (2022). arXiv:2106.09685
  • —Llama-3.1: Grattafiori et al. (2024). arXiv:2407.21783
  • —BRAIN HEALTH / Operation HELIX-FT — internal project document, MVP 2026.

Citation

bibtex
@misc{medqa_sft_big_2026,
  title  = { MedQA-Llama3.1-8B-SFT-Big: Trilingual medical QA via QLoRA SFT on Llama-3.1-8B with Dorosz KG },
  author = { BRAIN HEALTH project — Operation HELIX-FT },
  year   = { 2026 },
  url    = { https://huggingface.co/BrainHealthAI/MedQA-Llama3.1-8B-SFT-Big }
}