Artificial Ignorance

Ollama vs llama.cpp VRAM: Which Uses Less Memory? I Measured Both

With the same settings, Ollama and llama.cpp use the same VRAM, because Ollama now runs llama.cpp underneath. On my RTX 4090 with Gemma 4 26B, a 128K context took 18.2GB in Ollama and 18.2GB in llama-server, 13 MB apart. At 32K the gap was 311 MB, from a batch size Ollama picked. The big differences come from the defaults. Ollama chooses a small context from your VRAM (4K under 24GB, 32K up to 48GB) and one conversation slot, so out of the box it used 16.5GB. llama-server on its own asks for the model’s full context, here 262K with four slots, and used 21.4GB. On a small card its --fit step cuts that back, all the way to 4K in my 12GB test.

Below I show the exact command Ollama gives llama-server, the defaults side by side, my measurements at 32K and 128K with 16-bit and 8-bit caches, where every gigabyte goes, what happens on a 12GB card, the speed, every setting in both tools that changes VRAM, and recipes to make each behave like the other. All figures are my own measurements on 6 December 2026, with Ollama 0.40.15.

Ollama vs llama.cpp VRAM use, measuredGemma 4 26B on an RTX 4090. With the same 32K context Ollama used 16.5 GB and llama-server 16.2 GB. With each tool's own defaults Ollama used 16.5 GB at 32K and llama-server 21.4 GB at 262K with four slots.MEASURED ON ONE GPUOllama vsllama.cppWhich one uses less VRAM?Same engine underneath.The defaults make the difference.Gemma 4 26B-A4B QAT, RTX 4090 24 GB, VRAM in GBSame settings, 32K contextOllama16.5 GBllama.cpp16.2 GBEach with its own defaultsOllama16.5 GBllama.cpp21.4 GBartificialignorance.net
01

Why this question has a new answer

For years the honest answer to “Ollama or llama.cpp?” was that they were related but different. Ollama started as a friendly wrapper around llama.cpp, then built its own engine in Go on top of llama.cpp’s low-level GGML library. Forum threads were full of people finding that the same model used more memory, or ran slower, in one than the other, and there were real reasons for it.

That changed in 2026. Ollama 0.30, released on 13 May, announced “improved compatibility and performance using llama.cpp”. Since then, on Windows and Linux, Ollama runs models by starting llama.cpp’s own llama-server program in the background. Ollama 0.40.2 went further: models downloaded with older versions are upgraded in the background the first time you run them, “for better performance and compatibility when running on llama.cpp”. On Apple Silicon, Ollama uses Apple’s MLX for the models MLX supports, which I cover in section 16.

How Ollama runs a model todayOllama is a manager with a model library, a scheduler and an API. On Windows and Linux it starts llama.cpp's llama-server with its own flags, and llama-server holds the weights, KV cache and buffers in VRAM. On Apple Silicon Macs it uses an MLX runner for supported models.WHAT RUNS WHEN YOU TYPE ollama runOllama (ollama.exe)Model library and downloadsollama pull, blobs, ModelfilesSchedulerpicks context length, checks free VRAM, loads and unloadsAPI on port 11434/api/chat, /api/generate, OpenAI-style /v1starts withits own flagsllama-server (llama.cpp)Windows, Linux and most GPUs since Ollama 0.30.Loads the GGUF, holds the weights, KV cache andbuffers in VRAM.CUDA, ROCm, Vulkan or CPU backendMLX runnerApple Silicon Macs, for models MLX supports (defaultsince 0.40).On a Windows or Linux PC the memory is held by llama-server. Ollama decides how big that memory is.
On a Windows or Linux PC, Ollama is now a manager around llama-server. The memory is held by llama-server; Ollama decides how much.

So on a PC the question “which engine uses less VRAM?” has an unexpected answer: it is the same engine. What differs is everything around it: the context length each tool picks, how many conversations it prepares for, whether it loads the vision part of the model, and how it decides what fits. Those choices can easily add or remove several gigabytes, which is why people still see big differences. This article measures exactly where they come from.

02

The exact command Ollama gives llama-server

You do not have to guess what Ollama does. Its log file records the command it uses to start llama-server. This is the line from my PC when I ran ollama run gemma4:26b-a4b-it-qat with Ollama 0.40.15 on an RTX 4090 (I shortened the file paths):

llama-server.exe --model <gemma4 blob> --port 50922 --host 127.0.0.1 --no-webui --offline
  -c 32768 -np 1 --log-verbosity 4 --no-log-prefix --no-log-timestamps
  --no-jinja --chat-template chatml --mmproj <projector blob>
  --load-mode none --flash-attn auto -b 1024 -ub 1024 --context-shift --keep 4

Here is what each part means for memory:

