LLM Studio · how to run every open model, correctly Vol 01 · No 01 · 2026
Index/LLM Studio/Microsoft/Phi-4/Hugging Face Transformers · BF16
Hugging Face Transformers · BF16 · Cross-platform · CUDA + MPS + CPU

Phi-4 on Hugging Face Transformers at BF16

Slower than vLLM but universally supported. Works anywhere you can install PyTorch. The right choice for research and experimentation. Same memory as FP16. Better dynamic range for training; equivalent for inference.

At a glance The numbers

Model
Microsoft Phi-4
Family
Phi
Params
14B
License
MIT
Engine
Hugging Face Transformers
Quantization
BF16
Bytes per param
2
Platform
Cross-platform · CUDA + MPS + CPU

The command Copy and run

What Hugging Face Transformers expects you to type to serve Phi-4 at BF16. Adjust the paths for your filesystem; the structure holds.

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

tok = AutoTokenizer.from_pretrained("microsoft/phi-4")
model = AutoModelForCausalLM.from_pretrained(
    "microsoft/phi-4",
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

Why this quant The trade-off

BF16 — Same memory as FP16. Better dynamic range for training; equivalent for inference.

Expect to need around 32 GB of VRAM to hold the weights at this precision. This is a dense model: every parameter runs for every token. VRAM and compute both scale with the full 14B. Fits on Prosumer 48 GB — RTX 6000 Ada, 2× RTX 4090.

Common failures What breaks, and the fix

Out of memory
Add `device_map="auto"` or `torch_dtype=torch.bfloat16`; enable `low_cpu_mem_usage=True`.
Slow
Install flash-attn 2; set `attn_implementation="flash_attention_2"` on the model.
First-time download is massive
Set HF_HOME to a disk with capacity; consider `hf_transfer` for faster pulls.

Alternatives Other ways to run this model

About the model

Synthetic-data recipe; 14B that competes with 70B-class.

Open the full model page →