Back to Blog
AIPublished on October 17, 2026

Simulating Inference Before You Buy: Deconstructing Memory Bandwidth, KV-Cache Pressure, and Roofline Profiling in Local LLMs

Purchasing hardware for local LLMs often leads to unexpected performance bottlenecks due to misunderstood memory architectures. This guide deconstructs roofline models, KV-cache degradation, and bandwidth emulation to predict exact token throughput before spending a dime.

The Spec Sheet Fallacy: Why TFLOPs Lie in Autoregressive Inference

When evaluating modern hardware for running local Large Language Models (LLMs), engineering teams and enthusiasts frequently fall into the "TFLOP trap." Marketing materials proudly advertise massive FP16/BF16 compute numbers, leading buyers to believe that a high-compute desktop GPU or a neural-compute accelerator will effortlessly run 70B parameter models at conversational speeds.

However, in single-user autoregressive generation, theoretical compute power is almost entirely decoupled from real-world token generation rates. While prompt processing (the "prefill" phase) is compute-bound, token generation (the "decode" phase) is brutally memory-bandwidth-bound.

In autoregressive decoding, the model generates text token by token. To produce a single token at batch size 1, the hardware must stream every single parameter weight from high-bandwidth memory (DRAM/VRAM) into the on-chip processor registers or SRAM, perform a matrix-vector multiplication (GEMV), and discard those weights until the next cycle. Unless your memory subsystem can deliver weights to the compute cores at blistering transfer rates, those expensive Tensor Cores or vector units will spend up to 95% of their clock cycles idle, stalled on memory fetch operations.

Understanding and accurately emulating this performance envelope before investing thousands of dollars in silicon requires a deep dive into the Roofline Model, memory hierarchies, and the real impact of KV-cache growth.


The Roofline Model: Arithmetic Intensity of the Decode Phase

The fundamental metric governing inference latency is Arithmetic Intensity, defined as the number of floating-point operations performed per byte of data transferred from memory:

$$\text{Arithmetic Intensity} = \frac{\text{FLOPs}}{\text{Bytes Transferred}}$$

Prefill vs. Decode Dynamics

  1. Prefill Phase (GEMM): When processing an initial prompt of length $N$, the weight matrices are multiplied against an input tensor of size $N \times D$. Here, the arithmetic intensity is high because the weights loaded into cache are reused across all $N$ tokens. This phase saturates the compute units (Matrix-Matrix multiplication), making high TFLOPs relevant.
  2. Decode Phase (GEMV): In token-by-token generation, the input is a single vector ($1 \times D$). Each parameter in the model must be loaded from memory to compute a single operation for that token.

For a standard 16-bit model (2 bytes per parameter), generating one token requires:

  • Compute: $\approx 2 \times P$ FLOPs (where $P$ is the parameter count).
  • Memory Read: $\approx 2 \times P$ bytes transferred.

$$\text{Arithmetic Intensity}_{\text{decode}} = \frac{2 \times P \text{ FLOPs}}{2 \times P \text{ Bytes}} = 1 \text{ FLOP/Byte}$$

If your GPU provides 1,000 GB/s (1 TB/s) of memory bandwidth, the absolute theoretical upper bound for generating tokens on an unquantized model can be approximated by:

$$\text{Max Tokens/sec} = \frac{\text{Memory Bandwidth (Bytes/s)}}{\text{Model Size in Bytes}}$$

For a 70B FP16 model (140 GB footprint), a hypothetical 1 TB/s memory bus yields:

$$\text{Max Tokens/sec} = \frac{1000 \text{ GB/s}}{140 \text{ GB}} \approx 7.14 \text{ tokens/sec}$$

No amount of additional compute cores will push this generation speed higher if the memory bus is saturated.


Factoring in Quantization and Kernel Dequantization Overhead

Quantization techniques (GGUF k-quants, AWQ, EXL2) shrink the model footprint, reducing the denominator in our bandwidth equation. An 8-bit quantized model halves the memory read requirements; a 4-bit quantization reduces it by roughly a factor of four.

