CoolFace
Modelpublic

debajyotidasgupta/eu-halt-phi4-14b

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes21downloads
Model Card

EU-Halt heads for microsoft/phi-4 (default)

Lightweight epistemic-uncertainty detector: K=4 prediction heads sharing the frozen microsoft/phi-4 trunk. Configuration: mid_dim=256, K=4 (default).

Calibrate the sign before deploying. The direction of the disagreement signal is trunk-family-specific: on some families it rises on out-of-distribution input, on others (Llama-70B-class, gpt-oss-120B) it falls. Score ~50 known-ID and ~50 known-OOD prompts once and check which direction separates. Details: the paper and repo below.

Paper: When Uncertainty Lies (CAISc 2026, oral) · Code: github.com/debajyotidasgupta/eu-halt

Quick start

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from eu_halt import attach

model = AutoModelForCausalLM.from_pretrained(
    "microsoft/phi-4", torch_dtype=torch.bfloat16,
).to("cuda").eval()
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-4")

uncertainty = attach(
    model,
    heads_repo="debajyotidasgupta/eu-halt-phi4-14b",
    mid_dim=256,
)
print(uncertainty("Who founded Quora in 2008?", tokenizer))
# Higher = more uncertain.

Files in this repo

  • model.safetensors — the K=4 head weights (preferred format; config embedded as metadata).
  • config.json — head geometry: numheads, middim, sourcelayers, basemodel, dims.
  • heads_final.pt — the original torch checkpoint (kept for backward compatibility).
  • heads_step{500,1000,1500,2000,2500}.pt — intermediate checkpoints (where uploaded).
  • source_layers.json — the K=4 trunk-layer indices the heads read from.
  • history.json — per-step loss + disagreement + GPU stats.

Training

  • Dataset: HuggingFaceFW/fineweb-edu (streaming).
  • ~2-5M tokens, batchsize 2-4, seqlen 512, ~2000-2500 steps.
  • AdamW (lr 3e-4 to 5e-4), 100-200 warmup steps.
  • K=4 heads, middim=256, trainingnoise_std=0.01, dropout=0.1 (or both 0 for quiet variants).
  • Single GPU (~10-15 min on RTX A5000/A6000/L40S).

Evaluation

OOD AUROC (id vs ood), 1364 samples total:

SignalAUROC95% CI
disagreement0.8121[0.7807, 0.8396]
entropy0.4480[0.4119, 0.4826]
lasttokenunc0.4163[0.3714, 0.4599]
mahalanobis0.7235[0.6464, 0.7991]
targ_margin0.4435[0.4039, 0.4874]
etc_trend0.3454[0.3115, 0.3800]
llm_check0.0968[0.0798, 0.1142]
mc_dropout0.4834[0.4458, 0.5161]
rauq0.1021[0.0828, 0.1206]
p_truenan[nan, nan]
semantic_entropynan[nan, nan]
semanticentropynlinan[nan, nan]
eigenscorenan[nan, nan]

Best signal: disagreement

Intended use

  • Hallucination flagging at inference time (score before / during generation).
  • Dynamic-RAG gating (retrieve iff uncertainty > τ).
  • Selective prediction / risk-coverage trade-offs.
  • Token-level uncertainty visualization via uncertainty.per_token(text, tokenizer).

Limitations

  • No fine-tuning of the trunk — only the auxiliary heads are trained.
  • Heads are trained on web text. Specialized domains (medical, legal) may need a domain-specific recalibration.
  • For Gemma's 256k vocab, head output projection is ~70-100M params per head — still small relative to the trunk.

License

Apache-2.0 for the heads. The trunk model microsoft/phi-4 retains its own license (Qwen3 / Llama-3 / Phi / Gemma).

Citation

bibtex
@inproceedings{dasgupta2026euhalt,
  author    = {Dasgupta, Debajyoti and Mondal, Arijit and Chakrabarti, Partha P.},
  title     = {When Uncertainty Lies: How Model Scale and Layer Geometry Quietly
               Invert the Meaning of Internal Disagreement in Large Language Models},
  booktitle = {1st Conference For AI Scientists (CAISc)},
  year      = {2026},
  url       = {https://huggingface.co/debajyotidasgupta/eu-halt-phi4-14b},
}