Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Sizing CPU, Memory & Storage for AI Agent Workloads

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide helps you determine the right CPU, RAM, and storage for running self-hosted AI agents—whether you're using open-source language models, automation frameworks, or retrieval-augmented generation (RAG) pipelines. You'll learn a practical sizing method based on model size, concurrency, and data volume, plus how to avoid common bottlenecks.

What You'll Need

  • Your target AI model name and its parameter count (e.g., 7B, 13B, 70B).
  • Estimate of concurrent users or agent tasks per minute.
  • Planned context window length (tokens) and expected document corpus size for RAG.
  • Basic familiarity with Docker, Kubernetes, or your chosen deployment method.

Step-by-Step

  1. Identify the model and its memory footprint. For a transformer-based LLM, the VRAM/RAM needed for weights is roughly parameters (in billions) × 2 bytes for FP16, or × 4 bytes for FP32. For a 7B model in FP16, that's ~14 GB just for weights. Add ~20% overhead for activations and inference state.
  2. Decide on quantization. Using 4-bit quantization (e.g., GPTQ, AWQ) cuts weight memory to ~parameters × 0.5 bytes—a 7B model then needs ~3.5 GB. This is often the sweet spot for self-hosting on a single GPU or CPU+RAM setup.
  3. Calculate CPU cores for inference. If running on CPU, a rough rule: for a 7B model, you need at least 8–16 CPU cores for acceptable speed (2–5 tokens/sec). For 13B, 16–32 cores; for 70B, 64+ cores or a GPU. For GPU inference, 4–8 CPU cores are usually enough for data loading and preprocessing.
  4. Estimate memory for the model plus context. Each token in the context window consumes roughly 2 bytes per layer per parameter (for attention). A simpler estimate: add context_tokens × 2 KB per 1B parameters. For a 7B model with 8K context, that's ~112 MB extra—negligible vs. weights. But for long contexts (32K+), it adds up.
  5. Add memory for the agent framework and tools. Agent frameworks (LangChain, AutoGPT, etc.) and any vector database (Chroma, FAISS) typically need 2–4 GB RAM. If you run multiple agents concurrently, multiply that by the number of concurrent processes.
  6. Size storage for the model and data. The model file itself: 7B FP16 ~14 GB, 4-bit ~4 GB. Add your document corpus for RAG: if you have 100 GB of PDFs, expect ~1–2× that for embeddings and indexes. Use SSD/NVMe for both model and vector DB—latency matters.
  7. Account for concurrency. Each concurrent request or agent run consumes additional memory for the context and intermediate states. A safe multiplier: total_memory = (model_memory + context_memory) × (1 + 0.2 × expected_concurrency). For 5 concurrent agents, that's 2× the base.
  8. Add headroom for the OS and other services. Reserve 20–30% of RAM for the OS, Docker, logs, and monitoring. So if your calculated memory is 32 GB, plan for 40–48 GB total.
  9. Choose storage type and size. For models and vector DBs, NVMe SSD with at least 2× the model size plus your corpus size. For logs and checkpoints, add 10–20% extra. If you use a vector DB, plan for index size = ~1.5× your document size.
  10. Test with a realistic load. Deploy a single agent first, measure actual CPU, RAM, and disk I/O using htop and iostat. Then scale concurrency gradually and watch for bottlenecks. Adjust your sizing based on real metrics, not just estimates.

Common Mistakes

  • Underestimating context memory. Long-context models (128K tokens) can consume several GB just for attention, especially on CPU. Always calculate context memory separately.
  • Ignoring quantization overhead. 4-bit models still need some FP16 compute buffers; don't assume the file size is the total RAM.
  • Using HDD for models or vector DBs. Loading a 7B model from HDD can take minutes, and vector search becomes painfully slow. Always use SSD/NVMe.
  • Forgetting about swap. If you rely on swap, performance tanks. Never size memory so tight that you swap.
  • Overprovisioning CPU for GPU inference. If you have a GPU, you don't need 64 CPU cores; focus on PCIe bandwidth and GPU memory.

Tips

  • Start with a quantized model (4-bit) to save memory and allow a smaller, cheaper instance.
  • Use a vector database with built-in compression (e.g., product quantization) to reduce storage.
  • If your agents are I/O-bound (calling APIs), you can run many on modest hardware—just watch network latency.
  • Monitor with Prometheus/Grafana or simple top to see real usage patterns before scaling up.
  • Consider using a GPU for anything above 13B parameters; CPU inference will be too slow for interactive agents.

Troubleshooting

  • Out-of-memory (OOM) errors. Reduce concurrency, switch to a smaller quantized model, or increase swap (but prefer adding RAM). If using Docker, set memory limits and ensure the host has enough free RAM.
  • Slow token generation. Check CPU usage—if it's pegged, you need more cores or a GPU. Also verify that the model is not using swap (check free -h).
  • Disk I/O bottleneck. If loading the model takes minutes, move it to an NVMe drive. For vector DB, ensure the index fits in RAM; if not, reduce corpus size or use a smaller embedding model.
  • Agent crashes randomly. Check system logs for OOM killer messages. Increase memory or add a swap file temporarily, but fix the root cause by reducing memory pressure.
  • High latency when multiple agents run. Look at CPU steal time (in cloud VMs). If high, you're oversubscribed; upgrade to a dedicated instance.

Frequently Asked Questions

  • Can I run a 70B model on a single consumer GPU? Only with aggressive quantization (4-bit) and even then it needs 35–40 GB VRAM, which exceeds most consumer cards. You'd need a 48 GB GPU or offload to CPU, which is slow.
  • How much RAM do I need for a 7B model with 8K context? For 4-bit quantized, about 4 GB for weights + 1–2 GB for context/activations, so 6–8 GB total. For FP16, 14 GB + 2 GB = 16 GB.
  • Is CPU-only inference viable for AI agents? Yes, for small models (1–7B) with 4-bit quantization and patience. For interactive agents, a GPU is recommended.
  • How much storage does a vector database need? Typically 1.5–2× the size of your source documents, depending on embedding dimension and index type. For 100 GB of text, plan for 150–200 GB.
  • Should I use RAM or VRAM for the model? VRAM is much faster. If your GPU has enough VRAM, use it. Otherwise, you can offload to system RAM, but expect a 10–100× slowdown.
  • Can I run multiple agents on one machine? Yes, if you have enough memory and CPU. Use containerization to isolate them and set memory limits to prevent one from crashing the host.