FlagWhat Ollama choseEffect on VRAM
-c 32768A 32K context, picked from my 24GB of VRAMSets the size of the KV cache. This is Ollama’s biggest memory decision.
-np 1One conversation slotOnly one cache. llama-server alone would prepare four.
--mmprojThe vision projector is always loadedAbout 1.2GB for Gemma 4, even if you never send an image.
--flash-attn autoFlash attention where supportedSmaller buffers, and needed for a quantised cache.
-b 1024 -ub 1024Batch size, which Ollama changes from load to loadA larger batch means a larger compute buffer, a few hundred MB.
--load-mode noneNo memory-mapping on Windows with CUDAChanges system RAM use and load time, not VRAM. The log says reason=windows_cuda.
--context-shift --keep 4Drop old tokens when the context is fullNo memory cost. It lets long chats continue instead of failing.
--no-jinja --chat-template chatmlOllama formats the prompt itselfNo memory cost.

Ollama also starts this llama-server from its own folder (lib\ollama) with its own CUDA libraries. The llama.cpp build inside Ollama 0.40.15 reports itself as 0.9.0-dev; the 0.40.21 release moved it to llama.cpp build b12973. Ollama may carry small patches of its own, so I compared it with the very same llama-server.exe file, not a separate download, to keep the engine identical.

03

Ollama defaults vs llama.cpp defaults

Put the two sets of defaults side by side and the difference in memory use becomes predictable before you measure anything:

SettingOllama 0.40 (Windows, NVIDIA)llama-server on its own
Context lengthFrom your VRAM: 4K below 24GB, 32K from 24 to 48GB, 256K at 48GB or more (Ollama docs)The model’s full trained length (-c 0), cut down by --fit only if it does not fit
Conversation slots1 (OLLAMA_NUM_PARALLEL)Automatic: 4 in my test, sharing one cache
Vision projectorAlways loaded on the GPUOnly if you pass --mmproj or use -hf (then on by default)
KV cache typef16, one global setting for all modelsf16, set per launch with -ctk/-ctv
Flash attentionautoauto
Batch sizes512 or 1024, chosen by Ollama2048 logical, 512 physical
Fitting into VRAMOllama’s scheduler, then llama.cpp’s --fit--fit on, leaving 1,024 MiB free
UnloadingAfter 5 minutes idleNever, unless you set --sleep-idle-seconds

The first two rows decide most of the memory. On a 24GB card, Ollama gives Gemma 4 a 32K context and one slot. llama-server on its own gives it the full 262,144 tokens and four slots. Gemma 4 handles long contexts unusually cheaply, as you will see, but even so that gap is worth about 5GB.

04

How I tested

I wanted a fair test, so I removed every difference except the one I was measuring.

Hardware

NVIDIA RTX 4090 with 24GB (24,564 MiB), 64GB of system RAM, Windows 11, NVIDIA driver 621.14.

Software

Ollama 0.40.15. For llama.cpp, the llama-server.exe that ships inside that Ollama, with Ollama’s CUDA 13 backend.

Model

gemma4:26b-a4b-it-qat from the Ollama library: Gemma 4 26B-A4B, a mixture-of-experts model, 4-bit QAT (Q4_0), a 14.4GB file plus its vision projector. Both tools loaded the very same files.

Runs

Eighteen runs, each from a cold start, covering both tools at 4K, 32K, 128K and 262K, 16-bit and 8-bit caches, and parts of the model moved to system RAM.

  • Before each run I closed Ollama and llama-server completely, waited for the VRAM to settle and wrote down the starting figure from nvidia-smi. Windows and my other apps were already using about 1.5GB, which I do not count.
  • I loaded the model, sent a prompt of about 4,850 tokens, then asked for 400 tokens of output. Thinking was turned off.
  • After that I read the VRAM again. The difference is the “VRAM used” in this article. A second reader checked every 0.4 seconds for peaks; the peak was never more than a few MB above the final figure.
  • Speeds are the prompt and generation speeds each tool reports for that request.
  • I ran most setups once and repeated two. Memory use repeated to within 50MB; speeds can vary by a few per cent, so treat small speed differences as noise.

Units: I give GB as Windows Task Manager does, where 1GB is 1,024MB. Model download sizes on websites usually use 1GB = 1,000MB, so the same file can look about 7% bigger there.

One model on one card cannot cover everything, so in section 11 I also work out what the defaults would cost with models that need far more memory per token than Gemma 4.

05

Result 1: same settings, same VRAM

First I gave llama-server the same context and slot count that Ollama uses: -c 32768 -np 1. Then I repeated the test at a 128K context, and again at 128K with an 8-bit cache (num_ctx 131072 plus OLLAMA_KV_CACHE_TYPE=q8_0 in Ollama, -c 131072 -ctk q8_0 -ctv q8_0 in llama-server).

