AcademyAcademy
DocsLearnGitHub

Course

AI & LLM Foundations

Loading progress...

  1. 1

    The Idea Behind AI Models

    5 min read

  2. 2

    Agents, Tools and MCP

    2 min read

  3. 3

    Benchmark Methodology

    1 min read

  4. 4

    Technical Correction Register

    3 min read

  5. 5

    AI Network Infrastructure

    4 min read

  6. 6

    Mechanistic Interpretability

    3 min read

  7. 7

    Hardware Economics and Inference

    6 min read

  8. 8

    KV Cache, SSM State, and Context Engineering

    5 min read

  9. 9

    Quantization, Optimization, and Model Metadata

    4 min read

  10. 10

    Self-Attention, Multi-Head Attention, and Cross-Attention

    5 min read

  11. 11

    Source Audit

    2 min read

Publications
  • All publications
  • Publication 01Why a Bigger GPU Doesn't Always Mean Faster AI Inference
  • Publication 02Why Your AI Takes Time to Think Before It Starts Speaking
  • Publication 03The KV Cache: The Memory Behind Every Token
  • Publication 04Multi-Head Attention, Grouped-Query Attention and Multi-Query Attention
← Source publicationsRelated curated lesson →

Source publication. Illustration placeholders and evidence labels are preserved as supplied.

Why a Bigger GPU Doesn't Always Mean Faster AI Inference

Understanding GPU compute, memory bandwidth, prefill, decode, and the hidden economics of running large language models.

Imagine running a restaurant with twenty highly skilled chefs.

The kitchen has excellent equipment, enough space, and plenty of people ready to prepare meals. But there is one problem: ingredients arrive too slowly.

The chefs spend more time waiting than cooking.

Now imagine another restaurant with fewer chefs but a much more efficient supply chain. Ingredients arrive exactly when needed, and the kitchen operates continuously.

Which restaurant serves customers faster?

The answer isn't necessarily the one with more chefs.

This is a useful way to understand an often-overlooked aspect of AI inference: a GPU's computational power does not tell the whole story about how quickly it can generate tokens.

A GPU can have impressive TFLOPS specifications and substantial VRAM capacity yet still struggle to deliver the inference performance you expect.

To understand why, we need to look beyond compute capacity and examine memory bandwidth, model weights, attention, and the two major stages of LLM inference.


1. Compute capacity versus memory bandwidth

When comparing GPUs for AI inference, two specifications deserve particular attention.

Compute capacity describes how quickly a GPU can execute mathematical operations. It is commonly expressed in FLOPS or TFLOPS.

Memory bandwidth describes how quickly data can be transferred between GPU memory and the GPU's processing hardware. It is commonly expressed in GB/s.

Illustrative NVIDIA GPU package with surrounding memory components

Illustrative image supplied with the notes; source credited to NVIDIA by the author.

Using our restaurant analogy:

  • Compute capacity represents how many chefs are available to prepare meals.
  • Memory bandwidth represents how quickly ingredients reach the kitchen.
  • Model weights and other inference data represent the ingredients.

Having more chefs does not guarantee faster service if the ingredients cannot arrive quickly enough.

The same principle applies to GPUs.

If a workload is compute-bound, the GPU's mathematical processing capacity is the limiting factor.

If it is memory-bandwidth-bound, the processing units may spend significant time waiting for data.

This distinction becomes particularly important during autoregressive token generation.

2. Why prefill and decode behave differently

LLM inference is commonly divided into two stages: prefill and decode.

Although both stages use the same model, their computational characteristics are different.

Prefill: processing the prompt

When you submit a prompt to an LLM, the model must process the input tokens.

This is the prefill stage.

The model processes many prompt positions through its layers, performing substantial matrix operations. These operations can be parallelized across input positions.

Because many tokens are processed together, prefill can make substantial use of the GPU's computational capacity.

Its performance is influenced by:

  • Prompt length.
  • Model architecture.
  • Matrix-operation efficiency.
  • Available GPU compute.
  • Memory bandwidth.
  • Attention implementation.

Decode: generating the response

After processing the prompt, the model begins generating output tokens.

This is the decode stage.

Unlike prefill, autoregressive generation proceeds sequentially: the next token depends on the preceding generation step.

At low batch sizes, the GPU repeatedly accesses model weights to calculate each new token. The mathematical work for an individual sequence position may not be sufficient to keep all GPU compute resources busy.

Consequently, decode can become heavily memory-bandwidth-bound.

This is why a GPU with greater computational capacity does not necessarily deliver a proportional improvement in single-request token generation.

