• Home
  • AI
  • Running Local LLMs at Home: Size the Model to Your Memory First

Running Local LLMs at Home: Size the Model to Your Memory First

The most common local LLM failure is not a bad install. It is a model that is slightly too big for the memory you have, so the runtime quietly spills layers onto the CPU and generation crawls. This guide is a sizing routine: estimate the file size from the numbers published for the format, leave room for the working memory, check where the model actually landed, and keep the service private. It uses the llama.cpp and Ollama documentation as the reference.

Step 1: Understand what the file size is made of

llama.cpp is an MIT-licensed C/C++ project for running LLMs locally and in the cloud, built on the ggml library. Models are often run in quantized form, where weights are stored with fewer bits. The quantize README lists 24 types, from IQ1_S up to Q8_0 and F16, and gives bits per weight and file size for Llama-3.1-8B. The figure below picks five of them.

Llama-3.1-8B file size by quantization type Q2_K2.95 GiBQ4_K_M4.58 GiBQ6_K6.14 GiBQ8_07.95 GiBF1614.96 GiB Sizes from the llama.cpp quantize README. GiB, not decimal GB.
Going from F16 to Q4_K_M cuts the file from 14.96 GiB to 4.58 GiB. The README’s separate memory table lists the Q4_K_M file as 4.9 GB, the same file in decimal units.

You can estimate any model the same way: parameters times bits per weight, divided by 8. For about 8 billion parameters at Q4_K_M’s 4.8944 bits per weight, that gives roughly 4.9 GB, which matches the README. This is a file estimate only. The model also needs working memory for the context, which grows with the context length you set, so never size a model to fill the card exactly.

Step 2: Pick a size with headroom

  1. Write down your available memory: video memory for a discrete GPU, or system memory for CPU use.
  2. Compute the file size for the model and quantization you want with the formula above, or read it from the model page.
  3. Leave a margin for context and the operating system. The sources here do not give a universal margin, so choose a conservative one and adjust after step 3.
  4. If the file is too big, move down one quantization level or choose a smaller model, rather than a heavier setting on the same file.

A worked example

Suppose a hypothetical machine has 16 GB of video memory and you want an 8 billion parameter model. At F16 the README lists 14.96 GiB, which leaves almost nothing for context, so expect a split or a failure to load. Q8_0 at 7.95 GiB leaves roughly half the card free. Q4_K_M at 4.58 GiB leaves the most room and is a reasonable first try. The README gives sizes, not quality scores, so compare answer quality on your own prompts: run the same five real tasks through two quantization levels and keep the smaller one if you cannot tell the outputs apart.

Step 3: Check where the model actually runs

With Ollama, load the model and run ollama ps. The PROCESSOR column shows “100% GPU” when the model sits entirely in GPU memory, “100% CPU” when it sits in system memory, and a split such as “48%/52% CPU/GPU” when it is divided. A split is your signal that the model plus context does not fit.

Ollama’s documented default context length is 4096 tokens. You can raise it for the whole server with the OLLAMA_CONTEXT_LENGTH variable, or per session with /set parameter num_ctx. Raising it increases memory use, so re-run ollama ps afterward. Ollama also keeps a model in memory for five minutes by default, and ollama stop followed by the model name unloads it at once.

With llama.cpp’s server, -c sets context size (the default of 0 reads it from the model) and -ngl sets how many layers live in video memory, with auto as the default. If speed is poor, lower the context or the layer count to see what changes.

Step 4: Keep it private

  • Ollama binds to 127.0.0.1 port 11434 by default. Only set OLLAMA_HOST to 0.0.0.0 if you mean to expose it to your network.
  • llama.cpp’s server listens on 127.0.0.1 by default and supports an –api-key option. Its /health endpoint is public and does not check the key.
  • llama.cpp’s server offers OpenAI-compatible routes such as /v1/chat/completions, so tools that speak that protocol can point at your machine by changing the base URL.

Common mistakes

  • Comparing GB and GiB. The README figures use both. Check which unit a model page uses before concluding a file does not fit.
  • Raising context to the maximum. More context means more memory, and a model that fit at 4096 tokens may not fit at a much larger value.
  • Ignoring the split. A partly CPU model runs, so nothing errors. You only notice through slow output, which is why the ollama ps check matters.
  • Opening the port by habit. Exposing the service on every network interface without a key hands your hardware to anyone who can reach it.

Takeaway

Pick the model by arithmetic, then verify by looking: calculate the file size, load it, and read the PROCESSOR column. If it is not 100% GPU, drop one quantization step or shorten the context before blaming the software.

Keep a small log of what you tried: model, quantization, context length, the PROCESSOR reading, and how long a fixed test prompt took. Defaults in these tools change between releases, so repeat the check after any upgrade, and confirm current defaults in the linked documentation rather than trusting a blog post, including this one.

Sources

Drafted with AI assistance and reviewed by Ash Ahmad, editor of AI Bloggers Hub. Last checked November 2026. Spot an error? Write to [email protected].

Share this post

Subscribe to our newsletter

Keep up with the latest blog posts by staying updated. No spamming: we promise.
By clicking Sign Up you’re confirming that you agree with our Terms and Conditions.

Related posts