VRAM with identical settings in Ollama and llama-serverAt 32K context Ollama used 16.5 GB and llama-server 16.2 GB. At 128K Ollama 18.2 GB and llama-server 18.2 GB. At 128K with an 8-bit cache Ollama 17.3 GB and llama-server 17.3 GB.SAME SETTINGS, SAME VRAMOllama 0.40.15llama-server (same build)32K context16-bit cache16.5 GB16.2 GB128K context16-bit cache18.2 GB18.2 GB128K context8-bit cache (q8_0)17.3 GB17.3 GBVRAM added by loading the model, measured with nvidia-smi. Gemma 4 26B-A4B QAT with its vision projector, RTX 4090.
With matching settings, the two tools used the same VRAM to within a few hundred MB.
SetupOllamallama-serverDifference
32K context, 16-bit cache16.5GB16.2GBOllama +311 MB
128K context, 16-bit cache18.2GB18.2GBOllama +13 MB
128K context, 8-bit cache17.3GB17.3GB-4 MB

At 128K the two were within 13 MB of each other, which is measurement noise. At 32K Ollama used about 311 MB more. Its log explains why: for that load it chose a batch size of 1,024 instead of 512, which makes the compute buffer and the sliding-window part of the cache a little bigger. That is a setting, not a difference in the engine.

So the first answer is simple. If you give them the same settings, Ollama and llama.cpp use the same VRAM. Ollama itself, the program you talk to, keeps nothing on the GPU that matters.

06

Result 2: each tool with its own defaults

Most people never change the defaults, so this is the comparison that matters in practice. I started Ollama with no settings at all, and llama-server with nothing but the model and projector files.

VRAM with each tool's default settingsOllama's defaults gave a 32K context and one slot and used 16.5 GB. llama-server's defaults gave the full 262K context with four slots and used 21.4 GB.OUT OF THE BOX ON A 24 GB CARDOllama 0.40.15llama-server (same build)Ollama default32K context, 1 slot16.5 GBllama-server default262K context, 4 slots21.4 GB24 GB cardSame model file, same llama.cpp build. Only the defaults differ.
Out of the box, llama-server prepared the full 262K context for four slots and used about 5GB more.
Ollama defaultllama-server default
Context32,768 tokens262,144 tokens
Slots14
VRAM used16.5GB21.4GB
Prompt speed8,448 tokens/s8,857 tokens/s
Generation speed203 tokens/s181 tokens/s

llama-server used about 5GB more, all of it for the larger context and the extra slots. In return it can hold a conversation eight times longer, and serve four people at once. Ollama on the same card can only remember 32K tokens before old text starts falling out of the context.

Neither default is wrong. They are aimed at different people. Ollama assumes you want the model to load quickly and safely next to everything else on your PC. llama-server assumes you want the most the model can do and lets --fit trim it if needed. The surprise is that, with Gemma 4, llama-server’s “everything” still fits on a 24GB card. With most other models it would not, which is where --fit comes in (section 11).

The generation speed was about 10% lower with llama-server’s defaults in my run. I did not dig into why; the larger shared cache for four slots is the obvious difference. If you want the speed back, -np 1 costs nothing for a single user.

07

Where every gigabyte goes

llama.cpp prints a memory breakdown table when it loads a model, and Ollama copies it into its log. Together with nvidia-smi it shows exactly what fills the card:

Where the VRAM goes in each setupThe model weights take 13.4 GB in every setup. The KV cache is 1.0 GB at Ollama's 32K default, 2.8 GB at 128K, 1.5 GB at 128K with an 8-bit cache and 5.9 GB with llama-server's 262K default for four slots. Compute buffers take 0.3 to 0.7 GB, the vision projector about 1.2 GB and the CUDA runtime about 0.4 GB.WHERE THE VRAM GOESmodel weightsKV cachecompute buffersvision projectorCUDA runtime and otherOllama default32K, 1 slot13.41.01.216.5 GBOllama, num_ctx 128K128K, 1 slot13.42.81.218.2 GBOllama, 128K, q8_0 cache128K, 1 slot13.41.51.217.3 GBllama-server default262K, 4 slots13.45.91.221.4 GBFigures in GB from llama.cpp’s own memory report plus nvidia-smi. The projector cost was measured by moving it off the GPU.
The model weights never change. The KV cache is the part that the context, the slots and the cache type move up and down.
PartSize hereWhat changes it
Model weights13.4GBOnly the model file and quantisation you choose. Identical in both tools.
KV cache0.4GB (4K) to 5.9GB (262K, 4 slots)Context length, slots and cache type. The part Ollama’s defaults keep small.
Compute buffers0.3 to 0.7GBBatch size and cache type. Grew from 0.27GB to 0.69GB when I switched to a q8_0 cache.
Vision projector1.2GBLoaded by Ollama for every vision model, even for text-only chats.
CUDA runtime and otherAbout 0.4 to 0.5GBThe CUDA libraries and small work buffers. Roughly fixed.

