CoolFace
Modelpublic

adityag-india/Llama-3.1-8B-Medical-o1-LoRA

sourceHugging Facellama3.1updated 12d agoView on Hugging Face
0likes16downloads
Model Card

Llama-3.1-8B-Medical-o1-LoRA

A LoRA adapter for Llama 3.1 8B Instruct, supervised fine-tuned on medical-o1-reasoning-SFT to produce explicit step-by-step clinical reasoning inside <think> tags before committing to an answer.

Built with Llama.

Not for clinical use. This is a research artifact. It is not a medical device, has not been clinically validated, and its outputs should not inform patient care. It will produce fluent, confident, and sometimes wrong medical claims.

Usage

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

BASE = "meta-llama/Llama-3.1-8B-Instruct"
ADAPTER = "<your-username>/Llama-3.1-8B-Medical-o1-LoRA"

tok = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(BASE, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, ADAPTER)

messages = [
    {"role": "system", "content":
     "You are a medical expert. Reason carefully through the clinical question "
     "step by step inside <think> tags, then give your final answer."},
    {"role": "user", "content": "<your clinical question>"},
]
enc = tok.apply_chat_template(messages, add_generation_prompt=True,
                              return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**enc, max_new_tokens=768, do_sample=True,
                     temperature=0.6, top_p=0.9)
print(tok.decode(out[0][enc["input_ids"].shape[-1]:], skip_special_tokens=True))

The system prompt above is the one used during training. Results degrade noticeably without it.

Training

MethodLoRA, bf16 base (no quantization)
Rank / alpha / dropout32 / 64 / 0.05
Target modulesq, k, v, o, gate, up, down
Trainable params83.9M (1.03%)
Max sequence length2048
Effective batch size16 (4 × 4 grad accum)
Learning rate1e-4, cosine, 75 warmup steps
Optimizeradamwtorchfused
Epochs2 (2,414 steps)
Hardware1 × RTX 5090 32GB
Wall clock3h 28m
Peak VRAM26.6 GiB

Training examples were formatted as the dataset Question as the user turn, and <think>{Complex_CoT}</think>\n\n{Response} as the assistant turn. Loss was masked over the prompt so that only completion tokens were trained.

Results

Loss
Train (final)1.17
Eval (final)1.249

Loss plateaued at roughly epoch 1.5 and was flat thereafter; a third epoch is unlikely to help at this adapter rank.

Known limitations

  • —Trained on 19.7k examples at 2048 tokens; longer chains of thought in the source data were truncated, so very long reasoning traces are under-represented.
  • —Evaluated only by held-out loss and qualitative inspection. No benchmark scores (MedQA, PubMedQA, MMLU-medical) were run.
  • —Inherits the biases and knowledge cutoff of the base model.
  • —English only (en split).

License

Governed by the Llama 3.1 Community License. The training dataset is Apache 2.0.