Importantly, decode is not always memory-bandwidth-bound. Larger batches, longer contexts, model architecture, and optimized kernels can change the bottleneck.

Comparison of prefill and decode, including KV-cache use, parallelism and typical bottlenecks

AI-generated comparison supplied with the notes. It illustrates typical workloads: prefill can be chunked, and latency also includes other system overhead.

3. The role of model weights and KV cache

There are two important sources of data movement during inference.

Model weights

Model weights contain the learned parameters of the neural network.

During decode, the model repeatedly uses these weights to calculate the next token.

For a large model, the weight data can be substantial. At low batch sizes, repeatedly accessing this data can place considerable pressure on memory bandwidth.

KV cache

The KV cache stores previously computed key and value representations used by attention.

Without a KV cache, the model would need to recompute historical key and value representations during subsequent generation steps.

Instead, it stores and reuses them.

The cache grows as additional tokens are processed, and its memory requirements depend on factors such as:

  • Number of attention layers.
  • Context length.
  • Number of key-value heads.
  • Head dimension.
  • Cache precision.

This is particularly important for long-context inference.

A larger context can increase memory consumption and attention-related data movement.

However, model weights and KV cache are not the same thing. Optimizing one does not automatically optimize the other.

4. Why KV-cache quantization can help

One optimization I investigated was reducing KV-cache precision.

In my baseline Qwen experiment, the cache used FP16. In the optimized experiment, it used Q8_0 for both keys and values.

The idea is straightforward: represent the cached values using fewer bits, reducing the memory required to store them and potentially reducing the amount of cache data moved during attention.

But there is an important distinction:

KV-cache quantization reduces KV-cache storage requirements and can reduce cache memory traffic. It does not directly reduce model-weight traffic.

The actual performance improvement depends on how much of the workload is affected by KV-cache traffic, the implementation of quantized attention kernels, and the overhead associated with quantization and dequantization.

Q8_0 also has block metadata, so its storage is not exactly one byte per value.

This is why an optimization should be measured rather than assumed to provide a fixed percentage improvement.

5. Understanding the Roofline model

The Roofline model provides a useful way to reason about the relationship between compute and memory bandwidth.

Its central concept is arithmetic intensity.

Arithmetic intensity measures how much computation is performed relative to the amount of data transferred.

[ AI = \frac{\text{FLOPs}}{\text{Bytes transferred}} ]

A workload with high arithmetic intensity performs more computation for each byte moved.

A workload with low arithmetic intensity moves relatively more data for each operation.

The simplified Roofline equation is:

[ P_{\text{attainable}} = \min(P_{\text{peak}}, BW \times AI) ]

Where:

  • (P_{\text{peak}}) is theoretical peak compute performance.
  • (BW) is memory bandwidth.
  • (AI) is arithmetic intensity.

Consider an illustrative GPU with:

  • Peak compute: 100 TFLOPS.
  • Memory bandwidth: 600 GB/s.
  • Arithmetic intensity: 50 FLOPs per byte.

The bandwidth-imposed compute ceiling is:

[ 600 \times 50 = 30,000\ \text{GFLOPS} ]

Therefore:

[ P_{\text{attainable}} = \min(100,30) = 30\ \text{TFLOPS} ]

Although the GPU has a theoretical compute capacity of 100 TFLOPS, this particular workload is limited to an estimated 30 TFLOPS by its memory bandwidth.

This is an illustrative calculation, not a prediction of actual application performance.

The important lesson is that the GPU's theoretical compute specification is not necessarily the performance ceiling that matters for a particular workload.

AI-assisted diagram: the rising section represents the memory-bandwidth limit; the flat section represents the compute ceiling. Values are illustrative.

6. What my inference experiments revealed

To connect these concepts with practical engineering, I examined two Qwen inference configurations and a separate Gemma hardware comparison.

Experiment A: Qwen baseline

ConfigurationValue
ModelQwen-3.8-27B
QuantizationQ4_K_M
Weight file sizeApproximately 17.2 GB
GPUNVIDIA A10G, 24 GB
Context4,096 tokens
KV cacheFP16
AttentionStandard

Reported performance:

MetricResult
Prefill240.0 tokens/s
Prompt latency1.478 seconds for 2,500 tokens
Decode20.44 tokens/s
Decode latency7.338 seconds for 150 tokens

Experiment B: Qwen optimized configuration

ConfigurationValue
ModelQwen-3.8-27B
QuantizationQ4_K_M
Weight file sizeApproximately 17.2 GB
Hardware allocationg5.4xlarge / g6-class fleet
Context8,192 tokens
KV cacheQ8_0
AttentionFlash Attention enabled