Three details here are worth knowing.

Gemma 4 has a cheap cache. Only 5 of its 30 layers keep the whole conversation. The other 25 use a sliding window of 1,024 tokens, so their part of the cache stays at 0.3 to 0.4GB per slot however long the context grows. The 5 full layers cost about 20KB per token: 0.6GB at 32K and 5GB at 262K. That is why llama-server’s 262K default still fitted on my card.

The 8-bit cache saved less than you might expect. Switching to q8_0 cut the cache at 128K from 2.8GB to 1.5GB, but the compute buffer grew by about 0.4GB, so the card only gained 0.9GB. With a model whose cache is bigger, the saving is much larger.

ollama ps shows less than the card uses. For the 128K run it reported 14.1GB on the GPU, while nvidia-smi saw 18.2GB more in use than before the model loaded. Use ollama ps to check the context and the GPU/CPU split, not to plan your free VRAM.

As a final check I started the standalone llama-server with Ollama’s exact flags from section 2. It used 16,877 MB against Ollama’s 16,874 MB, a difference of 3 MB. Same flags, same memory.

08

A surprise: OLLAMA_GPU_OVERHEAD did not stop a full load

Ollama has a setting to keep part of the card free: OLLAMA_GPU_OVERHEAD, in bytes. I set it to 12GiB, hoping to make my 24GB card behave like a 12GB one. Ollama’s log showed that it took the setting seriously: it listed available="10.0 GiB" and overhead="12.0 GiB", and it lowered the default context from 32K to 4K, the default for small cards.

But the model still loaded entirely on the GPU and used 15.6GB of VRAM, far more than the 10GiB Ollama said was available. The reason is in the same log. Ollama started llama-server without any --fit-target, so llama.cpp’s own fitting step saw 23GB free and reported “no changes needed”.

In Ollama 0.40.15 on my PC, OLLAMA_GPU_OVERHEAD changed the default context but did not limit where the model was placed. If you rely on it to keep VRAM free for a game or another app, check with nvidia-smi after the model loads. This may change in later versions.

So on a real 12GB card, how do the two tools decide what goes where? With llama-server it is fully visible, so I tested that directly in the next section.

09

What happens on a 12GB card

Gemma 4 26B needs about 16GB at a 32K context, so on a 12GB card part of it has to live in system RAM. I could not borrow a 12GB card, so I asked llama-server to leave 12GB of my card unused (--fit-target 12288) and watched its log to see what it decided. I also tried the manual settings in both tools at about the same VRAM.

llama-server with no context set did two things to fit. First it cut the context from 262,144 tokens all the way down to 4,096, the --fit-ctx minimum. Then, because even that was not enough, it moved part of the expert weights in 12 of the 30 layers into system RAM and kept everything else on the GPU. It used 11.9GB of VRAM. On a small card, then, llama-server’s “use everything” default ends up at the same 4K context that Ollama picks for cards under 24GB. It also kept its four slots, which share that small cache.

llama-server with -c 32768 kept the context I asked for (the log says context size set by user to 32768 -> no change) and moved the same expert weights. That is the part of a mixture-of-experts model that is used least per token, so it is the cheapest part to move.

Ollama has no documented setting for expert offload. Its num_gpu parameter still works and became -ngl in the llama-server command, which moves whole layers to the CPU. With num_gpu 23 it used 11.8GB, about the same as llama-server’s 11.9GB.

VRAM and speed when part of the model moves to system RAMWhole model on GPU: 16.2 GB, 204 tokens per second generation, 8,614 prompt; llama-server --fit: 11.9 GB, 96 tokens per second generation, 1,737 prompt; llama-server --n-cpu-moe 12: 11.7 GB, 93 tokens per second generation, 1,852 prompt; Ollama num_gpu 23: 11.8 GB, 79 tokens per second generation, 4,625 prompt; Ollama num_gpu 15: 8.1 GB, 46 tokens per second generation, 3,079 prompt.SQUEEZING THE MODEL INTO LESS VRAM (32K CONTEXT)VRAM usedGeneration, tokens/sPrompt reading, tokens/sWhole model on GPUreference, 32K16.2 GB2048,614llama-server --fitexperts of 12 layers in RAM11.9 GB961,737llama-server --n-cpu-moe 12same idea, set by hand11.7 GB931,852Ollama num_gpu 237 whole layers in RAM11.8 GB794,625Ollama num_gpu 1515 whole layers in RAM8.1 GB463,079Gemma 4 26B-A4B QAT, 32K context, one slot. Measured on an RTX 4090 with parts of the model forced into system RAM.
At about 12GB, moving only the experts kept generation faster; moving whole layers kept prompt reading faster.
Method, 32K contextVRAMGenerationPrompt reading
Whole model on GPU (reference)16.2GB2048,614
llama-server, --fit with a 12GB margin11.9GB961,737
llama-server, --n-cpu-moe 12 (all experts of 12 layers)11.7GB931,852
Ollama, num_gpu 2311.8GB794,625
Ollama, num_gpu 158.1GB463,079

