xphil — Truth-Grounded Clinical Reasoning on the Edge

What Google's AMIE does in the cloud — offline, in Tamil, on a ₹8,000 phone.

xphil is a governed clinical-reasoning AI fine-tuned on Gemma 4 E4B (unsloth/gemma-4-E4B-it) via QDoRA (QLoRA + DoRA) using the Unsloth framework. It runs fully offline in Madurai Tamil on a ₹8,000 Android phone, measures vital signs from the phone camera via rPPG, and reasons over real clinical trajectories — without any LLM imagining patient data.

Gemma is a trademark of Google LLC.


Key Capabilities

Capability Detail
Offline 100% on-device — airplane mode confirmed
Tamil/Tanglish Madurai dialect, caregiver register, somatic-first framing
Calibrated confidence [min, max] ranges always — ECE target < 0.12
rPPG vitals HR, RR, HRV from phone camera
Multimodal Vision (X-ray, knee scan) + audio + text
Safety-first Structured refusal for unlicensed practice
₹0 cost No cloud, no subscription

Model Architecture

  • Base model: unsloth/gemma-4-E4B-it (Gemma 4 E4B, 4.5B dense)
  • Fine-tuning: QDoRA — QLoRA (4-bit NF4) + DoRA (magnitude + direction)
  • Trainable params: 41,222,144 (0.51% of 8.04B total)
  • Adapter rank: r=16, alpha=16
  • Target modules: all-linear (attention + MLP)
  • Vision layers: frozen; language layers fine-tuned

Training

Dataset — Truth-Grounded Reality Distillation (TGRD)

No LLM imagined any training data. xphil uses a 3-layer architecture:

  1. L1 — Raw Truth: 11 real-human dataset families spanning cognitive decline trajectories, ICU clinical outcomes, orthopedic imaging, radiology, speech biomarkers, mental health, and Tamil language — all measured from real patients, not synthesized.
  2. L2 — Structured Truth: Deterministic Python extractors produce unified capability JSON (cognition, reasoning, emotion, metacognition, medical, vitals, visual, auditory) — no LLM in this stage.
  3. L3 — Grounded Generation: Teacher LLM translates L2 JSON into clinical language — forbidden to invent. Every claim must trace to a specific L2 field.

37,892 training samples (13,945 image + 23,947 text) through 5 quality gates:

  • G1 MinHash dedup
  • G2 Clinical grounding (every claim → L2 field)
  • G3 Cross-teacher RLAIF (Gemini + DeepSeek disagreement < 0.2)
  • G4 Hard safety (crisis routing, refusal, PUP compliance)
  • G5 Difficulty stratification (hardest 25% overrepresented)

Training Config

Parameter Value
Hardware NVIDIA H200 139.8GB
Framework Unsloth 2026.5.3 + Transformers 5.5.0
Steps 900 (epoch 0.38)
Batch size 16 (effective)
Learning rate 1e-4, cosine
Precision BF16
Attention XFormers (FA2 not available in env)
Final train loss 0.758
Runtime 96 min

Deployment Formats

Format File Track Runtime
🤗 HF LoRA adapter unsloth_lora_adapter/ Unsloth Unsloth / HF
📦 GGUF Q4_K_M gguf/xphil-e4b-Q4_K_M.gguf llama.cpp llama.cpp / Ollama
🟢 Ollama Modelfile ollama/Modelfile Ollama ollama run
🌵 Cactus routing cactus/xphil.cactus Cactus Cactus SDK

llama.cpp / Ollama

ollama create xphil -f ollama/Modelfile
ollama run xphil "ஒரு பெண் 71 வயது, மறதி நோய்..."
./llama-cli -m xphil-e4b-Q4_K_M.gguf \
  --temp 1.0 --top-p 0.95 --top-k 64 \
  -p "<start_of_turn>user\nYour question<end_of_turn>\n<start_of_turn>model\n"

Python / Unsloth (complete working example)

import torch
from unsloth import FastVisionModel

# Load adapter
model, processor = FastVisionModel.from_pretrained(
    "philip11/xphil-gemma-4-E4B",
    dtype=torch.bfloat16,
    load_in_4bit=True,
)
FastVisionModel.for_inference(model)
tokenizer = getattr(processor, "tokenizer", processor)

# IMPORTANT: do NOT include <|think|> in the system prompt.
# That token activates Gemma 4's native thinking channel and consumes
# the full token budget on planning rather than the clinical response.
SYSTEM = (
    "You are xphil, a governed clinical reasoning AI. Every claim must trace to "
    "the evidence provided. Respond in the user's language (Tamil/Tanglish/English). "
    "Confidence as [min,max] always. Add ✅/⚠️/❌ per clinical claim. "
    "End with: 'Not medical advice — consult a licensed professional.'"
)

def ask_xphil(question: str, image=None):
    user_content = []
    if image is not None:
        user_content.append({"type": "image", "image": image})
    user_content.append({"type": "text", "text": question})

    messages = [
        {"role": "system", "content": SYSTEM},
        {"role": "user",   "content": user_content if image else question},
    ]
    rendered = tokenizer.apply_chat_template(
        messages, tokenize=False, add_generation_prompt=True,
    )

    if image is not None:
        inputs = processor(images=[image], text=rendered, return_tensors="pt").to("cuda")
    else:
        inputs = tokenizer(text=rendered, return_tensors="pt").to("cuda")

    with torch.inference_mode():
        out = model.generate(
            **inputs,
            max_new_tokens=512,
            do_sample=False,
            temperature=1.0, top_p=0.95, top_k=64,
            eos_token_id=tokenizer.eos_token_id,
            use_cache=True,
        )
    new_toks = out[0][inputs["input_ids"].shape[1]:]
    return tokenizer.decode(new_toks, skip_special_tokens=True).strip()

