Phi-4 Hardware: What 12GB and 16GB Cards Can Hold
Microsoft's Phi-4 is a 14-billion-parameter model. Its model card describes a dense decoder-only Transformer with a 16K-token context window, released on December 12, 2024. Dense means every weight is read for every token, so the memory math is simple: at 4-bit it fits a 12 GB graphics card. Using the whole context window on that card is where it gets tight.
The weights: about 10.4 GB at Q4
llmhardware.io sizes a model as parameters in billions × bytes per parameter × 1.2, plus 2 GB for the system. At Q4_K_M a weight takes about half a byte, so Phi-4 comes to about 10.4 GB. At 8-bit it is about 18.8 GB, and at FP16 about 35.6 GB. Ollama lists the default phi4 download at 9.1 GB, which is the file alone, before the runtime and the context take their share.
That sorts the cards. An 8 GB card does not hold Phi-4 at Q4. A 12 GB card does, with a little room left. A 16 GB card such as the RTX 4060 Ti 16GB or RTX 5060 Ti 16GB holds it with space for a longer context, but not the 8-bit file, which wants a 24 GB card.
The context: about 3.4 GB more for the full 16K
The 1.2 factor in the formula covers a short context. A long one needs its own line. The KV cache is the memory a model uses to hold the conversation so far, and it grows with every token. Phi-4's published config lists 40 layers, 10 key-value heads and a hidden size of 5,120 split across 40 attention heads, so each head is 128 wide. At the default f16 precision that is 2 × 40 × 10 × 128 × 2 bytes, or about 205 KB per token. Fill all 16,384 tokens and the cache comes to about 3.4 GB.
Add that to the 10.4 GB and the full window needs about 13.8 GB. That fits a 16 GB card and does not fit a 12 GB one. Ollama's FAQ says a q8_0 cache uses about half the memory of f16, which cuts the cache to about 1.7 GB and puts the full window right at the edge of a 12 GB card, around 12.1 GB.
What Ollama does by default
Ollama's FAQ says it uses a 4,096-token context window unless you change it, so a plain ollama run phi4 stays inside 12 GB. To raise the window for every model, set OLLAMA_CONTEXT_LENGTH before you start the server. Inside a chat session, /set parameter num_ctx 16384 does it for that session. After either change, run ollama ps. If the PROCESSOR column shows less than 100% GPU, part of the model has moved to system RAM, and replies will slow down.
When Phi-4-mini is the better download
Phi-4-mini-instruct is a 3.8B model, and its model card lists a 128K-token context. By the same formula it needs about 4.3 GB at Q4, and Ollama's phi4-mini download is 2.5 GB. That makes it the Phi-4 option for an 8 GB card. Its long window can grow the cache past the size of the weights, so set the context to what your documents need instead of the maximum.
One more line from Microsoft's card: it describes Phi-4 as focused on English. If most of your prompts are in another language, compare it with a multilingual model of the same size before you settle on it.
The Phi-4 hardware requirements guide has the card-by-card table, and the VRAM calculator handles other context lengths.
Sources: Microsoft phi-4 and Phi-4-mini-instruct model cards and the phi-4 config on Hugging Face, Ollama library tags and FAQ. Memory figures are formula estimates, not benchmarks.

Comments
Post a Comment