Explore how inference engine settings affect LLM performance within the limits of your local hardware.
llama.cppCUDA & MetalRTX 3080 / M4 Mac Mini
Explore the benchmarks in four units
Compare baseline performance on the RTX 3080 and M4 Mac mini, then explore how model architecture shapes memory use. Unit 3 compares the inference speed of speculative decoding against an auxiliary prediction head while measuring the total VRAM utilization for each. Unit 4 explores how prompt caching reduces repeated work and compares token efficiency across models running the same agent workflow.
01Inference Fundamentals
02Benchmark Scope & Setup
03Baseline Throughput
04Prefill Performance & Microbatch Scaling
05RTX 3080 VRAM Utilization
01
Inference Fundamentals
Hosting an LLM locally requires an engine which loads a pre-trained model and manages the computational resources required to generate responses. This process requires sufficient processing capacity and memory to accommodate the model’s weights and key-value (KV) cache.
Selecting an Inference Engine
The choice of inference engine can significantly impact performance. The optimal choice depends on the specific use case and amount of control required. Common choices include but are not limited to:
llama.cpp: A strong choice for local inference and detailed performance tuning, with broad hardware support and flexible CPU/GPU offloading.
Ollama: Offers streamlined model deployment and management.
vLLM: Ideal for GPU servers that handle concurrent requests and need to scale during demand spikes.
A general overview, not a universal ranking.
Ollama streamlines setup and model management, but that convenience can introduce performance overhead. llama.cpp does not introduce as much overhead and also enables performance tuning but requires familiarity with build systems (CMake). Similarly, vLLM also adds setup and runtime complexity as compatibility must be considered across several dependencies.
02
Benchmark Scope & Setup
The engine of choice for the benchmarks was llama.cpp which was built from source. The two test platforms were a Windows PC with a dedicated NVIDIA RTX 3080 GPU and an M4 Mac Mini. Idle VRAM utilization was minimized in the Windows environment by disabling 3D applications and displays during testing.
Generation throughput: The rate that tokens are generated by the model.
Prefill performance and Microbatch scaling: The rate at which prompt tokens are processed and how that rate changes with the number of prompt tokens processed together in physical batches. This directly affects when the first token is generated.
GPU memory utilization: The total VRAM consumption on the RTX 3080 during workloads.
The family of models above were not selected to suggest they are optimal choices for local AI. Rather they were selected due to their size being compatible with 10GBs of VRAM and also being available in many different quantized formats.
03
Baseline Throughput
Throughput was measured across several output lengths, with 100 GPU-only runs per length for each of three model quantizations. Benchmark scripts that leverage llama.cpp's llama-bench and full results are linked below. The tables report mean throughput ± one standard deviation for the shortest (3,277 tokens) and longest (13,107 tokens) output lengths.
Benchmark context
llama-bench does not always reflect real-world performance. Here, the benchmark aims to compare a memory-constrained environment with a compute-constrained environment.
Llama 3.2 3B is the fastest model on both test platforms whereas Phi 3.5 Mini is the slowest. We also see that Q5_K_M's smaller weights require less memory bandwidth per token than Q8_0's 8-bit weights, resulting in higher throughput in every model. The longer outputs show slower throughput as they give each new token more previous tokens to attend to. This increased computational load per token is most prevalent in the reduced throughput of Phi 3.5 Mini where the 13107 token workload is between ~30% - 38% slower than the 3277 token workload.
Smaller quantized weights can reduce output quality.
Always test outputs on representative tasks. Future works will examine these trade-offs.
04
Prefill Performance & Microbatch Scaling
Prefill processes the input context before output tokens are generated. The prefill rate was measured for all 3 model families at the Q8_0 quantization across 100 runs for different microbatches (n_ubatch) and input prompt sizes. The mean prefill rate ± one standard deviation for the microbatch sizes of 512 tokens and 2048 tokens is reported in the table below. The batch size (n_batch) was held constant at 2048 for all runs as the engine requires that n_batch >= n_ubatch. Benchmark scripts that leverage llama.cpp's llama-bench and full results are linked below.
Batch sizes
n_batch is the maximum logical token batch; n_ubatch limits how many tokens from that batch are processed at once. Since more tokens are available to process during prefill, n_ubatch impacts prompt processing.
Llama 3.2 3B is the fastest model on both platforms, while Qwen3 4B is the slowest. Increasing the microbatch size from 512 to 2048 improves RTX 3080 throughput by 8-12% for 2048-token prompts. This jump in performance is not observed on the M4 Mac-Mini as all available compute was already occupied at n_ubatch=512.
05
RTX 3080 VRAM Utilization
llama.cpp sizes its compute buffers to accommodate the configured microbatch size (n_ubatch). Larger microbatches generally require more memory for intermediate calculations. In the graph below, you can see how the maximum memory utilization varies with different microbatch and input prompt sizes. All models are with quantization Q8_0.
llama-bench adjusts the context size with prompt length.
When the prompt size is less than n_ubatch, llama.cpp will increase memory utilization to process more tokens at once. However, when the prompt size is greater than n_ubatch, llama.cpp will reuse compute buffers for processing the additional tokens. This is noticed by the slope of Peak VRAM Utilization being less steep for n_prompt > n_ubatch.
Running LLM inference in production requires estimating and monitoring memory utilization. This section explains how model weights and the KV cache establish a baseline memory requirement for production workloads.
Model Weights
For fast GPU inference, the model’s learned parameters (weights) are loaded into VRAM, where the GPU can access them at high bandwidth while processing tokens. This puts the minimum requirement for VRAM at the parameter count multiplied by the size of each weight in bytes. For Qwen3-4B (4e9 parameters) at Q8_0 quantization (1 byte), 4GBs of VRAM are utilized just to load the model.
Key-Value Cache
Inference engines also need to allocate memory for a key-value (KV) cache to speed up token generation. Without the cache, the attention mechanism would require the engine to process the entire growing sequence again for each new token. Recomputing attention across a sequence of t tokens requires O(t²) attention work per generation step. Repeating this as the sequence grows to N tokens gives O(N³) total attention work.
With a KV cache, the engine stores the keys and values computed for earlier tokens in each transformer layer. This reduces attention work to O(t) per new token and O(N²) as the sequence grows to N tokens.
Compute buffers also use memory.
These temporary workspaces hold intermediate results during inference. They are outside this section’s analysis because their size depends on runtime settings and backend execution.
02
Attention & KV Cache
Qwen3 4B and Llama 3.2 3B use grouped-query attention (GQA), while Phi-3.5 Mini uses standard multi-head attention (MHA). GQA reduces KV-cache memory by having groups of query heads share key and value heads.
A practical memory–quality trade-off.
The original GQA paper reported model quality close to MHA while substantially reducing KV-cache memory. This makes GQA an attractive architecture in constrained compute environments. It does not imply that it is the best transformer architecture or that GQA models are universally better.
The resulting KV cache size depends on the dimensions chosen for the model architecture:
Number of layers (L)
Number of KV heads per layer (HKV)
Head dimension (dh)
KV cache precision, in bytes per element (sKV)
Context window tokens (T)
KV cache precision (sKV) is independent of model weight quantization. llama.cpp defaults to FP16 for both keys and values, so sKV = 2 bytes per element even when the model weights use Q8_0 (1 byte per element).
When key heads and value heads have equal dimensions and precision, the KV-Cache size for one sequence is:
KV cache bytes ≈ 2 × L × T × HKV × dh × sKV
The table below applies this formula to a single sequence with an 8,192-token context window and FP16 precision for both keys and values (sKV = 2 bytes per element).
Model
Layers
KV heads
Head width
KV cache
Qwen3 4B
36
8
128
1,152 MiB
Phi 3.5 Mini
32
32
96
3,072 MiB
Llama 3.2 3B
28
8
128
896 MiB
In this table, Phi 3.5 Mini’s MHA cache uses 3,072 MiB, compared with 1,152 MiB for Qwen3 4B and 896 MiB for Llama 3.2 3B, which both use GQA.
03
Measured VRAM Utilization
VRAM utilization was logged on an RTX 3080 while running a local instance of llama-server with full GPU offload. The server was initialized with an 8,192-token context window, FP16 precision for both keys and values in the KV cache, and a microbatch size (n_ubatch) of 2,048 tokens. All models used Q8_0 weight quantization. The throughput_1k benchmark in the llama.cpp repository’s speed_bench.py sent prompts to the server with an output sequence length of 1 token (--osl 1). The benchmark script and full results are available below.
llama-server configures the context at initialization.
The roughly constant VRAM usage is consistent with the compute-buffer reuse described in Section 5 of the Inferencing Basics tab. llama.cpp reserves compute buffers ahead of inference, allowing later requests to reuse the workspace when their requirements fit. Here, the fixed 8,192-token context keeps KV-cache capacity unchanged, while similar prompts of roughly 1,000 tokens keep compute requirements comparable. The flat trace supports this explanation, but does not directly measure buffer reuse.
04
Cached Prompt States & System RAM
Prompt states retain the keys and values of processed prompts so they can be cached for later reuse. Prompt-state caching is configured when llama-server is initialized; the engineer specifies the maximum system RAM available for storing prompt states with --cache-ram. The script Section 3 above sets this limit to 12,288 MiB. The time-series plot below shows how llama-server process RAM increases as prompt states are cached for different models. Results were obtained by running the same script, with Windows typeperf polling for process memory.
Time alignment.
The calculated memory timeline is shifted to account for startup overhead, including the time llama.cpp’s speed_bench.py takes to retrieve prompt samples from the nvidia/SPEED-Bench dataset on Hugging Face. The shift aligns the first calculated prompt endpoint with the first substantial increase in measured RAM.
A change of variables expresses memory growth in terms of cumulative input tokens instead of time. Define , where Nj(tj) is the input-token count of prompt j at its cache timestamp tj. The plot below shows process RAM against cumulative input tokens, following the model Mprocess(Ci) = Mprocess,0 + mCi.
Models use different tokenizers.
Identical prompt text can produce different total input-token counts because each model's tokenizer uses different vocabularies and splitting rules. This is discussed at length in Hugging Face’s tokenizer guide.
The results show approximately linear prompt-state cache growth with cumulative input tokens, with the slope proportional to each model's respective dimensions. This explains Phi 3.5 Mini’s steeper growth compared with Qwen3 4B and Llama 3.2 3B. The cached prompt states remain within the 12,288 MiB limit specified by --cache-ram in the llama-server configuration. To make room for new states, llama-serverremoves the oldest cached entries first and discards cached prompts fully contained in a newly saved prompt.
A dedicated multi-token prediction (MTP) head is an auxiliary component trained to predict future tokens using the target model’s hidden representations. During inference, it can propose draft tokens for the target to verify together. Accepted tokens advance the output with fewer sequential target-model passes.
Speculative decoding can accelerate generation by having a smaller, faster draft model propose several future tokens for the main model, called the target, to verify together. The two models use compatible tokenization so the target can interpret the proposals. MTP-based drafting also uses speculative verification; the distinction here is how the draft tokens are produced.
The models tested for speculative decoding were Qwen3-4B as the target and EAGLE3 as the drafter.
02
Benchmark Scope & Setup
The benchmarks used llama-server and llama.cpp’s speed_bench.py on the RTX 3080 and M4 Mac Mini, using the platforms described in Inferencing Basics. The throughput_1k and throughput_2k tests were run for both low- and high-entropy prompts with output limits of 1,024, 2,048, and 4,096 tokens and --spec-draft-n-max varied from 1 to 5 when speculation was enabled. llama.cpp assigns --spec-draft-n-mina default value of 0. There were 30 runs completed for each configuration. The results for throughput_1k are shown below while the results for throughput_2k are available in the linked repository.
Effective throughput for each run is the number of final output tokens, including draft tokens accepted by the target model, divided by server generation time. Rejected draft tokens do not count toward throughput, but their drafting and verification time is included. Because runs can produce different numbers of output tokens, the reported throughput uses an output-token-weighted mean ± one weighted population standard deviation. For a run with a draft limit of n predicted tokens, the weighted mean and standard deviation are:
r̄n = ∑i(Ni · rn,i) / ∑iNi
σn = √(∑i[Ni · (rn,i − r̄n)2] / ∑iNi)
where Ni is the actual output-token count and ri = Ni / ti its generation throughput.
MTP
The MTP benchmark runs used --spec-type draft-mtp. The benchmark scripts and full results are referenced below.
On the RTX 3080, mean MTP throughput in throughput_1k peaks at Max Predicted Tokens of 3 for low-entropy prompts and 2 for high-entropy prompts at OSL 1,024. At OSL 2,048 and 4,096, the best settings rise to 4 and 3, respectively.
The M4 peaks at 1 for both, then slows as the draft limit increases. The M4’s peak at a draft limit of 1 may reflect compute limitations: the added drafting and verification work for longer drafts could outweigh the savings from accepting more tokens per target-model pass.
High-entropy prompts show lower effective throughput.
The MTP head may be less well trained to predict continuations for high-entropy tasks, leading to fewer accepted draft tokens per verification pass. Other work has also observed that draft-token acceptance varies by task. Leviathan et al. (2023), Table 3
Speculative Decoding
The EAGLE3 benchmark runs used --spec-type draft-eagle3. The Hugging Face EAGLE3 draft model was converted to BF16 GGUF with llama.cpp’s convert_hf_to_gguf.py and --outtype bf16 specified.
On the RTX 3080, EAGLE3 throughput peaks at n_predict = 2 at all three tested output lengths, with a lower peak than MTP.
On the M4, every tested n_predict above zero matches or falls below throughput with drafting disabled, so leaving EAGLE3 off gives the best throughput.
03
The VRAM Trade-off
Rollback states and verification buffers require extra VRAM. The auxiliary MTP head or separate draft model also needs VRAM for its weights. Generating and verifying draft tokens adds compute overhead, as does saving and restoring rollback state.
For each output limit, the figures compare the fastest tested draft setting for each method and prompt entropy group with its own no-drafting baseline. The left panel shows effective throughput gains. The right panel shows the corresponding increase in sampled peak VRAM on the RTX 3080.
Across the three output lengths, MTP’s fastest settings improved throughput by 34.8–69.9% while adding 0.40–0.47 GiB of peak VRAM utilization. EAGLE3’s fastest settings improved throughput by 17.9–29.3% while adding 2.62–2.90 GiB. Both methods show larger effective throughput gains at longer output sequence lengths. One possible explanation is that repeated patterns in longer outputs make later tokens easier to predict, increasing the draft-token acceptance rate.
The trade-off depends on the model pairing and MTP head dimensions.
These results apply to Qwen3.5’s MTP head and Qwen3-4B with EAGLE3. Other draft–target pairings may accept more tokens and gain enough throughput to justify extra VRAM. Additionally, the MTP head dimensions can influence the VRAM utilization and throughput gains.
Figures and analysis use the RTX 3080 and M4 Mac Mini benchmark exports. Downloadable summaries and available launch scripts are linked beside the relevant results.
An agent is a program that uses a model to choose actions toward a goal. In each iteration, the agent sends the task and current context to the model. If the model requests a tool, the agent runs it and feeds the result back into the next iteration. The loop ends when the agent returns a final answer or reaches a configured limit.
Agent SDKs
Agent SDKs manage the control loop, including model calls and tool execution. Options include:
For these benchmarks, the agent used Pydantic AI’s OpenAIResponsesModel to send inference requests to a /v1/responses endpoint. The full agent implementation and skills are available in this repository.
Tools are callable functions that let an agent retrieve data or take actions. Model Context Protocol (MCP) standardizes how agents discover and call tools exposed by a server. This benchmark uses FastMCP to expose the tools on a separate Linux machine. Pydantic AI calls them over MCP and feeds the results back to the model. The server implementation is available in this repository.
LLMs
The LLM reasons over the context and generates tokens for tool requests or the final answer. Smaller models can hallucinate by generating plausible but unsupported details, even when the agent has tool results available.
Two model configurations were selected for the benchmark because they consistently generated valid tool calls and completed the task.
The two configurations run within the card’s 10 GB of VRAM and require precise skill and tool definitions for reliable tool use.
02
Benchmark Setup
The benchmark runs the same agent task with both model configurations, serving inference through llama-server on an RTX 3080 desktop or an M4 Mac mini.
The agent and MCP server share a dedicated Linux machine. This prevents the processing and disk I/O of agent actions from interfering with inference or prompt-state caching which would skew benchmark results.
The agent sends prompts to the LLM by alternating between two conversations. One provisions a Python development environment based on a provided specification. The other performs file operations based on the files’ contents. The agent’s skills define how to carry out both tasks.
To measure inference performance and reasoning effort, the launcher scripts ran llama-server with --log-verbosity 4 and captured the following metrics in a .log file.
Processed input tokens
Generated tokens
Tokens reused from cache
Request and task completion times
The launcher scripts and benchmark results for each platform are linked below.
Agentic workflows make repeated model calls as the agent reasons, uses tools, and incorporates their results. These calls often share a long prompt prefix containing instructions and earlier turns. Caching the state for that prefix lets the model reuse it on later calls, reducing prefill work across the workflow.
On each platform, the benchmark ran Qwen3-4B with llama-server in two configurations, one with prompt-state caching enabled and one with it disabled. In both configurations, main.py switched to the other conversation after each agent.run_sync() call completed.
Restoring prompt prefixes from RAM cut cumulative prompt processing by 32.86% on the RTX 3080 and 33.61% on the M4 Mac mini. Prefill was reduced by 21.56% on the RTX 3080 and by 31.55% on the M4 Mac mini.
Prompt Similarity and Cache State
llama-server assigns an inferencing request to a GPU slot based on how recently it was used or the similarity of the incoming prompt and the slot's tracked tokens. The similarity is calculated by dividing the sequence length of shared prompt prefixes, over the prompt length. Should no slot meet the minimum threshold, the inference request is assigned to the most recently used slot.llama-server also tracks how much of the slot's state is being preserved with f_keep.
If the slot was assigned due to recency or a significant portion of the state is being overwritten (f_keep < 0.5), llama-server will first cache the state in system RAM and then load the most similar cached state from RAM. The criteria for this is based on the similarity score and the f_keep value between the incoming prompt and the cached state.
The timelines below compare the cumulative prompt tokens processed with and without RAM caching as the agent alternates between conversations on Qwen3-4B. Dotted lines mark where inferencing requests switched between conversations.
On both platforms, the divergence in cumulative prompt tokens processed occurs during the third message of each conversation. This indicates when llama-server loaded prompt snapshots from RAM. Since the conversations shared skills and system prompts, their common prefix gave the active GPU slot higher f_keep and sim scores on early switches (messages 1 & 2). As the conversation histories grew, the shared prefix accounted for less of the prompt and the slot state.
Define precise agent scopes to improve RAM cache reuse.
Shared context across unrelated workflows can cause requests to reuse the active GPU slot. Keep each agent’s context focused on its workflow to improve the utilization of cached states.
04
Token Efficiency
The same agent and prompts were used to send an inferencing request to a Qwen3.5-4B endpoint with Q6_K quantization. The figures below compare the cumulative generated tokens and engine end-to-end latency of Qwen3.5-4B against Qwen3-4B.
RTX 3080: total generated tokens and engine end-to-end latency across the agent runs.
M4 Mac mini: total generated tokens and engine end-to-end latency across the agent runs.
Qwen3.5-4B was more token efficient than Qwen3-4B, completing the tasks with 85.06% fewer generated tokens on the RTX 3080 and 53.38% fewer on the M4 Mac mini.
Token generation is a significant contributor to end-to-end latency. With fewer tokens to generate, Qwen3.5-4B was 288.76 seconds faster on the RTX 3080 and 1,036.74 seconds faster on the M4 Mac mini.