Most medical language models are trained to retrieve answers. LlamaTron RS1 MedThinker was trained to reason through them.
Built on Meta's Llama 3.2 1B Instruct and fine-tuned on 810,374 medical chain-of-thought samples, MedThinker doesn't just return a diagnosis — it works through the differential, explains the pathophysiology behind its conclusion, gives dose-specific treatment steps, and tells you exactly when to escalate care.
The reasoning pattern mirrors that of a junior physician presenting a case: structured, explainable, and clinically grounded.
Demo
Model Output — Step-by-Step Clinical Reasoning
LlamaTron RS1 MedThinker Output
Output Format
Every response follows a strict four-part clinical structure:
DIAGNOSIS Primary diagnosis with key differentials
REASONING Clinical logic, pathophysiology, and decision trail
IMMEDIATE TREATMENT Prioritised, dose-specific intervention steps
RED FLAGS Escalation criteria and emergency triggers
Example — Input:
3yo boy, barking cough, stridor, worse at night. Diagnosis and treatment?
Example — Output:
DIAGNOSIS: Viral croup (laryngotracheobronchitis).
Differentials: epiglottitis, foreign body aspiration, bacterial tracheitis.
REASONING: The classic triad of barking cough, inspiratory stridor, and nocturnal
worsening in a toddler is pathognomonic for croup. Caused by parainfluenza virus
producing subglottic edema. Nighttime worsening occurs due to supine positioning
increasing mucosal congestion. Age 6 months to 3 years is the peak incidence window.
Epiglottitis is deprioritised given the absence of drooling, tripod posturing,
or toxic appearance.
IMMEDIATE TREATMENT:
- Dexamethasone 0.6mg/kg PO/IM single dose (reduces subglottic edema within 2-6h)
- Nebulised epinephrine 5ml of 1:1000 if moderate-severe stridor present at rest
- Humidified cool air — supportive, reduces mucosal congestion
- Keep child calm — agitation significantly worsens stridor
- Oxygen via mask if SpO2 drops below 92%
RED FLAGS: Call emergency services immediately if stridor is present at rest and
not improving, child is drooling or cannot swallow, cyanosis appears, or the child
becomes exhausted. These indicate impending airway obstruction requiring intubation.
Each sample contains two components: the content (the answer) and the reasoning_content (the chain-of-thought trace that produced it). Training on both means the model internalised not just medical knowledge, but the structured thinking process behind clinical decision-making.
Dataset credit: Maziyar P.
Quickstart
Installation
pip install torch transformers accelerate
Inference
python
1import torch
2from transformers import AutoTokenizer, LlamaForCausalLM
34MODEL_PATH ="Rumiii/LlamaTron-RS1-MedThinker"56tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)7model = LlamaForCausalLM.from_pretrained(8 MODEL_PATH,9 torch_dtype=torch.bfloat16,10 device_map="auto",11)12model.eval()1314FEW_SHOT ="""CASE: 2yo girl, high fever, tugging right ear, irritable, not sleeping.
1516DIAGNOSIS: Acute otitis media (AOM). Differentials: otitis externa, teething.
1718REASONING: Unilateral ear tugging with fever and irritability in a toddler is the
19classic AOM presentation. Peak incidence at 6mo-2yr due to horizontal Eustachian
20tube anatomy impairing drainage.
2122IMMEDIATE TREATMENT:
23- Amoxicillin 90mg/kg/day divided BID x 10 days
24- Ibuprofen/paracetamol for pain and fever
25- Re-evaluate in 48-72h if no improvement
2627RED FLAGS: Refer immediately if mastoid swelling, facial palsy, or no improvement
28after 72h of antibiotics."""2930defask(question:str)->str:31 prompt =(32f"<|begin_of_text|>"33f"<|start_header_id|>system<|end_header_id|>\n"34f"You are LlamaTron RS1 MedThinker, a clinical medical assistant. "35f"Always use the structured format shown.<|eot_id|>"36f"<|start_header_id|>user<|end_header_id|>\n"37f"Answer this case using structured format:\n\n{FEW_SHOT}<|eot_id|>"38f"<|start_header_id|>assistant<|end_header_id|>\n{FEW_SHOT}<|eot_id|>"39f"<|start_header_id|>user<|end_header_id|>\nCASE: {question}<|eot_id|>"40f"<|start_header_id|>assistant<|end_header_id|>\n"41)42 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)43 input_len = inputs["input_ids"].shape[1]44with torch.no_grad():45 out = model.generate(46**inputs,47 max_new_tokens=400,48 temperature=0.35,49 top_p=0.85,50 do_sample=True,51 repetition_penalty=1.2,52 pad_token_id=tokenizer.eos_token_id,53)54 raw = tokenizer.decode(out[0][input_len:], skip_special_tokens=False)55for stop in["<|eot_id|>","<|end_of_text|>","<|start_header_id|>"]:56if stop in raw:57 raw = raw[:raw.index(stop)]58return raw.strip()5960# Run61print(ask("68yo woman, chest pain radiating to left arm, diaphoresis, nausea. BP 90/60, HR 110."))
Important Notes on Inference
This model benefits significantly from few-shot prompting. Because the fine-tuning dataset emphasised reasoning content over instruction-following format, providing a single worked example in the prompt before your real question enforces the structured output reliably. The quickstart code above includes this pattern — do not remove the FEW_SHOT block.
Recommended inference parameters:
Parameter
Value
Reason
temperature
0.35
Confident without hallucinating
top_p
0.85
Cuts low-probability tokens
repetition_penalty
1.2
Prevents reasoning loops
max_new_tokens
400-512
Sufficient for full structured response
Disclaimer
LlamaTron RS1 MedThinker is intended strictly for research and educational purposes. It is not a substitute for professional medical advice, clinical diagnosis, or treatment decisions. All outputs must be reviewed by a qualified medical professional before any clinical application. The authors accept no liability for decisions made on the basis of this model's outputs.