| Precision | Bytes per Param | 70B Footprint | Theoretical Tok/s (1000 GB/s Bus) | Practical Tok/s (Accounting for Kernel Overhead) | | :--- | :--- | :--- | :--- | :--- | | FP16 | 2.0 | 140 GB | 7.14 | ~6.5 | | Q8_0 | 1.0 | 70 GB | 14.28 | ~13.1 | | Q4_K_M | ~0.55 | ~38.5 GB | 25.97 | ~21.5 | | Q2_K | ~0.33 | ~23.1 GB | 43.29 | ~32.0 |

Notice the widening gap between theoretical maximum and practical throughput at lower bit-widths. This discrepancy occurs because of dequantization overhead.

When executing quantized GEMV kernels (such as those in llama.cpp or ExLlamaV2), the memory controller streams 4-bit packed weights from VRAM to SRAM. The compute units must unpack and scale these integer representations back to FP16 in-flight before performing the dot product with the hidden state.

At extreme quantizations (e.g., 2-bit), the operational intensity shifts back toward the compute boundary. If the GPU's integer ALU throughput or register file capacity is constrained, the kernel can become compute-bound or register-spill limited, diminishing the returns of the reduced memory footprint.


The Silent Performance Killer: KV-Cache Expansion

A static bandwidth calculation assumes context length is zero. In production, as the conversation history grows, the Key-Value (KV) Cache exerts significant pressure on both memory capacity and memory bandwidth.

For every layer in the Transformer, the key and value states of previous tokens must be retained to compute multi-head attention. For standard Multi-Head Attention (MHA), the memory footprint of the KV cache per token is calculated as:

$$\text{Memory per Token} = 2 \times \text{Layers} \times \text{Heads} \times \text{Head Dimension} \times \text{Precision (Bytes)}$$

Consider Llama-3-70B using Grouped-Query Attention (GQA):

  • Layers: 80
  • KV Heads: 8 (reduced from 64 query heads via GQA)
  • Head Dim: 128
  • Precision: FP16 (2 bytes)

$$\text{Bytes/Token} = 2 \times 80 \times 8 \times 128 \times 2 = 327,680 \text{ Bytes} \approx 320 \text{ KB/token}$$

At a context depth of 32,768 tokens, the KV cache consumes:

$$\text{Total Cache} = 32,768 \times 320 \text{ KB} \approx 10.48 \text{ GB}$$

Crucially, during the decode phase of token $T_{i}$, the model must load the KV caches of all preceding $T_{0} \dots T_{i-1}$ tokens to compute the attention matrix. The memory bandwidth equation must be updated:

$$\text{Effective Bandwidth Demand per Token} = \text{Model Weights} + \text{KV Cache Size}(T)$$

As the context window fills, the data transferred per step increases, causing a perceptible, progressive degradation in token generation speed.


Emulating Hardware Latency via Synthetic Stream Throttling

Developers frequently turn to interactive profilers and emulation tools like Llmspeed to evaluate whether a target hardware profile delivers an acceptable user experience before purchasing machines.

Building an accurate client-side latency emulator requires modeling the inter-token arrival time distribution rather than simply applying a flat delay. In real inference engines, token delivery is non-uniform due to system interrupts, page faults in paged attention, and garbage collection in high-level runtimes.

Below is a lightweight Python script that mathematically models and reproduces the exact streaming experience of a target hardware specification, accounting for model quantization, bus bandwidth, and context-dependent KV-cache drag:

import time
import sys
import random

