Downloads · 30 days
28
10% of all-time downloads
philip11/xphil-gemma-4-E4B
xphil-gemma-4-E4B is a text generation model from philip11. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
What Google's AMIE does in the cloud — offline, in Tamil, on a ₹8,000 phone.
Downloads · 30 days
28
10% of all-time downloads
All-time downloads
277
Public
Repo size
10.4 GB
Likes
0
Public
Click a slice to open those files.
.gguf10.2 GB · 98%
From the Hugging Face model README
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.
| 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 |
unsloth/gemma-4-E4B-it (Gemma 4 E4B, 4.5B dense)No LLM imagined any training data. xphil uses a 3-layer architecture:
37,892 training samples (13,945 image + 23,947 text) through 5 quality gates:
| 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 |
| 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 |
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"
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))
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.
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.
| 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.
xphil is a caregiver-support and educational tool. It is designed to:
xphil is NOT a medical device and does NOT provide medical advice. Always consult a licensed healthcare professional for medical decisions.
crisis_flag=trueBuilt 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.
@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.}
}