Running LLMs Locally: The Memory Wall, Unified Memory, and Agent Practices
This article explains why running large language models locally has become a practical choice, and why memory—not raw GPU compute—is the real limiting factor. It walks through how to estimate memory needs (model weights, KV cache, and runtime overhead), the role of unified memory in raising the ceiling on model size, how quantization trades quality for size, and why memory bandwidth drives decode throughput. It then covers building an AI agent around a local model with a tool-calling layer, memory, and an orchestration loop, combining local and cloud resources in a hybrid architecture, and a practical deployment checklist. You'll come away with a systematic way to reason about local LLM performance and to design a working agent application.
1. Why More People Are Running LLMs Locally
Even with cloud APIs just a request away, deploying a large language model on a local machine can seem redundant—yet it delivers irreplaceable value in several scenarios:
- Data privacy and compliance: Sensitive data never leaves the intranet or the device, eliminating exfiltration risk at the source. This is especially valuable in tightly regulated industries such as healthcare, finance, and legal.
- Low latency and offline availability: Local inference removes network round trips, making responses more consistent and keeping the application usable even in disconnected, weak-signal, or edge environments.
- Predictable cost: For high-frequency, long-term workloads, a one-time hardware investment is often more economical than paying per token on the cloud.
- Deep customization: You can swap models freely, adjust quantization precision, and inject private knowledge to build fully self-controlled applications.
That said, “getting a model to run” and “running it well” are two different things. The real challenge of local deployment is not whether you have enough compute, but whether memory can hold up—this is what’s known as the memory wall.
2. The Real Bottleneck: The Memory Wall
Many people assume LLM inference is all about GPU compute (FLOPS), but that is not the case. What determines whether you can load a model in full and run it smoothly is, first, memory capacity, and second, memory bandwidth.
The memory a loaded model needs can be roughly estimated as:
Memory required ≈ model weights + KV cache + runtime overheadModel weights ≈ parameter count × bytes per parameterFor a 30B-parameter model:FP16 (2 bytes/param): 30B × 2 ≈ 60 GBINT8 (1 byte/param): 30B × 1 ≈ 30 GBINT4 (0.5 bytes/param): 30B × 0.5 ≈ 15 GBKV cache ≈ 2 × num_layers × hidden_dim × seq_len × batch_size × bytes(grows faster as context length and concurrency increase)
This formula makes one key point clear: if you don’t have enough VRAM or memory, even the most powerful chip can only run a small 7B-class model. And small models often fall short on complex reasoning, long-context understanding, and code generation. This is precisely where large-capacity unified memory platforms—such as those with 128 GB—add value: they can comfortably hold “mid-size, high-IQ” models with tens of billions of parameters or more (with moderate quantization), giving you near-commercial-grade intelligence locally.
3. Why Unified Memory Architecture Matters
On a traditional PC, the CPU and discrete GPU use two separate memory pools: system memory (DRAM) and video memory (VRAM), which are isolated from each other. VRAM capacity is usually fixed and limited, and this becomes a hard ceiling for running large models locally.
Unified Memory architecture, by contrast, lets the CPU and integrated GPU share a single physical memory pool. The benefits are:
- Elastic capacity: You are no longer boxed in by a small amount of VRAM—however much memory you have is, in theory, how much you can allocate to a model.
- Zero-copy data movement: The CPU and GPU no longer need to shuttle data back and forth between two pools, reducing latency and overhead.
- Smooth heterogeneous cooperation: The CPU handles scheduling and logic while the GPU/NPU handles parallel matrix operations; shared memory keeps the cost of coordinating the two very low.
It is precisely because unified memory raises the memory wall as a whole that these platforms have become popular among local LLM enthusiasts. Of course, unified memory bandwidth is usually lower than the dedicated VRAM of a top-tier discrete GPU—which is the source of the performance behavior discussed in the next section.
4. Model Selection and Quantization: Balancing “IQ” and Size
Since memory sets the ceiling, choosing the right quantization precision is the core way to maximize model capability under capacity constraints.
| Quantization | Relative size | Quality loss | Use case |
|---|---|---|---|
| FP16/BF16 | 100% | Negligible | Ample memory, maximum quality |
| INT8 | ~50% | Very small | Balanced choice for quality and size |
| INT4 | ~25% | Moderate | Tight memory, prioritize speed |
Practical recommendations:
- When memory is plentiful (tens of GB or more available), prefer around 8-bit quantization for minimal quality loss and solid throughput.
- When memory is tight, 4-bit quantization lets larger models fit, but accept some drop in inference quality.
- Pay attention to the impact of context length on the KV cache: long contexts consume memory significantly, so leave headroom when deploying.
- Don’t blindly chase huge parameter counts; define your task needs (chat/summarization/code/reasoning) first, then choose an appropriate size.
A useful rule of thumb: reserve 20%–30% of memory for the KV cache and runtime overhead. Don’t fill memory to the brim at once—otherwise long conversations or high concurrency will quickly hit the boundary and cause crashes or severe slowdowns.
5. The Truth About Inference Throughput: Bandwidth Sets Decode Speed
To understand throughput, you need to distinguish the two phases of inference:
- Prefill: Processes the entire input prompt in parallel. This is compute-intensive and largely bounded by compute.
- Decode: Generates one token at a time, and each step requires reading all model weights from memory. This is memory-bandwidth-intensive.
This gives an approximate relationship:
Single-stream decode throughput (tokens/s) ≈ effective memory bandwidth / model sizeHigher memory bandwidth and a smaller model (more aggressive quantization) yield faster per-request generation.
This explains why unified memory platforms can still deliver a smooth generation experience despite not having a decisive compute advantage—thanks to low-overhead scheduling plus heterogeneous acceleration. It also explains why “bigger and faster” is often a contradiction: a larger model has to read more data at every step, so speed naturally drops. When evaluating a local inference setup, then, you can’t look only at the headline peak compute figure; you have to weigh memory capacity, memory bandwidth, quantization strategy, and scheduling efficiency—factors that constrain one another.
6. From Model to Agent: Building an Orchestrable Application Framework
Getting a model running is just the starting point. What truly makes a local LLM “useful” is building an AI agent on top of it—an application that can autonomously plan, call tools, and reason over multiple steps to accomplish complex tasks.
A typical agent framework has four core components:
- The model core: Responsible for understanding intent and generating reasoning and decisions—the “brain” of the entire agent.
- The tool/function-calling layer: Lets the model read and write files, query databases, and call external services, breaking beyond the limits of pure text generation.
- The memory mechanism: Distinguishes short-term context (the current session) from long-term memory (vectorized knowledge bases/history), supporting continuous, coherent multi-turn interactions.
- The orchestration and scheduling loop: Controls the iterative “think–act–observe” cycle, handling errors, bounding the number of steps, and deciding when to converge.
A minimal agent main loop can be expressed in pseudocode like this:
def agent_loop(user_input, model, tools, max_steps=10):history = [system_prompt, {"role": "user", "content": user_input}]for step in range(max_steps):response = model.generate(history) # model thinksif response.tool_calls: # a tool call is neededfor call in response.tool_calls:result = tools[call.name](**call.args)history.append(tool_result(call, result)) # observe the tool's returnelse: # no tool needed, give final answerreturn response.contentreturn "Maximum steps reached; task did not converge"
A few things to watch in engineering practice:
- Implement the low-overhead scheduling path in a performant language (such as C# or Python) so the framework’s own overhead doesn’t erode inference throughput.
- Add timeouts, retries, and permission isolation to tool calls to keep the agent from falling into infinite loops or executing dangerous operations.
- Introduce logging and tracing to record each step’s reasoning, tool inputs, and returns in full, making debugging and optimization easier.
- Manage the use of the context window by summarizing and compressing long conversations, avoiding unbounded KV cache growth.
7. Local and Cloud Together: A Hybrid Deployment Architecture
Local deployment isn’t meant to replace the cloud; it complements it in a hybrid architecture:
- Local handles: privacy-sensitive, low-latency, offline-capable high-frequency tasks, as well as scenarios that need deep customization.
- Cloud handles: extremely long contexts, inference of very large models, batch offline processing, and peak loads that need elastic scaling.
When building such a hybrid system, you can use foundational cloud capabilities—for example, those from a provider such as Baidu AI Cloud—to connect local and cloud:
- Use object storage to archive model weights, datasets, and inference logs.
- Use a message queue to distribute asynchronous tasks between local nodes and cloud services and to smooth out traffic spikes.
- Use a container platform to standardize the deployment and elastic scaling of cloud-side inference services.
- Use log and monitoring/alerting services to collect end-to-end latency, throughput, and error rates for full-stack observability.
A cloud-side model platform such as Baidu AI Cloud’s Qianfan can serve as the provider of model capabilities on the cloud side, forming a “run light tasks locally, offload heavy tasks to the cloud” split strategy with local inference—balancing cost, privacy, and performance.
8. A Practical Implementation Checklist
Here’s a checklist you can follow directly:
- Estimate memory first: Use the memory estimation formula from earlier to calculate model weights + KV cache, and reserve 20%–30% headroom.
- Then choose quantization: Use 8-bit when memory is plentiful and 4-bit when it’s tight, and test whether quality meets your needs.
- Look at bandwidth, not just compute: Evaluate throughput by actual tokens/s, and be wary of paper peak figures.
- Build a solid agent skeleton: Model core + tool calling + memory + orchestration loop—all four are essential.
- Add observability: Logs, metrics, and traces let you pinpoint problems and optimize performance.
- Plan hybrid deployment: Define the task boundaries between local and cloud, and use general-purpose cloud capabilities to connect the data flow.
9. Summary
The barrier to running LLMs locally has never been whether you can afford the hardware, but whether you can systematically understand and master the memory wall—this core constraint. Large-capacity unified memory raises the ceiling on model size, quantization strategy balances capacity against quality, memory bandwidth sets the ceiling on generation speed, and the agent framework upgrades “a model that can chat” into “an application that can get things done.”
Connect this whole chain, add a local-and-cloud collaborative architecture, and you can find your own optimal solution across privacy, cost, performance, and capability. That’s what makes local LLMs the most interesting and most valuable part of all.
