New Tool Radar

Local AI

How to Set Context Size and GPU Layers in KoboldCPP

Pass --contextsize and --gpulayers when you launch KoboldCpp so the model keeps enough conversation and uses the GPU the way you want.

Schematic diagram with three steps: choose a context size and GPU layer count, launch KoboldCpp with --contextsize and --gpulayers, and check the model loads.

Two numbers decide how a KoboldCpp model behaves: how much conversation it can remember, and how much of it runs on the GPU. Both are set before launch — the flags reference is explicit that context size must be set before launch, and the guide warns that the defaults can cap you. The flags are --contextsize and --gpulayers.

Related guide: Related Local AI guide

Set both flags at launch

koboldcpp.exe --model model.gguf --contextsize 8192 --gpulayers 28 --usecuda

The flags reference says --contextsize is how many tokens of conversation the model can keep in memory at once, with a default of 16384 and an allowed range of 256 to 524288, and that larger values use more RAM and VRAM. --gpulayers is how many model layers go on the GPU: the default of -1 estimates the layers when a GPU backend is found (autofit), and 0 keeps everything on the CPU. Write the flags in the long form exactly as --contextsize 8192 — the reference warns that short aliases and the --flag=value form are silently ignored when a config file is in play.

Tune them

Start with the defaults and change one thing at a time. If long chats lose their beginning, raise the context size — but watch memory, because context is paid for in RAM and VRAM. If loading fails with an out-of-memory error, lower the GPU layers or the context size; the autofit padding defaults to 1024 MB of spare VRAM, and you can raise it if loads keep failing at the edge. The same two settings exist in the launcher’s Quick Launch tab if you prefer the GUI.

Expected result. We checked the KoboldCpp flags reference for the –contextsize and –gpulayers definitions, defaults and ranges, and the setup guide for the Quick Launch settings. We did not run this software ourselves for this guide, so no output here is a recorded result; steps marked UNTESTED were checked against the sources below, not run.

Limits

Context size is capped at launch: a request can never use more context than the value you started with, so a long document that does not fit will be cut. GPU layers only help if a GPU backend is actually found — check the terminal line about the dynamic library if the model runs on the CPU unexpectedly. We did not run KoboldCpp.

Sources

Checked 2026-11-28.

See all