adityag-india/Llama-3.1-8B-Medical-o1-LoRA
016
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
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
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 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 (
ensplit).
License
Governed by the Llama 3.1 Community License. The training dataset is Apache 2.0.