Speeds in tokens per second. At the same VRAM, moving experts generated about 21% faster than moving whole layers, which is what you feel in a chat. Moving whole layers read the long prompt about 2.7 times faster, which matters if you paste long documents. Both are far behind the 204 tokens per second with the whole model on the GPU, and that gap is the real cost of a small card.

What does Ollama do on its own when a model does not fit? In all my tests it never chose a layer count by itself: unless I set num_gpu, it started llama-server without -ngl, which leaves the placement to llama.cpp’s --fit with its default 1GB margin. So on a real 12GB card I would expect it to place the model much as llama-server does, at its 4K default context. I could not confirm that without a real 12GB card, so check ollama ps and the log on yours.

10

Is one of them faster?

Not when they use the same settings. Both send the same work to the same CUDA code, and the numbers show it:

SetupPrompt speed, OllamaPrompt speed, llama-serverGeneration, OllamaGeneration, llama-server
32K, 16-bit cache8,4488,614203204
128K, 16-bit cache8,7308,626203204
128K, q8_0 cache8,1328,029192192
Each tool’s defaults8,448 (32K)8,857 (262K, 4 slots)203181

All speeds are in tokens per second, for a prompt of about 4,850 tokens and 400 generated tokens, with the whole model on the GPU. The differences of 1 to 3% are within run-to-run noise. Two things did make a real difference:

  • The q8_0 cache cost about 5 to 7% in both tools, for prompts and for generation. That is the price of the smaller cache, and it is usually worth paying when it lets the whole model stay on the GPU.
  • llama-server’s default four slots generated about 10% slower than one slot in my run. For a single user, -np 1 is free speed.

What changes speed far more than either tool is whether the model fits on the GPU. As section 9 shows, pushing part of the model into system RAM cut the generation speed by more than half. That is why the VRAM question matters at all.

Load time is harder to compare fairly. Ollama took 41 seconds the first time because it read the 14GB file from disk without memory-mapping; later loads took about 4 seconds once Windows had the file in its cache. llama-server took about 18 seconds each time on the same PC. Your disk and your RAM will change these numbers more than the tool does.

11

Why the defaults matter more with other models

Gemma 4 is a gentle test, because its cache is small. Most models need far more memory per token of context, and then the two sets of defaults drift much further apart. These are the 16-bit cache sizes, worked out from each model’s official configuration in my KV cache guide:

ModelCache per tokenOllama default, card under 24GB (4K)Ollama default, 24 to 48GB card (32K)llama-server default (full trained length)
Gemma 4 26B-A4B (measured)20KB0.4GB*1.0GB*5.9GB* (4 slots) at 262K
Qwen4-35B-A3B20KB0.08GB0.6GB20GB at 1M
Qwen 3.6 27B64KB0.25GB2GB16GB at 262K
Qwen3-30B-A3B-250796KB0.4GB3GB24GB at 262K
Llama 3.1 8B128KB0.5GB4GB16GB at 128K

* Gemma 4 rows are my measurements, including the sliding-window part. The others are my calculations for one slot, cache only.

Take Qwen3-30B-A3B on a 24GB card. Ollama gives it 32K tokens and a 3GB cache. llama-server on its own would ask for the full 262K, a 24GB cache that cannot fit next to the model. That is where --fit steps in: it shrinks the context until the model, the cache and the buffers fit with about 1GB to spare. So the practical rule is:

Ollama by default

Uses a fixed, small amount of VRAM for the cache. Predictable, leaves room for other apps, but the model forgets long chats early.

llama-server by default

Fills the card. It takes the longest context that fits, minus about 1GB. Long memory when the card is big enough, but nothing left for a game or a second model.

Neither is “more efficient”. One leaves VRAM unused by choice, the other uses it by choice. Once you set the context yourself, as the next sections show, the difference disappears.

12

Every Ollama setting that changes VRAM

Ollama hides llama.cpp’s flags, but most of them have an Ollama equivalent. Environment variables are read when the server starts, so quit the Ollama app from the tray (or stop ollama serve) and start it again after you change one. On Windows, set them in Settings → System → About → Advanced system settings → Environment Variables, or for one session in PowerShell with $env:OLLAMA_CONTEXT_LENGTH="65536"; ollama serve.