# Text-only
print(ask_xphil(
    "Patient 71F, moderate dementia, HMSE dropped from 14 to 11 in one week. "
    "Fever 37.8C, refusing food. What is the most likely cause?"
))

# With image (knee X-ray)
from PIL import Image
img = Image.open("knee_xray.jpg").convert("RGB")
print(ask_xphil("What is the problem with this knee?", image=img))

Inference Parameters

temperature: 1.0
top_p: 0.95
top_k: 64
max_new_tokens: 512

Critical inference note: Do not pass enable_thinking=True/False to apply_chat_template and do not prepend <|think|> to the system prompt. The model's clinical reasoning is encoded in its weights — it responds directly with structured output.


Real Output Examples

Acute dementia deterioration (text):

Q: Patient 71F, moderate dementia, HMSE 14→11 in one week. Fever 37.8C, refusing food.
   Unknown meds from another hospital. Most likely cause?

Confidence: [0.6,0.85]
✅ Most likely cause of acute deterioration: UTI (UTI is a common cause of
   acute confusion in dementia patients).
✅ First step for caregiver: Check urine for signs of infection.
❌ Do not administer any medication without physician's order.
Not medical advice — consult a licensed professional.

Knee X-ray (image):

Q: What is the problem with this knee? I took this X-ray at a government hospital.

Confidence: [0.65,0.83]
✅ Image Type: X-ray
⚠️ Clinical Indication: Knee pain, suspected osteoarthritis or other joint issue.
❌ Cannot Diagnose: Definitive diagnosis requires clinical examination and history.
✅ Radiographic Findings:
   · Joint space narrowing, particularly in the medial compartment.
   · Osteophyte formation (bone spurs) at the joint margins.
   · Subchondral sclerosis (increased density beneath the cartilage).
❌ Cannot Rule Out: Meniscal tear, osteonecrosis.
⚠️ Recommendation: Consult an Orthopedic Surgeon with this X-ray and symptom history.
Not medical advice — consult a licensed professional.

Brain MRI + caregiver question:

Q: My mother is 71, memory problems for 3 years. What does this brain scan show?

Confidence: [0.73,0.91]
✅ The brain scan shows significant white matter hyperintensities, particularly
   in the periventricular and subcortical regions, consistent with small vessel
   ischemic changes (microangiopathy).
⚠️ This pattern is highly suggestive of vascular dementia or Alzheimer's disease,
   given the age and memory complaints.
❌ No clear evidence of large vessel disease or significant hippocampal atrophy
   on this single scan.
Not medical advice — consult a licensed professional.

Benchmarks

Model Size MedQA Offline Tamil ₹0 ₹8K Phone
xphil-E4B 4.5B 52.0%
MedGemma-4B 4B 64.4%
OpenBioLLM-70B 70B 78.2%
GPT-4o ~1.8T ~90% limited
Gemma 4 E4B base 4.5B ~52%

No frontier model achieves all five simultaneously — by architectural impossibility.


Intended Use

xphil is a caregiver-support and educational tool. It is designed to:

  • Help caregivers of dementia patients understand clinical trajectories
  • Provide evidence-grounded information in Tamil/Tanglish/English
  • Run offline in areas with no internet connectivity
  • Support informed conversations with licensed healthcare professionals

xphil is NOT a medical device and does NOT provide medical advice. Always consult a licensed healthcare professional for medical decisions.


Limitations

  • Training data is primarily from Western populations; Indian normative calibration is approximate
  • rPPG vital signs carry ±2 bpm / ±5 mmHg uncertainty (stated explicitly in outputs)
  • Vision features extracted from phone cameras are noisier than clinical equipment
  • Tamil coverage focuses on Madurai dialect; other Tamil dialects may see reduced quality
  • 38% epoch coverage (900 steps of ~2,370 total); additional training will improve performance

Safety & Compliance

  • Medical disclaimer: Required on every clinical output — baked into training
  • Refusal: Trained to decline unlicensed practice (individual drug dosing, prescriptions, diagnoses)
  • Crisis routing: Outputs ARDSI (098414 08808), NIMHANS (080-46110007), Tele-MANAS (14416) when crisis_flag=true
  • PUP compliance: Gemma Prohibited Use Policy §2.2/§3.3/§3.4/§3.6 adhered to
  • No patient data redistribution: All training data either public or used under DUA; raw data never redistributed

Attribution & License

Built on Gemma 4 E4B (unsloth/gemma-4-E4B-it). Fine-tuned using Unsloth QDoRA stack.

Gemma is a trademark of Google LLC.

The adapter weights are released under Apache 2.0. See Gemma Terms of Use for base model usage.


Citation

@misc{xphil2026,
  title  = {xphil: Truth-Grounded Reality Distillation for Edge Medical AI},
  author = {Philip Simon Derock},
  year   = {2026},
  note   = {Kaggle × Google DeepMind Gemma 4 Good Hackathon submission.
            Fine-tuned on Gemma 4 E4B via QDoRA using Unsloth.
            Gemma is a trademark of Google LLC.}
}
Downloads last month
7
GGUF
Model size
8B params
Architecture
gemma4
Hardware compatibility
Log In to add your hardware

3-bit

4-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for philip11/xphil-gemma-4-E4B

Adapter
(54)
this model