Running Open-Source LLMs Locally: Memory Sizing, Model Selection, and Initial Setup
Learn how to estimate memory requirements for local LLMs, account for quantization and KV cache, and choose a model that fits your hardware. This guide compares four model size tiers, provides a practical selection checklist, and covers initial preparation for running models with Ollama.
1. The Benefits and Trade-Offs of Running LLMs Locally
Deploying a large language model on your own computer offers three main benefits:
- Local data processing: Sensitive information stays on your device, making local deployment useful for internal documents, source code, and personal files.
- Offline availability: You can keep working without relying on an external service when your internet connection is unavailable or unreliable.
- No per-call service charges: Local inference is useful for frequent experiments, batch processing, and development workflows without usage-based API billing.
The trade-offs are equally clear. Model weights consume substantial RAM or GPU memory, inference speed depends on your hardware, and you must maintain the runtime environment yourself.
Insufficient memory is a common reason local deployments fail: the process may exit before the model finishes loading. Before downloading a model, estimate whether your hardware can accommodate it.
2. Estimate Memory Requirements: Parameters, Quantization, and Context
Memory consumption during inference has three main components:
- Model weights: Determined primarily by parameter count and the number of bits used per parameter.
- Runtime overhead: Includes inference-engine structures, activation buffers, and reserved system memory.
- Key-value cache, or KV cache: Grows with the length of the input and generated output, becoming especially important for long-context workloads.
Quantization and Weight Memory
Quantization is the main way to reduce the memory occupied by model weights. Reducing parameters from 16-bit to 4-bit precision cuts their nominal storage requirement to approximately one-quarter, often with an acceptable loss in model quality.
The following function provides a rough estimate:
def estimate_memory_gb(params_billion, bits, overhead, kv_cache_gb):weights_gb = params_billion * bits / 8total_gb = weights_gb * overhead + kv_cache_gbreturn round(total_gb, 2)# Example: 25.2B parameters, 4-bit quantization,# 1.2 overhead multiplier, and approximately 1.5 GB of KV cacheprint(estimate_memory_gb(25.2, 4, 1.2, 1.5)) # Output: 16.62
The expression params_billion * bits / 8 gives the nominal weight size directly in decimal GB: one billion parameters stored at 8 bits per parameter occupy 1 GB.
In this example, the weights require approximately 12.6 GB. Applying the 1.2 overhead multiplier increases that to about 15.1 GB. Adding 1.5 GB for the KV cache brings the total to approximately 16.6 GB.
What the 1.2 Overhead Multiplier Means
The multiplier is a planning allowance for inference-engine internals, activation buffers, and system headroom. It is not a theoretical constant.
The appropriate allowance varies by framework and hardware. A rough planning range is 1.1–1.3; use 1.2–1.3 for a more conservative estimate.
Estimating KV Cache Size
As a model processes tokens, it stores the keys and values needed for attention. A rough estimate is:
kv_cache_gb ≈ 2 × num_layers × num_kv_heads × head_dim× context_length × bytes_per_element × batch_size / 10^9
Consider a hypothetical model with:
- 36 layers
- 8 KV heads
- A head dimension of 128
- 2 bytes per cache element, using FP16
For a single sequence, a context length of 4,096 tokens requires approximately 0.6 GB of KV cache. At 32,768 tokens, that rises to approximately 4.8 GB. Increasing context length eightfold also increases the cache eightfold.
Many inference tools support KV cache quantization, which can substantially reduce this memory requirement.
Allow More Headroom for Small Models
Simple parameter-based estimates can understate actual memory consumption, especially for smaller models. The quoted parameter count may not describe every component that must be loaded, and components such as embeddings and multimodal encoders can make up a substantial share of the total footprint.
Reserve additional headroom for small models and use measured memory consumption as the final reference.
3. Comparing Four Model Size Tiers
The following table groups models into four broad tiers. The memory figures are estimates for 4-bit quantization, not benchmark measurements. They include weights and general runtime overhead, but not the additional KV cache required by your chosen long-context configuration.
The context lengths and multimodal capabilities shown describe the configurations summarized here; they are not guaranteed by parameter count alone. Before downloading, verify the specific model, version, quantization format, and publisher specifications.
| Tier | Parameter scale | Estimated memory at 4-bit | Context length | Multimodal support | Typical use |
|---|---|---|---|---|---|
| Small on-device | About 2.3B | About 4 GB | About 128K tokens | Images and audio | Phones and embedded devices |
| Small-to-medium | About 4.5B | About 5.5 GB | About 128K tokens | Images and audio | Everyday chat and lightweight tasks |
| Mixture of experts | About 25.2B total; about 3.8B active per token | About 16–18 GB | About 256K tokens | Images | Balancing quality and speed |
| Large dense | About 30.7B, with all parameters participating in computation | About 17–20 GB | About 256K tokens | Images | Complex tasks where quality takes priority |
Why a Small Model Might Still Need 4 GB
The 4 GB estimate for the small on-device tier is noticeably higher than the approximately 1.2 GB suggested by a simple 4-bit calculation for 2.3 billion parameters.
One possible reason is that the quoted parameter figure counts only parameters active during inference, while embeddings and multimodal encoders must still be loaded in full. For this tier, rely on measured memory requirements rather than the weight formula alone.
Understanding Mixture-of-Experts Models
Mixture-of-experts, or MoE, models require a distinction between total and active parameters:
- Total parameters determine the weight footprint. A model with 25.2 billion total parameters needs memory comparable to a dense model of a similar total size.
- Active parameters determine much of the per-token computation. Activating approximately 3.8 billion parameters per token can bring computational requirements closer to those of a medium-sized model.
This architecture can be useful when you have enough memory and want a balance between quality and speed. Its advantages are harder to realize when memory is limited.
Which Tier Fits Your Workload?
Small on-device models
Suitable for phones, compact development boards, and simple local tasks such as text classification or short rewrites. They are not a good fit for complex reasoning or long-document analysis.
Small-to-medium models
Suitable for organizing notes, everyday questions, and short code snippets. They are less appropriate for tasks requiring highly accurate, extended reasoning.
Mixture-of-experts models
Worth considering when you have more than 16 GB of available RAM or GPU memory and want to balance quality and speed. Avoid this tier below 16 GB, and check the full estimate carefully: the listed 16–18 GB footprint still needs additional headroom and KV cache capacity.
Large dense models
Better suited to devices with at least 24 GB of GPU memory or 32 GB of unified memory, particularly for complex reasoning and long-form writing. Because all parameters participate in each inference step, these models may feel slow in latency-sensitive interactive use.
4. A Model Selection Checklist
Before downloading a model, check these five items:
- RAM or GPU memory: Check available capacity, not just installed capacity, and leave at least 20% headroom.
- Context length: Determine your usual input length and estimate the KV cache requirement using the formula above.
- Multimodal requirements: Decide whether you need image or audio processing. If not, a text-only version can save memory.
- Response speed: Establish what response time is acceptable. Larger models generally take longer to generate an answer.
- License: Read the model license and confirm that it permits your intended use, especially commercial use.
To check available memory:
- Windows: Open Task Manager.
- macOS: Open Activity Monitor.
- Linux: Run
free -h. - NVIDIA GPUs: Run
nvidia-smito inspect GPU memory.
5. Initial Setup with Ollama
Ollama combines model downloading, loading, and an inference interface, making it a practical starting point for running a model locally.
Step 1: Check Free Disk Space
Downloads can create temporary files. Ideally, keep more than twice the model’s download size available on disk.
Step 2: Install Ollama
On Windows and macOS, download the installer from the official Ollama website.