SettingWhereWhat it does to memoryllama.cpp equivalent
num_ctxPer request, Modelfile or /set parameterThe context length. The biggest lever: it sets the size of the KV cache.-c
OLLAMA_CONTEXT_LENGTHEnvironmentThe default context for every model. Overrides the VRAM-based default (4K, 32K or 256K).-c
Context sliderOllama app settingsThe same setting as OLLAMA_CONTEXT_LENGTH, for the desktop app.-c
OLLAMA_KV_CACHE_TYPEEnvironmentCache precision: f16 (default), q8_0 or q4_0. Global, for all models. Needs flash attention.-ctk -ctv
OLLAMA_FLASH_ATTENTIONEnvironmentOllama turns it on automatically where supported. 1 forces it on, 0 off.-fa
OLLAMA_NUM_PARALLELEnvironmentRequests served at once per model. Default 1 on PC GPUs. Each extra slot multiplies the context.-np
OLLAMA_MAX_LOADED_MODELSEnvironmentHow many models can stay loaded together. Default 3 per GPU, if they fit.--models-max (router mode)
OLLAMA_KEEP_ALIVE / keep_aliveEnvironment or per requestHow long a model stays in VRAM after use. Default 5 minutes. 0 unloads at once, -1 keeps it forever.--sleep-idle-seconds (roughly)
OLLAMA_GPU_OVERHEADEnvironmentMeant to leave VRAM unused for other apps. In my test it lowered the default context but did not limit placement (section 8).--fit-target
num_gpuPer request or ModelfileNumber of layers on the GPU. Lower it to push layers to system RAM.-ngl
OLLAMA_SCHED_SPREADEnvironmentSpread one model over all GPUs, even if it fits on one.-sm layer

There is no Ollama switch for the vision projector, the batch size or the slot layout. If you need those, run llama-server yourself.

13

Every llama.cpp setting that changes VRAM

With llama-server you set these yourself on the command line, or as LLAMA_ARG_ environment variables. Anything you leave unset is chosen by --fit, which is on by default. It starts from the model’s full trained context and shrinks things until the model fits with about 1GB to spare.

FlagDefaultWhat it does to memory
-c N0 = trained lengthContext length. Set it, or --fit picks the biggest that fits, up to the model’s maximum.
-np Nauto (4 in my test)Conversation slots. With automatic slots the cache is shared (-kvu), but each slot can grow to the full context. Use -np 1 for one user.
-ctk / -ctvf16Cache precision. q8_0 roughly halves the cache with little quality loss. You can set keys and values separately.
-faautoFlash attention. Needed for a quantised value cache and smaller compute buffers.
--fit / --fit-target Non / 1024 MiBFit the model into free VRAM, leaving N MiB spare. Raise the target to leave room for a game or a second model.
-ngl NautoLayers kept on the GPU. Fewer layers means less VRAM and much slower generation.
--n-cpu-moe N / -cmoeoffKeep the experts of the first N layers (or all layers) of a mixture-of-experts model in system RAM. The best way to squeeze a big MoE model onto a small card.
-b / -ub2048 / 512Batch sizes. A smaller -ub shrinks the compute buffer but slows long prompts.
--no-mmproj / --no-mmproj-offloadprojector loaded and on GPUSkip the vision projector, or keep it in system RAM. Saved 1.2GB on Gemma 4 in my test.
-nkvooffKeep the KV cache in system RAM. Saves VRAM, but long prompts slow down a lot.
--load-modeauto (mmap)How the file is read. Affects system RAM and load time, not VRAM.
--cache-ram N8192 MiBSystem RAM used to keep old prompts for reuse. Does not use VRAM.

The defaults that cost the most VRAM are the first two. An unset -c with automatic slots is a good default for a server shared by several people, and a poor one for a single person on a gaming card.

14

Make them behave the same

Since the engine is shared, you can make either tool behave like the other. These recipes are for Windows PowerShell; on Linux or macOS use export NAME=value instead of $env:.

Use Ollama’s model files in llama-server

Ollama stores models as ordinary GGUF files with long hash names. Ask Ollama which ones belong to a model:

ollama show --modelfile gemma4:26b-a4b-it-qat
# FROM gemma4:26b-a4b-it-qat
FROM C:\Users\you\.ollama\models\blobs\sha256-4c85...d054c5   <- the model
FROM C:\Users\you\.ollama\models\blobs\sha256-d8e2...9239     <- the vision projector

The first FROM line with a path is the model, the second (if there is one) is the vision projector. The files live in %USERPROFILE%\.ollama\models\blobs unless you moved them with OLLAMA_MODELS. Use them in place; do not rename or delete them, or Ollama will lose the model.

llama-server with Ollama’s memory use

llama-server -m <model blob> --mmproj <projector blob> -c 32768 -np 1

This matches Ollama’s default on a 24GB card. Leave out --mmproj if you only chat in text, and you save the projector’s 1.2GB.

A lean llama-server for one user

llama-server -m <model blob> -c 32768 -np 1 -fa on -ctk q8_0 -ctv q8_0