def simulate_inference(
    prompt: str,
    max_tokens: int,
    param_count_billions: float,
    bits_per_weight: float,
    mem_bandwidth_gbps: float,
    kv_bytes_per_token: int = 327680  # Llama-3-70B GQA default
):
    # Calculate raw weight footprint in Gigabytes
    weight_size_gb = (param_count_billions * 1e9 * (bits_per_weight / 8)) / (1024**3)
    
    # Prefill phase approximation (Compute-bound TTFT simulation)
    prompt_length = len(prompt.split())
    ttft = max(0.05, (prompt_length * param_count_billions * 2) / (mem_bandwidth_gbps * 15))
    
    print(f"[*] Emulating: {param_count_billions}B Model @ {bits_per_weight}-bit")
    print(f"[*] Target Memory Bandwidth: {mem_bandwidth_gbps} GB/s")
    print(f"[*] Base Model Footprint: {weight_size_gb:.2f} GB")
    print(f"[*] TTFT: {ttft:.3f}s... Processing prompt.")
    time.sleep(ttft)
    
    text_stream = "The rapid emergence of edge-compute architectures challenges the legacy centralized datacenter paradigm..."
    sample_tokens = text_stream.split()
    
    current_context = prompt_length
    print("\n--- Generation Start ---\n")
    
    for i in range(max_tokens):
        # Calculate current KV cache footprint in GB
        kv_footprint_gb = (current_context * kv_bytes_per_token) / (1024**3)
        total_data_moved_gb = weight_size_gb + kv_footprint_gb
        
        # Theoretical generation time step based on memory bus limits
        base_step_time = total_data_moved_gb / mem_bandwidth_gbps
        
        # Add stochastic noise for kernel dispatch and system jitter (2-5%)
        jitter = base_step_time * random.uniform(0.02, 0.05)
        step_time = base_step_time + jitter
        
        time.sleep(step_time)
        
        token = sample_tokens[i % len(sample_tokens)] + " "
        sys.stdout.write(token)
        sys.stdout.flush()
        
        current_context += 1
        
    tok_per_sec = 1.0 / step_time
    print(f"\n\n--- Final Metric: {tok_per_sec:.2f} tok/s at context length {current_context} ---")

if __name__ == "__main__":
    # Simulate Llama-3-70B Q4_K_M on an Apple M3 Max (Unified Memory: ~400 GB/s bus)
    simulate_inference(
        prompt="Analyze the structural limits of high-bandwidth memory.",
        max_tokens=30,
        param_count_billions=70.0,
        bits_per_weight=4.5,
        mem_bandwidth_gbps=400.0
    )

Architectural Tiers: Where Hardware Reality Hits

When evaluating deployment targets, the physical memory topology dictates the ceiling of your performance:

1. Consumer Dual-Channel DDR5 (e.g., Intel Core i9 / AMD Ryzen 9)

  • Theoretical Bandwidth: 60 to 90 GB/s.
  • Reality: Running a 70B model at Q4 (~39 GB) on CPU-only system memory caps throughput at an abysmal 1.5 to 2.2 tokens per second. It is usable only for asynchronous batch tasks, entirely unsuitable for interactive agentic workflows or low-latency conversational user interfaces.

2. Apple Silicon Unified Memory Architecture (UMA)

  • Theoretical Bandwidth: 150 GB/s (Base Pro) to 819 GB/s (M2/M3/M4 Ultra).
  • Advantage: Apple's UMA enables the GPU to access massive pools of shared system memory (up to 192 GB on Ultra chips) without crossing high-latency PCIe buses. An M2 Ultra with 800 GB/s bandwidth runs a 70B Q4 model at roughly 18–20 tokens/sec, making it one of the most cost- and power-efficient developer workstations for massive parameter models.

3. Discrete Desktop GPUs (PCIe Interface)

  • RTX 4090 (24 GB VRAM): ~1,008 GB/s memory bandwidth.
  • The Offloading Trap: A 70B model does not fit in 24 GB of VRAM. If you offload partial layers to system RAM over PCIe Gen 4 x16 (~31.5 GB/s bidirectional), your inference pipeline drops to the speed of the slowest link. The system will run at sub-4 tokens per second despite the card having over 1 TB/s internal VRAM speed.

The Hardware Procurement Rulebook

Before allocating capital to local LLM infrastructure, use this three-step validation framework:

  1. Verify Complete In-Memory Fit: Ensure (Model Footprint) + (KV Cache for Max Target Context) < 90% of Total Dedicated Fast Memory. If any layer falls back to system DDR5 or swap, performance degrades exponentially.
  2. Calculate Pure Bandwidth Throughput: Divide your hardware's measured (not marketed) memory bandwidth by the quantization size of your selected model. Discount this number by 15% to account for kernel scheduling overhead, quantization unpacking, and context length scaling.
  3. Test the Subjective Latency: Use token-speed emulators on your local machine to determine if the calculated tokens per second meets human-factors standards for your application. Reading speed averages 4–5 tokens per second; code review and multi-agent loops demand 25+ tokens per second to feel responsive.

Inference performance is fundamentally a plumbing problem. Prioritize memory bus width, memory topology, and caching strategies over raw teraflops, and you will consistently design hardware footprints that deliver sustained, cost-effective performance.

#Local LLMs#Hardware Benchmarking#Memory Bandwidth#Inference Optimization