Author note: I’m a graphics engineer exploring how GPU optimization instincts from games and AR/VR transfer to modern LLM inference.
Introduction
After years of optimizing GPU workloads in games and AR/VR, I wanted to answer a practical question:
How much of graphics performance optimization intuition transfers to LLM inference?
The short answer: a lot.
The vocabulary changes. Instead of shaders, render targets, texture compression, and frame budgets, you hear about CUDA kernels, KV caches, quantization, and tokens per second. But the core skill is familiar: understand the hardware, identify the bottleneck, reduce unnecessary memory traffic, and measure whether the optimization actually moved the needle.
The goal of this article is to provide a practical introduction to inference optimization for real-time graphics engineers.
For this project I benchmarked open-source Qwen3 models using llama.cpp on an RTX 3090. I focused on practical inference optimizations that show up in real systems:
Weight quantization
Flash Attention
KV-cache compression
Speculative decoding
Workload-specific tradeoffs
Being open source, Qwen3 provides a convenient playground for exploring optimization strategies. However, the goal was not to produce a single leaderboard number or provide the last word in how to optimize Qwen specifically. The goal was to build a general purpose optimization map that can be used broadly: which technique helps which bottleneck, when it fails, and why.
Naming Primer: Reading a Model Name
Before getting into the benchmarks, it is worth decoding the model names. The names look cryptic at first, but they contain useful information about the model family, size, file format, and quantization strategy.
Take this example:
Qwen3-8B-Q4_K_M.gguf
Read it as:
The parameter-count suffix is straightforward:
0.6B= about 600 million parameters. I used this as a small draft model for speculative decoding.8B= about 8 billion parameters. This was the main benchmark target.14B= about 14 billion parameters. This was useful as a slower target where speculative decoding had a better chance of paying off.
Further explanation on the quantization suffix:
In GGUF / llama.cpp naming, Q generally means a quantized weight format, and the number is the approximate bit depth. So:
Q8_0is an 8-bit quantization format. It is large and relatively high quality, so I used it as a conservative baseline.Q6_Kis roughly 6-bit.Q5_K_Mis roughly 5-bit.Q4_K_Mis roughly 4-bit and was the best practical speed/quality tradeoff in these tests.Q3_K_MandQ2_Kare more aggressive low-bit formats.
The suffixes after the bit number describe the quantization scheme:
_0/_1are older/simple quantization variants. For example,Q8_0andQ5_0._Kmeans a newer blockwise “K-quant” format in llama.cpp. These usually give better quality for a given size than the older simple formats._S,_M, and_Lmean small, medium, and large variants within that quant family. Larger variants usually spend a little more storage on scales/metadata or mixed precision to preserve quality. In practice,_Mis often a good default.
IQ formats are another family:
IQmeans importance-aware quantization. These formats use calibration information — often called an importance matrix or imatrix — to preserve the weights that matter most.IQ3_XXSis an importance-aware, roughly 3-bit, extra-extra-small format. It was the fastest quant in my testing, but it also moved farther away from the quality plateau.
The important caveat: these names are not exact mathematical descriptions of every weight in the file. A name like Q4_K_M does not mean every tensor is naively stored as exactly 4 bits. GGUF quant formats can use blockwise scales, mixed tensor treatment, and format-specific packing. For this project, the useful mental model is:
lower bit depth = fewer bytes moved per token = usually faster decode,
but also more compression error and sometimes slower kernels.That last clause matters. Q3_K_M was smaller than Q4_K_M but slower in my tests, which is a good reminder that compression format and kernel efficiency matter just as much as file size.
Setup
Hardware
NVIDIA RTX 3090 24GB, used as the primary benchmark GPU, and connected to my laptop via a Razer Core X GPU enclosure
NVIDIA RTX 5080 Laptop GPU, used for comparison and one split-device speculative decoding test
Runtime
llama.cpp CUDA backend
GGUF model format
Windows host environment
Models
Qwen3-8B: primary dense model for most experiments
Qwen3-0.6B: draft model for speculative decoding
Qwen3-14B: slower target model for speculative decoding break-even testing
The Bridge: Graphics Concepts to AI Inference
Many LLM inference concepts have a conceptually similar counterpart in real-time graphics. For someone familiar with graphics optimization for games, etc., it can be useful to keep these in mind.
That last row is the key. A lot of LLM inference performance is not limited by how many FLOPs the GPU can theoretically execute. It’s limited by how many bytes the GPU has to move per generated token.
Graphics engineers will find that very familiar territory.
Profiling — Prefill and Decode Are Different Workloads
The first useful split is between prefill and decode.
Prefill processes the prompt. This is batch-like: many tokens are processed together, matrix operations are large, and arithmetic intensity is relatively high.
Decode generates new tokens one at a time. Each token depends on the previous one, so the GPU repeatedly runs small sequential steps and streams model weights / KV-cache data.
This distinction matters because a model can be fast at prefill and slow at decode, or vice versa. “Tokens per second” is not one workload.
A graphics analogy: prefill is closer to a big compute dispatch with enough work to fill the GPU. Decode is closer to repeatedly launching a small latency-sensitive pass where memory traffic and scheduling overhead dominate. Or alternatively, prefill is like loading rendering data (meshes, textures, shaders, etc.), and decode is like rendering frames.
This showed up repeatedly in the results. Q8_0, for example, had strong prefill performance in some cases but much worse decode throughput than Q4_K_M because decode is more sensitive to weight bandwidth.
Quantization — The Texture Compression of AI
If you come from graphics, weight quantization feels immediately familiar: it’s texture compression for neural networks.
A full-precision model stores weights in high precision, usually FP16 or BF16. That’s useful for training and maximum fidelity, but inference often needs to move the same weights repeatedly for every generated token. Smaller weights mean fewer bytes per token.
The tradeoff is the same one graphics programmers have lived with for decades: how much quality can we give up before compression artifacts matter?
For this phase I benchmarked Qwen3-8B across GGUF quantization levels from roughly 2-bit to 8-bit on the RTX 3090 using llama.cpp’s CUDA backend. Each run used Flash Attention, 1024 prompt tokens, 128 generated tokens, and context depths from 4K to 32K.
Quick Detour: What Perplexity Measures
I use perplexity as a quality metric. Here’s the short version of what perplexity is:
Perplexity measures how surprised a language model is by a sequence of text. For each token, the model assigns probabilities to what it thinks could come next. If the actual next token had high probability, the model was not very surprised. If the actual next token had low probability, the model was more surprised.
Lower perplexity is better.
A useful intuition:
perplexity ≈ the model's average number of plausible next-token choices
So a perplexity of 8 means the model is, very roughly, as uncertain as choosing among 8 likely next tokens on average. That is not literally how sampling works, but it is a good mental model.
In graphics terms, it’s similar to PSNR or compression error metrics: not perfect, but repeatable.
For this project, perplexity is useful because it gives a repeatable way to compare quantization damage. If Q4_K_M is much faster than Q8_0 but has nearly the same perplexity, that suggests the compression preserved most of the model’s predictive ability. If perplexity jumps sharply, that is the quality cliff.
Perplexity is not a perfect human-quality metric. It will not tell you whether an answer is useful, truthful, or well-written. But for measuring whether weight compression damaged the model, it’s a solid first-pass signal.
Throughput at 4K Context
To measure quality, I ran llama.cpp’s perplexity tool on WikiText-2 with a 2048-token context over 100 chunks.
The headline result is simple, but with an important nuance: smaller or more compressed models usually decode faster because each token requires less total work — and in single-stream GPU decode, the limiting factor is often the bytes moved through memory rather than peak arithmetic throughput.
Q4_K_M produced 110.5 tok/s, while Q8_0 produced 78.6 tok/s. That is a 41% throughput increase, while perplexity only worsened from 8.457 to 8.736 — about a 3.3% quality hit by this metric.
That’s the kind of tradeoff production systems love: a large speed gain for a small quality loss.
IQ3_XXS is an interesting case. At only 3.13 GiB, it was the fastest model in the sweep at 121.6 tok/s. It beat Q4_K_M by quite a bit, but the caveat is that it also had worse perplexity. That makes it an interesting aggressive option for latency-sensitive or memory-constrained deployments, but not one I would use blindly.
Q3_K_M was interesting for the opposite reason. It was slower than Q4_K_M even though it’s smaller. File size is not the whole story; the dequantization kernel and memory layout matter.
Quality: Where the Cliff Starts
Throughput alone is not enough. A model can be fast because it’s broken.
Let’s look at the comparison of a few of the models to the baseline:
The useful threshold: quantization is almost free down to around Q4. Below that, the curve starts bending.
That mirrors texture compression perfectly. You can often move from uncompressed RGBA to BC7 or ASTC and get most of the memory win with little visible difference. Push far enough, though, and the artifacts stop being theoretical.
Deployment Takeaway
For this setup, I would start with Q4_K_M or Q5_K_M.
Q4_K_M is the best speed/quality default.
Q5_K_M is the conservative choice.
IQ3_XXS is the aggressive latency/memory option.
The broader lesson is that quantization is not just a model-compression trick. For autoregressive decode, it is a memory-bandwidth optimization.
Flash Attention — Tiled Rendering for Attention
Flash Attention is one of the cleanest examples of an AI optimization that maps directly to graphics intuition.
Standard attention can create huge intermediate memory traffic. Flash Attention changes the data movement pattern: it tiles the attention computation so more work happens through SRAM/registers and less intermediate state is materialized in HBM.
Graphics analogy: instead of writing a giant intermediate render target and reading it back later, you tile the pass and keep more of the working set on-chip.
For this sweep I used Qwen3-8B Q4_K_M, 1024 prompt tokens, 128 generated tokens, and contexts from 4K to 32K.
Decode Throughput
Prefill Throughput
The pattern is exactly what you would expect: Flash Attention matters more as context grows.
At 4K context, decode improved by 15%. At 32K, it doubled. Prefill benefited even more, reaching a 3.5x speedup at 32K.
Flash Attention does not eliminate the cost of long context, but it dramatically flattens the curve.
KV Cache — Your Runtime Texture Atlas
Weight quantization compresses the model. KV-cache quantization compresses the per-request working set.
During decode, the model attends over previous tokens. Those previous keys and values live in the KV cache, and the cache grows with context length. The model weights are fixed, but the runtime working set grows as the prompt gets longer.
Graphics analogy: model weights are static textures/assets. The KV cache is the runtime render target, history buffer, or texture atlas that grows with scene complexity.
Peak VRAM Usage
At 40K context, q8_0 saved 2.61 GiB versus f16, and q4_0 saved 4.05 GiB.
That is enough to matter for long context, larger models, or serving multiple concurrent sequences.
Decode Throughput
The memory savings are not free. At 40K context, q4_0 KV reduced VRAM by 37.7%, but decode fell from 64.9 tok/s to 47.6 tok/s.
That makes KV quantization a capacity optimization, not a pure speed optimization. Use it when fitting longer contexts or more concurrent sessions matters more than maximum single-stream decode speed.
Speculative Decoding — An Optimization To Use With Care
Speculative decoding has an elegant idea: use a small draft model to predict several tokens ahead, then ask the larger target model to verify those tokens in a batch. If the target accepts enough of them, you reduce the number of sequential target-model decode steps.
Graphics analogy: this is like an occlusion or LOD pre-pass. The pre-pass is extra work, but it can still win if it avoids enough expensive downstream work. If the pre-pass is too expensive or fails to cull enough, the optimization becomes a pessimization.
For the first test, I used Qwen3-8B Q4_K_M as the target and Qwen3-0.6B Q8_0 as the draft model. Both ran on the RTX 3090 for the main runs. I also tried one split-GPU run with the draft model on the laptop RTX 5080.
The result: speculative decoding was slower.
At temperature 0, baseline decode ran at 117.7 tok/s. The best speculative run reached only 54.3 tok/s, or 0.46x baseline. Draft length 8 fell to 40.0 tok/s.
Splitting the draft model onto the laptop GPU was worse: 20.6 tok/s. Multi-GPU is not magic; synchronization and scheduling overhead can dominate a latency-sensitive per-token workload.
The VRAM tradeoff was also negative. Same-GPU speculation increased RTX 3090 memory use from 5604 MiB to 6978 MiB, about +1.34 GiB.
Chasing the Failure
The useful part was figuring out why it failed.
llama.cpp’s verbose logs expose draft acceptance rate. On the regular technical-writing prompt, Qwen3-0.6B Q4 only had about 40% acceptance with draft length 4. Draft length 8 dropped to 22% acceptance.
That explains the slowdown. The system was paying to run a second transformer but rejecting too many of its guesses.
A cheaper Q4 draft was better than Q8, but still not enough to beat the already-fast 8B Q4 target.
Where Speculation Did Work
Speculation did work in narrower conditions.
On a highly repetitive structured-output prompt, ngram-cache speculation reached 157.6 tok/s versus 116.8 tok/s baseline — a 1.35x speedup. In that mode, the “draft” is not a second transformer. It is cheap pattern reuse from repeated token sequences.
Draft-model speculation also won when the target model was slower. With Qwen3-14B Q4_K_M, draft-model speculation reached 39.9 tok/s versus 33.4 tok/s baseline — a 1.19x speedup.
So, using speculative decoding as an optimization is real, but conditional. It has a break-even point.
It wins when:
cost(draft + verification + scheduling) < target work avoided by accepted draft tokens
For fast 8B Q4 prose generation, it lost. For repetitive output, ngram speculation won. For a slower 14B target, draft-model speculation finally crossed break-even.
Results — The Optimization Map
The final picture is not one magic switch. Each optimization attacks a different bottleneck.
There are a few lessons to takeaway from this exercise:
Quantization is a weight-bandwidth optimization.
Flash Attention is an attention-memory-traffic optimization.
KV-cache quantization is a capacity optimization.
Speculative decoding is a sequential-decode optimization with a break-even point.
Every optimization has an operating envelope.
Summary
1. Graphics intuition transfers extremely well
Most of the important questions are familiar:
Am I bandwidth-bound or compute-bound?
Am I moving more bytes than necessary?
Is this intermediate representation worth materializing?
Did my compression format help the bottleneck or just add decode overhead?
Is my pre-pass cheaper than the work it avoids?
The terminology changes, but the instincts transfer.
2. Prefill and decode must be analyzed separately
Prompt processing and token generation stress the GPU differently. Prefill is more batch-like. Decode is more sequential and memory-bandwidth-sensitive.
A single tokens/sec number can hide the bottleneck.
3. Smaller is usually faster, but kernels matter
Quantization generally improves decode by reducing bytes per token. But not every smaller quant is faster. Q3_K_M losing to Q4_K_M is a good reminder that layout, unpacking, and kernel quality matter.
4. Long context is a working-set problem
The model does not get bigger at 40K context, but the KV cache does. Long-context optimization is as much about managing runtime memory as it is about model weights.
5. Failed optimizations are valuable data
Speculative decoding failing on the 8B Q4 target was not a bad result. It exposed the break-even condition. The follow-up tests showed when the same technique can win.
Conclusion
LLM inference optimization is full of problems graphics engineers already know how to solve.
You still care about memory bandwidth, locality, intermediate buffers, compression artifacts, batching, occupancy, and latency budgets. The assets are different and the kernels are different, but the hardware is the same.
There is rarely a universal optimization. Quantization, Flash Attention, KV-cache compression, and speculative decoding all help in specific conditions and hurt in others.
The job is to understand the bottleneck well enough to choose the right tool.
And that is exactly what graphics performance engineers have been doing for years.
Cameron Egbert — Former graphics engineer in the game industry and on Hololens, former AR/VR research engineer at Meta Reality Labs. Currently exploring AI inference optimization.