Reported performance:

MetricResult
Prefill276.1 tokens/s
Decode26.83 tokens/s
KV-cache memory reductionApproximately 48.5%, as reported

The second configuration reported higher prefill and decode throughput.

However, this is not a controlled GPU comparison.

Several variables changed simultaneously:

  • KV-cache precision changed from FP16 to Q8_0.
  • Flash Attention was enabled.
  • Context capacity changed from 4,096 to 8,192.
  • Hardware allocation was not held constant.

The reported decode throughput increased from 20.44 to 26.83 tokens/s.

That is approximately a 31.3% increase, calculated from the reported measurements.

But it would be incorrect to attribute that entire difference to KV-cache quantization, Flash Attention, or a GPU upgrade.

The experiments demonstrate that the combined configuration performed differently. They do not isolate the contribution of each individual optimization.

That distinction matters when publishing engineering findings.

Experiment C: Gemma 4 hardware comparison

I also examined a separate experiment involving Gemma 4 E4B with Q8_0 GGUF weights.

MetricNVIDIA L4 24 GBNVIDIA A10G 24 GB
Prefill260.05 tok/s354.94 tok/s
Decode44.45 tok/s73.72 tok/s

This comparison is interesting because it shows that two GPUs with the same nominal VRAM capacity can produce substantially different reported inference throughput.

However, these results should be treated as observations from the reported test configurations, not universal GPU rankings. Reproducibility requires confirming that the model revision, runtime, context, batch settings, attention implementation, workload and measurement procedure were equivalent.

The comparison also reinforces why identifying the actual GPU matters.

AWS instance families have different hardware mappings. G5 is associated with NVIDIA A10G GPUs, while G6 uses NVIDIA L4 GPUs. The actual device should be confirmed from the live runtime rather than inferred from an ambiguous fleet description.

A CUDA device enumeration log is useful evidence:

CUDA0 : NVIDIA A10G

or:

CUDA0 : NVIDIA L4

The hardware you actually received is more important than the hardware you assumed you requested.

[IMAGE PLACEHOLDER 3: Insert a screenshot of the actual CUDA device enumeration or inference startup log, with sensitive information removed.]

7. What should we measure before upgrading a GPU?

A useful inference benchmark should measure more than tokens per second.

The following metrics help distinguish different aspects of performance:

MetricWhat it tells us
TTFTTime to first token; initial responsiveness
ITLInter-token latency; streaming responsiveness
Decode TPSOutput generation throughput
Prefill TPSPrompt processing throughput
GPU memory usageHow much VRAM the workload consumes
GPU utilizationHow actively the GPU is being used
KV-cache allocationMemory consumed by attention caching

Under consistent measurement boundaries, decode TPS is approximately the inverse of inter-token latency:

[ TPS_{\text{decode}} \approx \frac{1}{ITL} ]

For example, an inter-token latency of 50 milliseconds corresponds to approximately 20 tokens per second.

These metrics should be interpreted together.

A model might have excellent prompt processing speed but relatively slow token generation. Another configuration might improve streaming responsiveness while consuming more memory.

The right configuration depends on the workload.

8. The engineering lesson

The biggest lesson from these experiments is that GPU selection should not be based on TFLOPS or VRAM capacity alone.

A larger GPU can provide more compute, more memory, or greater bandwidth, but whether those improvements translate into faster inference depends on the workload's actual bottleneck.

Before upgrading hardware, ask:

  1. Is the workload compute-bound or memory-bandwidth-bound?
  2. Is the bottleneck occurring during prefill or decode?
  3. How much memory is consumed by model weights?
  4. How much memory is consumed by the KV cache?
  5. Is attention implementation limiting performance?
  6. Is batching changing weight reuse and arithmetic intensity?
  7. Are the benchmark configurations genuinely comparable?

The objective is not simply to find the GPU with the largest specifications.

It is to identify the hardware and runtime configuration that best match the model and workload.


Final thought

A powerful GPU is only one part of an efficient inference system.

Model architecture, quantization, memory bandwidth, attention implementation, batching, context length and runtime configuration all influence performance.

The more I work with inference infrastructure, the clearer this becomes:

Optimizing AI inference is not just about buying more computational power. It is about understanding where the time and data actually go.

This is one of the foundations of building efficient and economically sustainable AI infrastructure.

This article documents my learning and practical inference experiments. Reported benchmark results are identified as observations, not universal hardware claims. Calculations and interpretations are distinguished from directly measured results.