Cart

    Sorry, we could not find any results for your search querry.

    Which AI model (LLM) and server size should I use with Ollama/Lama.cpp/Codex/Claude Code?

    Hosting LLMs requires powerful hardware. Preferably you use one or more powerful GPUs, but it is also possible to run LLMs using only CPU and RAM. This is especially interesting when you want to host a model internally, when GPUs are too expensive, or when data is not allowed to be sent to external AI services.

    Please note: CPU-only inference is usually considerably slower than GPU inference. As a rough estimate, expect performance to be 10 to 50 times slower, depending on the model, CPU, memory, quantization used and context size. For interactive chat this can be annoying, but for tasks such as code analysis, documentation, batch processing or agentic coding, CPU-only can still be useful if speed is not the most important requirement.

    In this article we explain which models and which server size (RAM or RAM + VRAM) you need to effectively use LLMs with Ollama, Llama.cpp, Codex and Claude Code.

    • New models are released regularly. The model you are interested in may not be listed here. In that case, use the memory guidelines to make a choice.
       
    • Would you like to closely match the performance of Claude or ChatGPT? GLM 5.2 is at the moment of writing your best option and requires a minimum of 256GB RAM and preferably a GPU of 24GB on top
       
    • Dedicated CPU cores provide up to 3-4 times faster LLM performance compared with shared CPU cores.
       
    • With the right server size and dedicated CPU cores, 15 tokens per second is achievable. 
       
    • For ordinary chat or simple RAG tasks, a 7B-14B model may already be enough. For Codex / Claude Code-like workflows, you preferably want at least a good 20B-35B model, and preferably a model that is explicitly strong in tool use, structured output, coding and reasoning.
     

     

    The model file is not the same as RAM usage

     

    A common mistake is to look only at the download size of the model. If a model in Ollama is 20 GB in size, for example, that does not mean the full runtime only uses 20 GB RAM.

    Total RAM usage roughly consists of:

    Component What does this mean?
    Model weights The actual model file, for example a Q4 or Q8 quantized model.
    Runtime overhead Extra memory for Ollama, llama.cpp, buffers, tokenizer, scheduler and processes.
    K/V cache The memory required to retain the context of the prompt and conversation.
    Context / prompt Long prompts, large codebases and agent logs increase the K/V cache.
    Operating system Ubuntu, services, SSH, shell, monitoring, filesystem cache, and so on.
    Parallel requests Multiple users or multiple sessions at the same time increase RAM usage.

    That is why a 7.2 GB model may sometimes work in llama.cpp on an Ubuntu server with 8 GB RAM, but not in Ollama. Ollama itself uses additional memory and the operating system also needs RAM. At such tight margins, 500 MB to 1 GB of overhead can already make the difference between “works” and “out of memory”.


     

    Quantization: less RAM, slightly lower quality

     

    To reduce hardware requirements, you can use quantized models. Simply put, the model is stored more compactly. You usually sacrifice a little accuracy, but significantly reduce the required RAM or VRAM.

    Type Memory usage Quality Practical use
    Q3 Very low Lower Only use if RAM is extremely limited.
    Q4 Low Good Usually the best balance for local use.
    Q6 Medium Very good A good balance if you have extra RAM.
    Q8 High Almost original Stronger, but much heavier.
    FP16 / BF16 Very high Original / almost original Mainly useful on powerful GPUs, less so for CPU-only.

    For many local models, Ollama uses a 4-bit quantized variant by default when you only use the model name, for example:

    ollama pull qwen3.5

    This normally fetches the default tag, for example qwen3.5:latest. If you deliberately want a different quantization, you need to choose a specific tag, for example:

    ollama pull qwen3.5:27b
    ollama pull qwen3.5:27b-q8_0

    The exact tag names differ per model. Therefore always check the model’s “Tags” page in Ollama.


     

    Example: Qwen3.5 and RAM per quantization

     

    The table below gives a practical impression of model size/RAM direction for Qwen3.5-like models. This is not the same as full runtime usage at maximum context, but it helps to understand the sizes.

    Qwen3.5 3-bit 4-bit 6-bit 8-bit BF16
    0.8B / 2B ±3 GB ±3.5 GB ±5 GB ±7.5 GB ±9 GB
    4B ±4.5 GB ±5.5 GB ±7 GB ±10 GB ±14 GB
    9B ±5.5 GB ±6.5 GB ±9 GB ±13 GB ±19 GB
    27B ±14 GB ±17 GB ±24 GB ±30 GB ±54 GB
    35B-A3B ±17 GB ±22 GB ±30 GB ±38 GB ±70 GB
    122B-A10B ±60 GB ±70–81 GB ±106 GB ±132 GB ±245 GB
    397B-A17B ±180 GB ±214 GB ±340 GB ±512 GB ±810 GB
    Important: a larger model is usually better, but the jump in RAM usage is enormous. For CPU-only servers, Q4 is often the most realistic choice.

     

    Context size and K/V cache

     

    The context size determines how many tokens the model can take into account at the same time. For simple chat, 4K to 16K context is often enough. For RAG, long documents and codebases, you’ll sooner want 32K to 64K. For Codex / Claude Code-like workflows, 64K or more is often desirable (preferably even 256K or more), because the agent needs to keep a lot of code, terminal output, tool results and previous steps in context.

    But large context is not free. During inference, the model has to store information for every token in the so-called K/V cache.

    The simple explanation:

    • The model file is the “brain”.
    • The prompt and conversation are what you ask at that moment.
    • The K/V cache is the working memory that allows the model to keep using that context efficiently.

    As a result, a large context can cost tens of GB of additional RAM.


     

    Rough formula for K/V cache

     

    The K/V cache depends on the model’s architecture:

    K/V cache ≈ 2 × layers × KV_heads × head_dim × context_tokens × bytes_per_value

    The 2 stands for Key and Value. The number of layers, KV heads and head dimensions differs per model. You therefore cannot reliably calculate the K/V cache based only on “20B” or “70B”.

     

    Example: 20B model with 256K context

    Suppose you have a modern 20B-like model with Grouped Query Attention, for example:

    48 layers
    8 KV-heads
    128 head-dim
    256K context

    Then you get approximately:

    K/V cache type Extra RAM at full 256K context
    F16 / BF16 K/V cache ±48 GiB
    Q8 K/V cache ±24 GiB
    Q4 K/V cache ±12–14 GiB

    Important: a Q4 model does not automatically mean the K/V cache is Q4 as well. In many runtimes, the K/V cache is F16 by default unless you explicitly enable K/V cache quantization. This is an important reason why a model with a seemingly acceptable file size can still require much more RAM once you increase the context.


     

    Example: GLM-5.2 with 1M context

     

    GLM-5.2 is interesting because it is aimed at long agentic engineering tasks and offers a context of around 1M tokens. Due to the MLA/KV compression used, the K/V cache can be much more efficient than with classic attention.

    With a full 1M context and Q4 K/V cache, you roughly end up around 25 GiB K/V cache. With F16/BF16, that would be closer to around 88 GiB K/V cache.

    This is only realistic if the runtime properly supports the model’s compressed K/V cache. If a runtime were to expand the cache to classic K/V heads, 1M context quickly becomes impractical on CPU-only servers.


     

    Ollama versus llama.cpp

     

    Ollama and llama.cpp use similar techniques under the hood, but in practice llama.cpp is often slightly easier to tune if you are at the absolute limit of your RAM.

    Situation Best choice
    You want to get something working quickly Ollama
    You use Codex / Claude Code / OpenCode Ollama
    You want maximum control and minimal overhead llama.cpp
    You are extremely tight on RAM llama.cpp
    You want to switch easily between local and cloud models Ollama

     

    How large should the server be?

     

    The RAM recommendations below are based on CPU-only servers, Q4 models and normal to reasonably large context usage. They are intentionally practical and not theoretically minimal.

    This overview is aimed at “running usefully”, not “theoretically just loading”. A model can sometimes start on less RAM, but then still crash once the prompt, context or tool output becomes larger.

     
    Server RAM Suitable models Expectation
    8 GB 1B–7B Q4, very limited 8B/9B Small models only. Not suitable for Codex/Claude Code-like tasks.
    16 GB 7B–14B Q4 Fine for chat, simple RAG and light coding. Not ideal for large repos.
    32 GB 20B–27B Q4 Good lower limit for serious local coding and tool use.
    48 GB 27B–35B Q4 More comfortable for agentic coding with larger context.
    64 GB 35B–70B Q4, depending on context Strong for local coding, but 70B remains heavy on CPU.
    96 GB 70B Q4 or larger MoE models Usable for strong models, provided speed is less important.
    128 GB gpt-oss 120B, Qwen 122B-A10B, large coder models Good high-end CPU-only server for agentic coding.
    256 GB+ Very large models or multiple sessions Only needed for large 100B+ models, high context or concurrency.

     

    Model suitability for Codex / Claude Code

     

    TL;DR: Does your server have less than 32GB RAM? Then we recommend 1) not using a thinking model and 2) not using your self-hosted LLM for Codex or Claude.

     

    Codex and Claude Code-like tools place higher demands on a model than ordinary chat. The model must not only generate text, but also:

    • be able to understand code;
    • analyse multiple files at the same time;
    • structure tool calls reliably;
    • interpret terminal output;
    • recover from errors;
    • follow instructions strictly;
    • not hallucinate too quickly;
    • sustain long tasks across multiple steps.

    That is why 2B and 4B models are unsuitable for these kinds of workflows. They can generate simple code examples, but often fail on real repositories, refactors, tests, dependency problems and multi-step tasks.

    The star rating below is intended practically: how suitable is the model as a backend for Codex / Claude Code-like agentic coding? The rating is not only about benchmark scores, but also about tool use, coding quality, context and realistic usability on CPU-only servers.

    Model Developer Size / tag size Context Vision Tools Thinking Audio Recommended RAM llama.cpp / Ollama Codex / Claude Code
    gpt-oss 20B OpenAI (US) 14 GB 128K 24 GB / 32 GB ★★★☆☆
    gpt-oss 120B OpenAI (US) 65 GB 128K 64–96 GB / 96–128 GB ★★★★★
    GLM-5.2 Z.ai (CN) 239 GB ±976K / 1M 256 GB ★★★★★
    Mistral Medium 3.5 128B Mistral AI (FR) 80 GB Q4 256K 96–128 GB / 128 GB+ ★★★★☆
    Nemotron3 33B NVIDIA (US) 28 GB Q4 128K 48 GB / 64 GB ★★★★☆
    Qwen3.6 27B Alibaba (CN) 17 GB Q4 256K 24 GB / 32 GB ★★★☆☆
    Qwen3.6 35B-A3B Alibaba (CN) 24 GB Q4 256K 32 GB / 48 GB ★★★★☆
    Qwen3-Coder-Next Alibaba (CN) 52 GB Q4 256K 64–96 GB / 96–128 GB ★★★★★
    Devstral Small 2 24B Mistral AI (FR) + All Hands AI (US) 15 GB Q4 384K local / 256K cloud 24 GB / 32 GB ★★★★☆ (for coding)
    DeepSeek-R1 14B DeepSeek (CN) 9 GB Q4 128K 12–16 GB / 16 GB ★★☆☆☆
    DeepSeek-R1 32B DeepSeek (CN) 20 GB Q4 128K 32 GB / 48 GB ★★★☆☆
    DeepSeek-R1 70B DeepSeek (CN) 43 GB Q4 128K 64 GB / 96 GB ★★★★☆
    Gemma4 12B Google DeepMind (US/UK) 7.6 GB Q4 256K 8 GB very tight / 12–16 GB ★★☆☆☆
    Gemma4 31B Google DeepMind (US/UK) 20 GB Q4 256K 32 GB / 48 GB ★★★☆☆
    Qwen3.5 2B Alibaba (CN) 1.9 GB Q4 256K 4–6 GB / 6–8 GB ★☆☆☆☆
    Qwen3.5 4B Alibaba (CN) 3.4 GB Q4 256K 6 GB / 8 GB ★☆☆☆☆
    Qwen3.5 9B Alibaba (CN) 6.6 GB Q4 256K 8–10 GB / 10–12 GB ★★☆☆☆
    Qwen3.5 27B Alibaba (CN) 17 GB Q4 256K 24 GB / 32 GB ★★★☆☆
    Qwen3.5 122B-A10B Alibaba (CN) ±81 GB Q4 256K 96–128 GB / 128 GB+ ★★★★★

     

    Use cases per server size

     

    RAM

    Recommended amount of RAM (minimum)

    8GB Only use small models for simple chat purposes, for example via ChatBox. Do not expect good Codex / Claude Code results.
    16 GB Good lower limit for usable local LLMs, for example for RAG or Open WebUI, but still quite limited for agents.
    32 GB This is the first true entry-level category for local Codex / Claude Code-like workflows, for example with gpt-oss 20B or Qwen 3.6 27B.
    48 GB  30B-35B-like models become more comfortable here. Suitable for Codex / Claude Code, but do not expect the performance of a top-tier model.
    64–96 GB Suitable for larger models and larger context such as DeepSeek-R1 70B and gpt-oss 120B. Expect around 15 tokens per second and assume that a top-tier model such as GPT 5.5 high scores around 2-3 times higher in synthetic benchmarks. 
    128GB  An excellent server size for CPU-only agentic coding via stronger models such as Qwen 3.5 122B-A10B or Mistral Medium 3.5 128B. There is sufficient room for a large context.
    256GB With 256GB, you can get closest to the paid top models from providers such as OpenAI and Anthropic: with Q4 quantization (also for K/V cache), it is possible to run GLM 5.2.

    If speed is less important (15 tokens per second) and you mainly want it to work well, gpt-oss 120B is one of the most logical choices. The model is relatively compact for its class, is designed for agentic workflows, supports tool use and reasoning, and fits more practically in a server with 96 GB to 128 GB RAM than many other 100B+ models.


     

    Practical settings

     

    1. Keep context deliberately low

     

    Do not automatically use the maximum context. For example, start with:

    Use Starting context
    Simple chat 4K–8K
    RAG / document questions 16K–32K
    Small codebase 32K
    Codex / Claude Code 64K
    Large repo / long sessions 128K+

     

    2. Use K/V cache quantization where useful

     

    If you use long context, K/V cache quantization can save a lot of RAM. A Q4 K/V cache can save tens of GB at large context compared with F16/BF16. Q8 K/V cache is often a safe middle ground. Q4 K/V cache saves more RAM, but comes at a greater cost to quality.

    Test K/V cache specifically with long coding tasks, not only with short prompts.

     

     

    3. Prefer a better 20B–35B model over a weak 70B model

    Bigger is not always better. For Codex / Claude Code, a model that is well trained on coding, tool use and instruction following is often more useful than a larger general chat model.


     

    4. Do not use small models for serious agents

    2B and 4B models are attractive because they run quickly and cheaply, but for real agentic coding they are disappointing. They often lack reliable tool calling, good error recovery, code understanding, long-term planning, consistent patches and understanding of project structure.


     

     

    • Best choice for 32 GB RAM: Devstral Small 2 24B or gpt-oss 20B. Devstral is strong for coding workflows and relatively lightweight. gpt-oss 20B is attractive for tool use, reasoning and agentic focus.
    • Best choice for 48 GB RAM: Qwen3.6 35B-A3B or DeepSeek-R1 32B. This class is powerful enough for serious coding work and still fits reasonably well on CPU-only servers.
    • Best choice for 128 GB RAM: gpt-oss 120B. For a CPU-only server with 128 GB RAM, where speed is less important than quality, gpt-oss 120B is one of the strongest choices (while still performing at 15 tokens per second). It fits more practically in memory than many other large models, is designed for agentic workflows and is strong in tool use and reasoning.
    • Best cloud option via Ollama: GLM-5.2 cloud (also available locally, but at least 256GB RAM required). If local hosting is not a hard requirement, a cloud-hosted version of GLM-5.2 is interesting because of its very large context and focus on long-horizon agentic engineering. It is especially relevant for large repositories and long tasks where a lot of context is needed.

     

    Need help?

    Receive personal support from our supporters

    Contact us