PhiLLM-School
PhiLLM-School is a from-scratch, synthetic-math, sparse mixture-of-experts language model. It uses a frozen shared transformer trunk, an always-on shared expert, and 111 routed expert columns. Only the trunk, shared expert, router, and top-2 experts are loaded at inference time.
- Total parameters: 9.108B
- Active parameters: 264.4M per token
- Context: 512 tokens
- Tokenizer: digit-split BPE, vocabulary 1,109
- Training data: 100% synthetic and verifier-checked
- Model license: Apache-2.0
- Data license: CC BY 4.0 (if data is included)
See MODEL_CARD.md and DATA_CARD.md for architecture, evaluation, limitations, and
provenance.
Release layout
README.md
LICENSE
MODEL_CARD.md
DATA_CARD.md
THIRD_PARTY_NOTICES.md
SHA256SUMS.model
model/
model_config.json
trunk.safetensors
shared.safetensors
router.safetensors
router_meta.json
registry.json
tokenizer.json
experts/*.safetensors
data/ optional
shards/*.jsonl
tokenizer.json
meta.json
src/phillm/ model, generation, tokenizer, registry code
pyproject.toml
Install
python -m pip install -e .
or install the runtime dependencies directly:
python -m pip install torch numpy tokenizers safetensors sympy tqdm
Chat
Run from the release root:
python -m phillm.inference.chat \
--ckpt-dir model \
--data model \
--registry model/registry.json \
--dtype bfloat16
The registry paths are resolved relative to model/registry.json, so the command works
from any directory.
Python usage
from pathlib import Path
import torch
from phillm.config import load_model_configs
from phillm.data.tokenizer import load_tokenizer
from phillm.model.moe import PhiLLM
from phillm.inference.generate import build_prompt_ids, extract_answer, generate
ckpt = Path("model")
trunk, expert_cfg, router_cfg = load_model_configs(ckpt / "model_config.json")
model = PhiLLM(trunk, expert_cfg, router_cfg)
model.load_trunk(ckpt / "trunk.safetensors")
model.load_shared(ckpt / "shared.safetensors")
model.load_experts_from_registry(ckpt / "registry.json")
model.load_router(ckpt / "router.safetensors")
model.max_loaded_experts = 2
model = model.to(device="cuda", dtype=torch.bfloat16).eval()
tok = load_tokenizer(ckpt / "tokenizer.json")
ids, routes, weights = generate(
model,
build_prompt_ids(tok, "What is 12 + 7?"),
max_new_tokens=256,
temperature=0.0,
)
print(extract_answer(tok, ids))
Evaluation
The published numbers are synthetic-template evaluations, not GSM8K/MATH/AMC/AIME:
| Probe | Exact match |
|---|---|
| In-distribution, model-only | 97.57% |
| In-distribution, tool-assisted | 99.37% |
| Paraphrased | 93.09% |
| OOD difficulty-shifted | 90.86% |
See MODEL_CARD.md for confidence intervals and per-core results.
Hardware
- Inference: 6 GB laptop GPU class
- Only top-2 experts are loaded at a time
- Expert weights are memory-mapped from disk
- Keep roughly 40 GB free for the full expert set and runtime overhead
Limitations
- Synthetic template math only; not a general-purpose model.
- Not comparable to public math benchmarks.
- OOD routing is weak (33.3% top-1 on the shifted-difficulty probe).
- Not safety-tuned; do not use for high-stakes decisions.
PhiLLM is an independent project and is not affiliated with Microsoft or the Phi model family.