One slot, a fixed 32K context, flash attention and an 8-bit cache, and no projector. For a 12GB card and a mixture-of-experts model, add expert offload and raise the number until the model fits:

llama-server -m <model blob> -c 32768 -np 1 -fa on -ctk q8_0 -ctv q8_0 --n-cpu-moe 12

A lean Ollama

$env:OLLAMA_CONTEXT_LENGTH="32768"
$env:OLLAMA_KV_CACHE_TYPE="q8_0"
$env:OLLAMA_MAX_LOADED_MODELS="1"
ollama serve

Quit the Ollama app from the tray first, or the new values will not be used. To keep these for good, set them as Windows user environment variables and restart the app. For one model only, put PARAMETER num_ctx 32768 in a Modelfile and create a copy with ollama create.

Ollama with llama-server’s long memory

Set OLLAMA_CONTEXT_LENGTH to the length you need, for example 131072, and keep OLLAMA_KV_CACHE_TYPE=q8_0. Check with ollama ps that the PROCESSOR column still says 100% GPU. If it does not, lower the context again: a model split between GPU and CPU loses far more speed than a shorter context costs.

15

How to see the real VRAM use on your own PC

Do not trust one number. Each tool counts something slightly different, and I used all of them for this article.

ToolWhat it showsWhat it misses
ollama psSize of the loaded model, the GPU and CPU split, the context and when it unloads.Leaves out some buffers and the CUDA runtime, so it reads lower than Task Manager.
nvidia-smiTotal VRAM used on the card by every program.Cannot split the model from the cache. Subtract the number you see before loading.
Task Manager → Performance → GPUDedicated GPU memory, the same total as nvidia-smi.Shared GPU memory there is system RAM, not VRAM.
llama-server logThe memory breakdown table: model, context and compute per device, plus KV buffer size lines.Needs -lv 4 for the full table. Ollama writes this log to server.log.
/props endpointThe context per slot and the number of slots llama-server picked.No memory figures.

On Windows, Ollama’s logs are in %LOCALAPPDATA%\Ollama. Open server.log after loading a model and search for starting llama-server: the line shows the exact flags Ollama used. A few lines further down, the memory breakdown table shows where every megabyte went.

16

What about Macs?

Everything above is about Windows and Linux PCs with a graphics card. On Apple Silicon the picture is different in two ways.

  • Ollama may not use llama.cpp at all. Since Ollama 0.40, models whose architecture the MLX runtime supports run on Apple’s MLX by default. Other models still run on llama.cpp with Metal. So on a Mac, “Ollama vs llama.cpp” can really be “MLX vs llama.cpp”, and the memory use can differ for real reasons, not just settings.
  • There is no separate VRAM. The GPU shares the Mac’s unified memory, and macOS lets the GPU use only part of it by default. The model, the cache and every other app compete for the same pool.
  • The context default still applies. Ollama picks the default context from the memory the GPU can use, so a Mac with lots of memory can get a much larger default context than a 16GB PC card.

I did not measure a Mac for this article, so I give no Mac numbers. The settings advice is the same: set the context yourself, use an 8-bit cache, and check ollama ps.

For a worked Mac example, my guide to running Qwen4 on a Mac compares the memory Ollama, llama.cpp, LM Studio and MLX need for the same model, and shows how to check and raise the GPU memory limit.

17

Which one should you use?

Since the engine is the same, choose by how you work, not by VRAM.

Pick Ollama if

You want one command to download and run models, you switch between several models, you use apps that expect Ollama’s API (Open WebUI, coding tools, ollama launch), or you want models to unload by themselves when idle. Set OLLAMA_CONTEXT_LENGTH and OLLAMA_KV_CACHE_TYPE once and it will use VRAM as well as llama.cpp does.

Pick llama-server if

You want every setting: per-model cache types, the vision projector off, exact batch sizes, expert offload with --n-cpu-moe, speculative decoding options, or the newest llama.cpp the day it comes out. It is also the better choice on a small card, where fine control decides whether a model fits.

Or use both. Ollama’s downloaded files are ordinary GGUF files. You can point llama-server at them (section 14) and keep Ollama for everyday use. Just do not run both with big models at once: each reserves its own VRAM.

For VRAM alone, there is one honest answer: the one you configure uses less. A tuned Ollama and a tuned llama-server land within a few hundred MB of each other.

18

Troubleshooting VRAM problems in both

