Instructions to use philip11/xphil-gemma-4-E4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use philip11/xphil-gemma-4-E4B with PEFT:
Task type is invalid.
- llama-cpp-python
How to use philip11/xphil-gemma-4-E4B with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="philip11/xphil-gemma-4-E4B", filename="gguf/xphil-e4b-Q3_K_M.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use philip11/xphil-gemma-4-E4B with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf philip11/xphil-gemma-4-E4B:Q3_K_M # Run inference directly in the terminal: llama cli -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf philip11/xphil-gemma-4-E4B:Q3_K_M # Run inference directly in the terminal: llama cli -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf philip11/xphil-gemma-4-E4B:Q3_K_M # Run inference directly in the terminal: ./llama-cli -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf philip11/xphil-gemma-4-E4B:Q3_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Use Docker
docker model run hf.co/philip11/xphil-gemma-4-E4B:Q3_K_M
- LM Studio
- Jan
- vLLM
How to use philip11/xphil-gemma-4-E4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "philip11/xphil-gemma-4-E4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "philip11/xphil-gemma-4-E4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/philip11/xphil-gemma-4-E4B:Q3_K_M
- Ollama
How to use philip11/xphil-gemma-4-E4B with Ollama:
ollama run hf.co/philip11/xphil-gemma-4-E4B:Q3_K_M
- Unsloth Studio
How to use philip11/xphil-gemma-4-E4B with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for philip11/xphil-gemma-4-E4B to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for philip11/xphil-gemma-4-E4B to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for philip11/xphil-gemma-4-E4B to start chatting
- Pi
How to use philip11/xphil-gemma-4-E4B with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "philip11/xphil-gemma-4-E4B:Q3_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use philip11/xphil-gemma-4-E4B with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default philip11/xphil-gemma-4-E4B:Q3_K_M
Run Hermes
hermes
- Atomic Chat new
- OpenClaw new
How to use philip11/xphil-gemma-4-E4B with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf philip11/xphil-gemma-4-E4B:Q3_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "philip11/xphil-gemma-4-E4B:Q3_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- Docker Model Runner
How to use philip11/xphil-gemma-4-E4B with Docker Model Runner:
docker model run hf.co/philip11/xphil-gemma-4-E4B:Q3_K_M
- Lemonade
How to use philip11/xphil-gemma-4-E4B with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull philip11/xphil-gemma-4-E4B:Q3_K_M
Run and chat with the model
lemonade run user.xphil-gemma-4-E4B-Q3_K_M
List all available models
lemonade list
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:
- 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.
- L2 — Structured Truth: Deterministic Python extractors produce unified capability JSON (cognition, reasoning, emotion, metacognition, medical, vitals, visual, auditory) — no LLM in this stage.
- 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
3-bit
4-bit