llama.cpp 'Failed to Fit Params': What It Means
The failed to fit params line in llama.cpp is a warning, not the crash. What the fit step adjusts, what each reason means, and which flags to change.
By Cogniq Labs ResearchEvidence policy

If your llama.cpp log contains this line:
common_fit_params: failed to fit params to free device memory: n_gpu_layers already set by user to 99, abort
it is a warning, not the crash. llama.cpp tried to adjust your settings so the model would fit, could not, and then carried on loading with what it had. If the model loads and runs, nothing is broken. If it fails afterwards, the later error is the one to fix. The text after the second colon tells you why fitting gave up.
What the fit step does
llama.cpp has an option called --fit, on by default. Its help text describes it as adjusting unset arguments to fit in device memory. Two words matter: unset arguments. It changes only what you left to it.
Broadly, when the model would not fit in free memory:
- If you did not set a context length, it can shrink the context, but not below a minimum.
- If that is not enough, it can change how many layers go to the GPU and how they are spread across devices, again only if you did not set that yourself.
- If it cannot reach its target, it gives up and logs the warning.
It aims to keep some memory free. The defaults, from the server documentation:
| Option | Meaning | Default | Environment variable |
|---|---|---|---|
-fit, --fit [on|off] |
Adjust unset arguments to fit | on | LLAMA_ARG_FIT |
-fitt, --fit-target |
Free memory to leave on each device, in MiB | 1024 | LLAMA_ARG_FIT_TARGET |
-fitc, --fit-ctx |
Smallest context fitting may choose | 4096 | LLAMA_ARG_FIT_CTX |
Warning or error?
The source prints two different messages:
| Message | Level | What happened |
|---|---|---|
failed to fit params to free device memory: ... |
Warning | Fitting could not meet the target, for the reason shown |
encountered an error while trying to fit params to free device memory: ... |
Error | Something broke while measuring, such as failing to load the model |
In both cases, the code that applies fitting then goes on to load the model. With the second message, expect the load to fail too, and read the reason it gives: if it says the model failed to load, check the file path, the file and your llama.cpp version before thinking about memory.
The reasons, one by one
| Reason in the warning | What it means | What to do |
|---|---|---|
n_gpu_layers already set by user to N, abort |
You set -ngl, so fitting will not change it |
Remove -ngl, or lower it yourself |
model_params::tensor_split already set by user, abort |
You set a split across GPUs | Remove -ts, or adjust the split |
model_params::tensor_buft_overrides already set by user, abort |
You forced where certain tensors go | Remove the override, or manage memory yourself |
was unable to fit model into system memory by reducing context, abort |
A CPU-only setup, and even a small context does not fit | Use a smaller model or quantization |
changing weight allocation for LLAMA_SPLIT_MODE_ROW not implemented, abort |
Fitting cannot rearrange layers in row split mode | Set layers yourself, or use layer split |
llama_params_fit is not implemented for SPLIT_MODE_TENSOR, abort |
Not supported in tensor split mode | Fit manually in that mode |
The first row is the one most people meet, because many guides and launch scripts add -ngl 99 to put everything on the GPU. That tells llama.cpp you have decided, so it does not rescue you if the model is too big.
Common launch lines and what fitting can do
| You run | What you decided | What fitting may still change |
|---|---|---|
llama-server -m model.gguf |
Nothing | Context length and GPU layers |
llama-server -m model.gguf -c 32768 |
Context | GPU layers |
llama-server -m model.gguf -ngl 99 |
GPU layers | Nothing about layers; the warning appears if it does not fit |
llama-server -m model.gguf -c 32768 -ngl 99 |
Both | Effectively nothing: it fits or it does not |
llama-server -m model.gguf -fit off |
Everything | Nothing at all |
The pattern is simple: every flag you add takes one option away from the fit step. If you copied a long command from somewhere, remove flags until the warning disappears, then add back only the ones you need.
More than one GPU
With several GPUs, fitting is deliberately more cautious. The source comments explain why: for ordinary models only whole layers can be placed on a card, so some space on each is expected to be wasted, and the calculation sets a little aside for that. Two 12 GB cards therefore do not behave quite like one 24 GB card. If a model only just fails to fit across two cards, a slightly smaller quantization or a shorter context usually closes the gap.
The margin set by --fit-target applies to each device. Give one value to use it everywhere, or a comma-separated list to leave more room on the card that drives your display.
How to fix a load that then fails
Let fitting do its job. Remove -ngl, -c, -ts and tensor overrides, and run again. llama.cpp then has room to adjust.
If you want a fixed context, set only -c. A context you set is kept as it is, so pick one that leaves room:
llama-server -m model.gguf -c 8192
If fitting is nearly there, ask it to leave less memory free:
llama-server -m model.gguf --fit-target 512
A smaller margin means less headroom for anything else using the GPU, including your desktop, so lower it gradually.
If the context floor is in the way, allow a smaller one with --fit-ctx 2048. Check that a context that short is still useful for your task.
If you want full control, turn fitting off and set everything yourself:
llama-server -m model.gguf -fit off -ngl 20 -c 4096
Working out what fits
Memory goes on two main things. The weights take roughly the size of the GGUF file. The context cache grows with the context length: for a model shaped like Llama 3.1 8B it is about 128 KiB per token at 16-bit, so 4 GiB at 32,768 tokens. We explain the formula in how much VRAM you need for a 70B model.
As illustrative arithmetic for a 12 GB card, leaving the default 1 GB margin:
| Item | Memory |
|---|---|
| Card | 12 GB |
| Default margin | 1 GB |
| Weights of a 4-bit model file | 8 GB |
| Left for context and working memory | 3 GB |
A context of 8,192 tokens needs about 1 GiB at 128 KiB per token and fits easily. At 32,768 it needs about 4 GiB and does not, so either the context shrinks or some layers move to the CPU.
Shrinking what you need
- A smaller quantization of the same model reduces the weights, with a quality cost covered in what quantization actually costs you.
- A shorter context reduces the cache, which often matters more than people expect.
- Fewer parallel slots in the server reduce how much context is reserved in total.
See what it decided
Add --verbose to see the detail. The log then shows the projected memory use per device, how much free memory it expected to leave, and whether it reduced the context or moved layers. The source also suggests that to check whether a bug comes from fitting itself, you reproduce it with -fit off.
A related point if you run the server in router mode with several models: its documentation explains that with fitting on, an instance takes the largest context that fits at the moment it loads, which depends on what else is loaded. Pin the context with -c in the preset if you need it to be the same every time.
If you meet this through another tool
Several programs are built on llama.cpp, so this line can appear in their logs. The meaning is the same, but their settings are not llama.cpp's flags. In Ollama, set the context length and GPU use with its own options, covered in why Ollama runs out of memory. If you are serving many users and meet memory limits at startup, the equivalent problem in vLLM is explained here.
What we do not know
We read the source and did not run these commands on hardware. llama.cpp changes very quickly, so option names, defaults and messages may differ in your build; llama-server --help is the authority for yours. The estimates above ignore working buffers that vary by model and backend, so trust the verbose log over any table.
Sources
Frequently asked questions
What does "failed to fit params to free device memory" mean?
llama.cpp tried to adjust settings you had not set, such as context length or GPU layers, so the model would fit in free device memory, and could not. It logs this as a warning and then loads with the current settings anyway.
Is "failed to fit params" a fatal error?
No. The warning version is followed by a normal load attempt. If the load succeeds you can ignore it. If it fails afterwards, the later message, often an out of memory error, is the actual failure.
What does "n_gpu_layers already set by user, abort" mean?
You set the number of GPU layers yourself, so the fit step will not change it. Remove the flag to let llama.cpp choose, or reduce the number yourself.
How do I turn off fitting in llama.cpp?
Use the option -fit off, or set the environment variable LLAMA_ARG_FIT. You then control context length and GPU layers entirely, and a configuration that does not fit will fail at load time.
How much memory does llama.cpp leave free?
By default the fit step aims to leave a margin of 1024 MiB on each device, set with --fit-target. It will not shrink the context below the --fit-ctx value, 4096 by default.
Related reading
Ollama 'Model Requires More System Memory': The Fix
What Ollama's two memory numbers actually measure, why Docker and WSL report less than you have, which versions show this error, and how to fix it.
Why Ollama Is Slow Even When It Runs on the GPU
Slow Ollama replies on a GPU come from loading, reading the prompt or writing the answer. How to measure each with Ollama's own timings, and what to change.
Why Ollama Is Using the CPU Instead of Your GPU
When Ollama runs on the CPU, the cause is a driver, a container, a card Ollama does not support, or a model too big for the GPU. How to tell which, and fix it.