SymptomLikely causeFix
The model runs much slower in Ollama than in llama-serverOllama put some layers on the CPU (ollama ps shows something like 30%/70% CPU/GPU)Lower num_ctx, set OLLAMA_KV_CACHE_TYPE=q8_0, or close other GPU apps
llama-server uses almost all my VRAMNo -c given, so --fit took the longest context that fitsSet -c yourself, for example -c 32768
Ollama forgets the start of long chatsDefault context of 4K or 32KRaise num_ctx or OLLAMA_CONTEXT_LENGTH
Same model, 1 to 2GB more in OllamaThe vision projector, a bigger context, or a second model still loadedCheck ollama ps; use a text-only model or run llama-server without --mmproj
VRAM stays full after I stop chattingOllama keeps a model for 5 minutes; llama-server keeps it until closedSet keep_alive to 0, run ollama stop <model>, or close llama-server
llama-server crashes with an out-of-memory error at load--fit off, or another app took VRAM between the check and the loadLeave --fit on, raise --fit-target, or lower -c
Everything slows to a crawl when VRAM is full, with no errorOn Windows the NVIDIA driver can spill GPU memory into system RAM instead of failingWatch “Shared GPU memory” in Task Manager; free VRAM until it stays near zero
OLLAMA_KV_CACHE_TYPE changes nothingFlash attention not active, or the server was not restartedRestart Ollama fully from the tray; set OLLAMA_FLASH_ATTENTION=1
Two models fight for VRAMOllama keeps up to 3 models per GPU loadedSet OLLAMA_MAX_LOADED_MODELS=1
19

Frequently asked questions

Does Ollama use more VRAM than llama.cpp?

Not with the same settings. In my tests the gap was 13 MB at 128K and 311 MB at 32K. With default settings Ollama usually uses less, because it picks a small context.

Is Ollama just llama.cpp now?

On Windows and Linux it runs models with llama.cpp’s llama-server, since version 0.30. Ollama adds the model library, the scheduler, the API and the app. On Apple Silicon it uses MLX for supported models.

Why does llama-server fill my whole GPU?

Because without -c it asks for the model’s full trained context and lets --fit shrink it until about 1GB is left. Set -c to the length you need.

Why does Ollama give me only 4K or 32K of context?

Its default depends on VRAM: 4K under 24GB, 32K from 24 to 48GB, 256K at 48GB or more. Raise num_ctx or OLLAMA_CONTEXT_LENGTH.

Is llama.cpp faster than Ollama?

With the same settings, no: within 1 to 3% in my tests, which is noise. Differences come from settings such as slots, cache type and how much of the model is on the GPU.

Does Ollama load the vision part of a model even for text?

Yes, for models that include a projector. With Gemma 4 that cost me 1.2GB. llama-server loads it only if you pass --mmproj.

Does an 8-bit KV cache hurt quality?

Ollama’s FAQ says q8_0 usually has no noticeable impact. It cost me 5 to 7% speed and saved 0.9GB at 128K with Gemma 4; with models that have a bigger cache it saves much more.

Can I set the KV cache type per model in Ollama?

No. OLLAMA_KV_CACHE_TYPE is global. llama-server lets you set it per launch, even separately for keys and values.

Can Ollama offload only the experts of a MoE model?

Not with a documented setting. num_gpu moves whole layers. llama-server has --n-cpu-moe and -cmoe, and its --fit does it automatically.

Why does ollama ps show less memory than Task Manager?

It reports the model’s size estimate, not every buffer and the CUDA runtime. In my 128K test it showed 14.1GB while the card had 18.2GB more in use.

Can I run Ollama and llama-server at the same time?

Yes, on different ports (11434 and 8080 by default), but each loads its own copy of a model and its own cache. Two copies of a 14GB model will not fit on a 24GB card.

Should I switch from Ollama to llama.cpp to save VRAM?

Only if you need settings Ollama does not have, such as expert offload or a per-model cache type. Otherwise set the context and cache type in Ollama and you get the same memory use.

Does OLLAMA_GPU_OVERHEAD keep VRAM free for games?

Not reliably in my test with Ollama 0.40.15: with 12GiB set, it lowered the default context to 4K but still put the whole model on the GPU. Check with nvidia-smi after loading, or limit the context and layers directly.

Does LM Studio behave the same way?

LM Studio also uses llama.cpp for GGUF models and has its own defaults and settings. I did not measure it here; the same rule applies: compare at the same context and cache type.

20

Your next step

Open Ollama’s server.log after you load your favourite model and find the starting llama-server line. It tells you the context, slots and batch Ollama chose, and the memory breakdown table below it shows the cost. Then decide what you actually need: for most chats and coding, 32K with an 8-bit cache is plenty. If you need much longer contexts, read my guide to KV cache memory first, and if your card is small, my Qwen4 guide for 8GB to 16GB cards shows expert offload in practice. For faster generation on any card, see the llama.cpp MTP guide.

Sources: Ollama 0.30 release notes, Ollama 0.40.2 release notes, Ollama 0.15.5 release notes (VRAM-based context), Ollama context length docs, Ollama FAQ, llama.cpp server README, Gemma 4 on Ollama. All VRAM and speed figures are my own measurements on 6 December 2026; the per-token cache sizes for other models are my calculations from their official configuration files.