GPU Mind Map: Attention (Q, K, V), KV Cache, PCIe, NVLink, InfiniBand, RDMA and NCCL Explained
Why LLMs need GPUs and fast links: CPU against GPU cores, attention and the KV cache, why PCIe is too slow, and how NVLink, InfiniBand and RDMA move tensors between GPUs and servers.
LLMs & VRAMGPU, Attention & Interconnects
SFT, RLHF & RLVR
LLM Serving & InferenceLLMOps
AI Gateways
Snowflake
Databricks
CPU vs GPU
Few strong, many small
- What it is
- A CPU has a few powerful cores built to finish one hard, branching task as fast as possible. A GPU has thousands of small, simple cores built to run the same operation on a huge amount of data at once. LLMs are mostly giant matrix multiplications, which is exactly that second kind of work.
- When to use it
- The first answer to "why do we need GPUs for LLMs?".
What a core is
One unit that executes
- What it is
- A core is the unit that fetches an instruction, does the arithmetic and writes the result. A CPU core is large and clever (deep caches, branch prediction, out-of-order execution). A GPU "core" is much simpler, and it only works because thousands of them run in lock-step.
- When to use it
- Reading a spec sheet: core counts of a CPU and a GPU are not comparable numbers.
CPU: low latency
One hard job, fast
- What it is
- Designed to minimise the time of a single task: operating system, databases, web servers, control logic with many if/else branches. A handful to a few hundred cores, each very fast on serial work.
- When to use it
- Tokenisation, request handling, scheduling and anything that branches a lot.
GPU: high throughput
Many small jobs at once
- What it is
- Designed to maximise the work done per second: thousands of simple cores apply the same instruction to different data (SIMT). Each operation is slower than on a CPU core, but ten thousand of them in parallel finish a matrix far sooner.
- When to use it
- Matrix multiplication, convolutions, attention: anything that is the same maths over many numbers.
SMs and warps
How GPU cores are grouped
- What it is
- NVIDIA GPU cores are grouped into streaming multiprocessors (SMs). Threads run in warps of 32 that execute the same instruction together. The GPU hides memory delays by switching to another warp, which is why it needs far more work in flight than it has cores.
- When to use it
- Understanding why batching requests raises GPU utilisation.
Tensor Cores
Matrix maths in hardware
- What it is
- Special units inside each SM that multiply small matrix tiles in one step, in low precisions such as FP16, BF16, FP8 and FP4. They are why a modern GPU is far faster at LLM maths than its plain CUDA core count suggests.
- When to use it
- Why quantised models run faster on newer GPUs that support the format natively.
Why LLMs fit GPUs
Matrices, not branches
- What it is
- A transformer layer is a chain of matrix multiplications over thousands of independent numbers, with almost no branching. Each output element can be computed in parallel, so the work spreads over every core.
- When to use it
- Explaining GPU choice to a non-technical stakeholder in one sentence.
Compute- vs memory-bound
Prefill vs decode
- What it is
- Prefill (reading the prompt) multiplies big matrices and is limited by compute. Decode (one token at a time) must stream every weight and the whole KV cache from memory for each token, so it is limited by memory bandwidth, not by core count.
- When to use it
- Why a GPU with more memory bandwidth can beat one with more raw FLOPS for chat serving.
Attention: Q, K, V
A search inside the model
- What it is
- Think of Query, Key and Value as a search system inside the model, like looking for information in a library. Each token asks a question (Q), every earlier token advertises what it holds (K) and carries its content (V). The model gives more weight to the tokens whose K matches the Q.
- When to use it
- The core idea behind every transformer LLM; the base for the KV cache and the memory maths.
Q: Query
What am I looking for?
- What it is
- The question a token asks of the others. In the sentence "The cat sat on the mat because it was tired", the Query of "it" asks: what does "it" refer to?
- When to use it
- Computed fresh for the current token only; it is never cached.
K: Key
What does each word hold?
- What it is
- The matching label of each earlier token. The Query is compared with the Keys of cat, sat, mat and tired to find which ones are relevant. K answers "how do I identify relevant information?".
- When to use it
- Stored in the KV cache so past tokens never recompute it.
V: Value
The actual information
- What it is
- The content a token hands over once it is judged relevant: the information inside the book. After matching, the model retrieves the Values of the matching tokens, mostly "cat" in the example.
- When to use it
- Stored in the KV cache next to K.
Q K V in one table
Question, label, content
- What it is
- Q is the question, K the matching label, V the actual information. Q searches, K finds, V retrieves. Library version: Q is what I want, K is what each book says it contains, V is what is written inside.
- When to use it
- A memory aid for interviews: Question, Matching label, Actual information.
Why three vectors
Need, identify, retrieve
- What it is
- The model must separate three jobs: what information it needs (Q), how to identify relevant information (K), and what information to retrieve (V). With one shared vector, the signal used to match could not differ from the content passed on.
- When to use it
- The standard follow-up question after "explain Q, K, V".
Scores and softmax
Turn matches into weights
- What it is
- Each Query is multiplied with every Key to get a score; softmax turns the scores into weights that sum to 1; the output is the weighted sum of the Values. Relevant tokens such as "cat" get most of the weight.
- When to use it
- The formula behind every attention layer: softmax(QKᵀ / √d) · V.
- In code
attention = softmax(Q @ K.T / sqrt(d)) @ V
Multi-head attention
Several searches in parallel
- What it is
- The model runs many attention searches side by side, each with its own Q, K and V projections, so one head can track grammar while another tracks who "it" refers to. Their outputs are joined. Variants share K and V across heads (MQA, GQA) to shrink the KV cache.
- When to use it
- Reading a model card: "8 KV heads" means GQA and a much smaller KV cache.
FlashAttention
Fewer trips to HBM
- What it is
- Computes attention in tiles that stay in fast on-chip memory instead of writing the full score matrix to HBM. Same result, far less memory traffic, and long contexts become practical.
- When to use it
- Default in modern serving stacks; the reason long prompts do not explode memory.
KV cache
Remember K and V
- What it is
- The KV cache stores the Keys and Values of every earlier token so they do not need to be recalculated for each new token. Only the new token's Q, K and V are computed; its Q is matched against the cached Ks and the cached Vs are read back.
- When to use it
- The reason generation speed does not collapse as the answer grows, and the reason memory does.
Without it
Recompute everything
- What it is
- Without a cache, producing token 500 would redo the K and V maths for tokens 1 to 499. Generation cost would grow with the square of the length instead of staying close to flat per token.
- When to use it
- Explaining why every inference engine has a KV cache.
Memory it takes
Grows with every token
- What it is
- The cache grows with context length and with the number of simultaneous requests, per layer and per KV head. It lives in GPU memory next to the weights and is what runs out first at long context or high concurrency. The exact formula is in the LLMs & VRAM map.
- When to use it
- Capacity planning: a model that "fits" can still fail with ten concurrent users.
- Key figures
- KV cache size = 2 × layers × KV heads × head dimension × precision bytes × sequence length × batch.Source: NVIDIA blog, Mastering LLM Techniques: Inference Optimization
PagedAttention
Cache in small blocks
- What it is
- vLLM stores the KV cache in fixed-size blocks that do not need to be contiguous, like virtual memory pages. This removes fragmentation and wasted reserved space, so more requests fit in the same GPU.
- When to use it
- Higher throughput on a given GPU without changing the model.
Prefix caching
Reuse a shared prompt
- What it is
- When many requests start with the same system prompt or document, the cached K and V of that prefix are reused instead of recomputed. Providers sell the same idea as prompt caching.
- When to use it
- Chatbots with a long fixed system prompt, RAG over one document, agents with big tool lists.
Quantise and offload
Shrink or spill the cache
- What it is
- The cache can be stored in FP8 instead of FP16 to halve it, or moved to CPU RAM when the GPU is full. Offloading crosses PCIe on every use, so it trades speed for capacity.
- When to use it
- Squeezing more concurrent users or a longer context into the same card.
- In code
vllm serve <model> --kv-cache-dtype fp8 --max-model-len 32768
What a token is
A piece of text
- What it is
- A token is the small piece of text an LLM processes: a whole word, part of a word, punctuation, a number or a symbol. "The cat is sitting on the table." is roughly The / cat / is / sitting / on / the / table / . (illustrative: real boundaries depend on the tokenizer). The model works on numerical representations of tokens, and every token adds to attention work, context-window use, generation time and memory.
- When to use it
- Estimating cost and memory: both scale with the number of tokens, not words.
How important is this token
Q scored against every K
- What it is
- To decide how important an earlier token is for the one being generated, the model scores the new token's Query against that token's Key (QKᵀ divided by √d_k), then softmax turns all scores into weights that sum to 1. A high weight means "pay attention to this token", and its Value is mixed into the output in that proportion.
- When to use it
- Answering "how does the model know which words matter" in plain terms.
- In code
Attention(Q, K, V) = softmax(Q @ K.T / sqrt(d_k)) @ V
The cache formulas
K_t, V_t and the cache
- What it is
- For each new token t the model computes K_t = W_K · x_t and V_t = W_V · x_t from the token's hidden state x_t, and appends them: K_cache = [K_1 … K_t], V_cache = [V_1 … V_t]. The next step is Attention_t = softmax(Q_t · K_cacheᵀ / √d_k) · V_cache, so earlier tokens are never recomputed: only Q_t, K_t and V_t are new.
- When to use it
- Showing in an interview exactly what is cached (K and V) and what is not (Q).
- In code
K_t = W_K @ x_t V_t = W_V @ x_t K_cache = [K_1, K_2, ..., K_t] V_cache = [V_1, V_2, ..., V_t] Attention_t = softmax(Q_t @ K_cache.T / sqrt(d_k)) @ V_cache
Memory formula
2 × L × B × S × H × D
- What it is
- For standard multi-head attention: KV memory = 2 × L × B × S × H_kv × D_h × bytes. The 2 is Key plus Value, L the layers, B the batch size, S the sequence length in tokens, H_kv the number of KV heads, D_h the dimension per head, and bytes the size per element (FP16 = 2).
- When to use it
- Sizing GPU memory for a context length and a number of users.
- In code
kv_bytes = 2 * L * B * S * H_kv * D_h * bytes
Worked example
8K tokens = 1.05 GB
- What it is
- A model with 32 layers, 8 KV heads, head dimension 128 and FP16, one sequence of 8,000 tokens: 2 × 32 × 1 × 8000 × 8 × 128 × 2 = about 1.05 GB. At 32,000 tokens the cache is about 4.19 GB, four times larger. This is the cache of one sequence, without weights or other GPU allocations.
- When to use it
- Why long context windows need so much VRAM: the cache grows linearly with tokens and with concurrent users.
- In code
python -c "print(2*32*1*8000*8*128*2/1e9)" # 1.048576 GB python -c "print(2*32*1*32000*8*128*2/1e9)" # 4.194304 GB
Inside one GPU
Compute and HBM
- What it is
- Within a single GPU the cores talk to HBM (high-bandwidth memory) stacked right next to the chip. This is the fastest link in the whole system and where weights and the KV cache live.
- When to use it
- Level one of the ladder: GPU compute to HBM.
HBM
Memory on the package
- What it is
- Stacks of DRAM dies connected to the GPU through a very wide interface, giving terabytes per second instead of the tens to low hundreds of GB/s of ordinary system RAM. It is expensive and limited in size, which is why GPU memory is the scarce resource.
- When to use it
- Explaining why a 80 GB card costs far more than 80 GB of server RAM.
- Key figures
- H100 SXM: 80 GB of memory at 3.35 TB/s.Source: NVIDIA H100 datasheet
Registers, SRAM, HBM
Small and fast to big
- What it is
- Registers and on-chip shared memory (SRAM) are tiny and extremely fast; HBM is large and slower; system RAM is larger and slower still. Fast kernels such as FlashAttention keep data in the small tiers as long as possible.
- When to use it
- Why the same maths can run several times faster with a better memory access pattern.
Bandwidth sets decode speed
Bytes per token
- What it is
- Each generated token reads the active weights and the KV cache from HBM once, so the ceiling on tokens per second is roughly memory bandwidth divided by bytes read per token. A single stream cannot go faster than that, whatever the core count.
- When to use it
- Back-of-the-envelope speed estimates before renting a GPU.
When it does not fit
Shard across GPUs
- What it is
- When weights plus the KV cache exceed one GPU's memory, the model is split over several GPUs. From that moment the speed of the links between GPUs decides how well it runs, which is the rest of this map.
- When to use it
- The bridge from single-GPU to multi-GPU serving.
Why PCIe is not enough
The general-purpose bus
- What it is
- PCIe is the standard bus that connects a GPU to the CPU, RAM, disks and network cards. It was designed for general-purpose devices, so its bandwidth is a small fraction of what GPU memory or a GPU-to-GPU link provides.
- When to use it
- The answer to "why not just use PCIe between GPUs?".
The numbers
x16 slot against HBM
- What it is
- A PCIe 5.0 x16 slot gives about 64 GB/s in each direction (128 GB/s both ways), while HBM on a data-centre GPU delivers terabytes per second. Moving data over PCIe is roughly 25 to 50 times slower than reading it from HBM.
- When to use it
- Putting the gap in one sentence in an interview.
- Key figures
- PCIe 5.0 x16: 64 GB/s per direction, 128 GB/s bidirectional.Source: PCI-SIG PCIe 5.0 specification figures
- H100 SXM memory bandwidth: 3.35 TB/s.Source: NVIDIA H100 datasheet
Detours through the CPU
GPU to RAM to GPU
- What it is
- Without a direct GPU link, data between two GPUs on PCIe goes through a root complex and often through host memory, with extra copies and CPU involvement. Lanes are shared with disks and network cards, so concurrent transfers compete.
- When to use it
- Spotting why 4 PCIe-only GPUs scale worse than 4 NVLink GPUs.
Offloading to RAM
Capacity at a speed price
- What it is
- Keeping weights or the KV cache in CPU RAM lets a model run on a small GPU, but every token must pull the offloaded part across PCIe. Generation drops from HBM speed to PCIe speed for that part.
- When to use it
- Hobby and edge setups where fitting matters more than tokens per second.
- In code
llama-server -hf <repo>:Q4_K_M -c 16384 -ngl 20
CPU and RAM still matter
Feeding and control
- What it is
- The CPU still tokenises, schedules batches, launches GPU kernels and loads weights from disk over PCIe at start-up. PCIe is right for that control and loading traffic; it is wrong for the constant tensor exchange between GPUs.
- When to use it
- Not over-correcting: PCIe is fine for what it was built for.
NVLink and NVSwitch
GPU to GPU in a server
- What it is
- NVLink is NVIDIA's direct high-speed link between GPUs, and NVSwitch is the switch chip that connects many GPUs in a server all-to-all at full link speed. Between GPUs in one server it replaces PCIe with a far faster path.
- When to use it
- Level two of the ladder: between GPUs in one server.
How much faster
Hundreds of GB/s per GPU
- What it is
- Fourth-generation NVLink on the H100 gives 900 GB/s per GPU; fifth generation on Blackwell gives 1.8 TB/s, which NVIDIA states as over 14 times the bandwidth of PCIe Gen5. Totals are bidirectional peaks.
- When to use it
- Sizing a multi-GPU box: SXM boards have NVLink, many PCIe cards do not.
- Key figures
- NVLink 4 (H100 SXM): 900 GB/s per GPU.Source: NVIDIA H100 datasheet
- NVLink 5 (Blackwell): 1.8 TB/s per GPU, over 14 times PCIe Gen5.Source: NVIDIA NVLink page
NVSwitch
Every GPU to every GPU
- What it is
- Without a switch, GPUs link pairwise and bandwidth to a given peer is limited to the links between them. NVSwitch gives every GPU full-speed access to every other GPU at the same time, so collective operations do not bottleneck on a few cables.
- When to use it
- 8-GPU servers (HGX and DGX) running one model across all GPUs.
Why tensor parallelism needs it
Sync in every layer
- What it is
- Tensor parallelism splits each layer's matrices over GPUs, so after every layer the partial results must be summed across all of them (an all-reduce). That happens for every layer of every token, which is only fast enough on NVLink.
- When to use it
- Choosing --tensor-parallel-size: stay inside one NVLink domain.
- In code
vllm serve <model> --tensor-parallel-size 8
No NVLink: what then
Pipeline over PCIe
- What it is
- On PCIe-only GPUs (consumer cards, many cloud instances), prefer pipeline parallelism or one model per GPU: they pass much less data between GPUs than tensor parallelism and tolerate the slower link.
- When to use it
- Cheap multi-GPU boxes: expect the scaling to be worse than the GPU count suggests.
Between servers
InfiniBand, RoCE, RDMA
- What it is
- When a model or a training job spans several servers, GPUs must exchange tensors across the network. Ordinary TCP/IP over Ethernet is too slow and CPU-hungry for that, so AI clusters use InfiniBand or RoCE with RDMA.
- When to use it
- Level three of the ladder: between servers.
InfiniBand
Lossless HPC fabric
- What it is
- A network built for high-performance computing: very low latency, high bandwidth, lossless by design and with RDMA built in. It is the standard fabric of large GPU training clusters.
- When to use it
- Multi-node training and large multi-node inference where every microsecond counts.
RoCE
RDMA over Ethernet
- What it is
- RDMA over Converged Ethernet carries RDMA on Ethernet hardware, so a data centre can keep its Ethernet switches. It needs careful flow control and congestion settings to behave like a lossless network.
- When to use it
- Clouds and enterprises that standardise on Ethernet but need RDMA speeds.
RDMA
Memory to memory, no CPU
- What it is
- Remote Direct Memory Access lets a network adapter read or write registered memory on another machine directly, with minimal CPU involvement. It cuts latency and CPU overhead, which matters for distributed AI where GPUs constantly exchange tensors.
- When to use it
- The technology behind both InfiniBand and RoCE performance.
TCP: the normal path
Through the OS stack
- What it is
- TCP transfers data through the traditional operating system networking stack, which adds CPU overhead, kernel processing and often extra memory copies. Fine for web traffic and APIs, costly for a flood of tensors.
- When to use it
- The baseline to compare RDMA against.
GPUDirect RDMA
NIC reads GPU memory
- What it is
- Lets the network card read and write GPU memory directly, skipping the copy through host RAM and the CPU. Tensors travel GPU to NIC to network to NIC to GPU.
- When to use it
- Multi-node jobs where host-memory copies would waste bandwidth.
Ethernet + TCP/IP
General networking
- What it is
- The standard communication layer for everything else: user requests, API calls, storage, monitoring. Still the right choice for most traffic even in an AI cluster.
- When to use it
- Front-end and control traffic, while the RDMA fabric carries tensors.
RDMA does not replace TCP
Use it where it pays
- What it is
- Most applications still use TCP. RDMA is especially valuable for performance-critical communication such as distributed GPU workloads, where the CPU and latency savings add up.
- When to use it
- The one-line caveat that makes an interview answer sound experienced.
NCCL
Library for GPU collectives
- What it is
- NVIDIA's Collective Communications Library. Frameworks such as PyTorch and engines such as vLLM call it to exchange tensors; it detects the topology and picks the best transport (NVLink, PCIe, InfiniBand or RoCE with RDMA, or plain sockets) by itself.
- When to use it
- The next concept after the hardware: how software uses these links.
All-reduce
Sum and share to all
- What it is
- Every GPU contributes a tensor, the tensors are summed, and every GPU receives the total. It is the main collective of tensor parallelism and of gradient averaging in data-parallel training.
- When to use it
- The operation to name when asked what travels over NVLink.
All-gather, reduce-scatter
Collect or split pieces
- What it is
- All-gather lets every GPU collect the pieces held by all the others; reduce-scatter sums tensors and leaves each GPU with one slice of the result. Together they make an all-reduce and are used by sharded training.
- When to use it
- Sharded optimisers and fully sharded data parallel (FSDP) training.
All-to-all
Everyone sends to everyone
- What it is
- Each GPU sends a different slice to every other GPU. Mixture-of-experts models use it to route tokens to the GPU that holds the chosen expert and to bring results back.
- When to use it
- Serving large MoE models across several GPUs or nodes.
Transport choice
NVLink, PCIe, IB, sockets
- What it is
- NCCL prefers NVLink inside a server, then PCIe, and between servers uses InfiniBand or RoCE with RDMA (and GPUDirect where available), falling back to TCP sockets. A slow fallback is a common reason for a mysteriously slow cluster.
- When to use it
- Debugging with NCCL_DEBUG=INFO to see which transport was chosen.
- In code
NCCL_DEBUG=INFO python train.py
Tensor parallelism
Split each layer
- What it is
- Each layer's matrices are split across GPUs that work on the same token together. Lowest latency per request but the heaviest communication: an all-reduce per layer. Keep it inside one NVLink domain.
- When to use it
- One big model on 2 to 8 GPUs of the same server.
Pipeline parallelism
Layers in stages
- What it is
- Consecutive groups of layers sit on different GPUs or servers and pass activations forward like an assembly line. It sends little data between stages, so it tolerates slower links such as InfiniBand or PCIe, at the cost of idle gaps (bubbles).
- When to use it
- Models too big for one server, split across nodes.
Data parallelism
Copies of the model
- What it is
- Several replicas of the model each handle different requests or batches. For serving it needs almost no GPU-to-GPU traffic; for training the gradients are all-reduced after each step.
- When to use it
- Scaling throughput once one replica already fits.
Expert parallelism
Experts on different GPUs
- What it is
- The experts of a mixture-of-experts model are spread across GPUs and tokens travel to them with all-to-all. Heavy on the network, so large deployments pair it with fast NVLink or InfiniBand.
- When to use it
- Frontier-size open MoE models that do not fit on one node.
Cluster architectures
Six ways to serve
- What it is
- There are several ways to lay out an LLM inference cluster, and the right one depends on four things: prompt length (input tokens), generation length (output tokens), number of concurrent users, and GPU memory, memory bandwidth and network bandwidth. Splitting prefill from decode is one option, not the best for every workload.
- When to use it
- Start from the comparison table under the map, then open the architecture that fits.
1. Combined
Prefill + decode together
- What it is
- One GPU node handles prefill and decode: the prompt arrives, the GPU processes it, generates the tokens and keeps the KV cache locally. No KV transfer, simple scheduling, easy to deploy and debug; but prefill and decode compete for the same GPU and cannot be scaled separately.
- When to use it
- Small and medium deployments, low concurrency, short prompts, or when simplicity matters most.
2. Disaggregated
Separate prefill / decode
- What it is
- Separate GPU pools: prefill nodes process prompts, the KV cache is transferred, decode nodes generate the answer. Each pool scales on its own and can use a different GPU configuration, with better control of time to first token and token latency. The price is KV transfer overhead, harder scheduling and a need for fast networking.
- When to use it
- High concurrency, long prompts, sustained traffic and predictable performance targets.
3. Data parallel
Identical replicas
- What it is
- Several identical replicas, each running prefill and decode on its own; a load balancer spreads the requests. Easy horizontal scaling, request isolation, good fault isolation and no KV transfer between replicas. Every replica needs the full weights, and memory is wasted if traffic is uneven.
- When to use it
- Many independent users and enough GPUs to replicate the model.
4. Tensor parallel
One model over GPUs
- What it is
- One model is split across GPUs: each computes part of every matrix operation and the results are synchronised with collective communication. Allows models larger than one GPU and can cut latency, but needs GPU-to-GPU traffic and usually NVLink or a similarly fast interconnect.
- When to use it
- A model that does not fit one GPU, inside one node.
5. Pipeline parallel
Layers in stages
- What it is
- Each GPU owns a group of layers (for example 1-8, 9-16, 17-24, 25-32) and activations flow from stage to stage. It spreads weights across nodes and suits very large models, but leaves pipeline bubbles where GPUs idle and needs careful scheduling.
- When to use it
- A large model across several nodes when tensor parallelism over the network is too chatty.
6. Hybrid
Combine several
- What it is
- Combines the others, for example a prefill pool and a decode pool that each use data plus tensor parallelism, linked by RDMA, with a KV-cache-aware scheduler placing sessions. Independent scaling, large models and good utilisation at scale, at the cost of complex infrastructure, scheduling and networking.
- When to use it
- Large inference providers with high concurrency and mixed workloads.
Prefill vs decode
Two different workloads
- What it is
- Prefill reads the whole prompt at once: compute-bound, sets time to first token (TTFT), produces the KV cache. Decode generates one token at a time: memory-bandwidth-bound, sets the time between tokens, and keeps growing the cache. Mixing them on one GPU lets a long prefill stall everybody's decode, which is the reason to separate them.
- When to use it
- The argument for disaggregation: tune each pool to its own bottleneck.
Kubernetes and Helm setup
Prefill and decode pools
- What it is
- A sensible layout for a Kubernetes cluster: one Deployment for the prefill pool, one for the decode pool, a router in front, GPU nodes labelled and tainted for inference, and an RDMA-capable network between the two pools. Helm packages the pools as two values blocks of one release so they scale and roll out independently.
- When to use it
- Open the diagram under the map for the full picture.
Topology
Router, two pools, fabric
- What it is
- Client, ingress and a router/gateway sit on CPU nodes. Prefill pods (few, large, compute-heavy) and decode pods (many, memory-heavy) sit on GPU nodes. The router sends each prompt to a prefill pod, the KV cache moves to a decode pod over the RDMA fabric, and the decode pod streams the tokens back.
- When to use it
- Drawing the architecture on a whiteboard in five boxes.
GPU scheduling
Device plugin and taints
- What it is
- The NVIDIA device plugin (or the GPU Operator that installs it) exposes GPUs as the schedulable resource nvidia.com/gpu. Label GPU nodes by role, taint them so only inference pods land there, and request whole GPUs in the pod limits. A tensor-parallel pod needs all its GPUs on the same node, on NVLink.
- When to use it
- Keeping decode pods off prefill nodes and CPU-only workloads off GPU nodes.
- In code
kubectl label node <gpu-node> inference/role=prefill kubectl taint node <gpu-node> nvidia.com/gpu=present:NoSchedule resources: limits: nvidia.com/gpu: 4
Helm values
One release, two pools
- What it is
- One chart with two worker blocks in values.yaml: prefill and decode each get their own replicas, GPU count, parallelism flags, nodeSelector, tolerations and resource limits, so each pool can be changed and rolled out independently. This is an illustrative layout, not a published chart; real projects (llm-d, NVIDIA Dynamo) ship their own charts and operators.
- When to use it
- A starting point for a values file when you build your own chart.
- In code
# values.yaml (illustrative) model: <model-id> prefill: replicas: 2 gpusPerPod: 4 nodeSelector: { inference/role: prefill } args: ["--tensor-parallel-size", "4"] decode: replicas: 6 gpusPerPod: 2 nodeSelector: { inference/role: decode } args: ["--tensor-parallel-size", "2"] router: replicas: 2 # install helm upgrade --install llm ./chart -n inference -f values.yaml
KV transfer
NIXL between the pools
- What it is
- vLLM moves the KV cache between prefill and decode workers through a connector; the NIXL connector is configured with --kv-transfer-config. In the llm-d guide the decode instance pulls the KV blocks over RDMA with NIXL, which also works over TCP, but InfiniBand, RoCE or EFA is strongly recommended for production. In current vLLM versions the router decides which instance is the prefiller and which the decoder.
- When to use it
- Choosing the fabric: TCP for a lab, RDMA for anything with real traffic.
- In code
vllm serve <model> --kv-transfer-config '{"kv_connector":"NixlConnector","kv_role":"kv_both"}' VLLM_NIXL_SIDE_CHANNEL_PORT=5600- Key figures
- llm-d P/D: two vLLM Deployments in one InferencePool, labelled by role; the decode instance pulls KV over RDMA with NIXL.Source: Documentation of llm-d, prefill/decode disaggregation path
RDMA in pods
Expose the NIC to pods
- What it is
- Pods only see the RDMA network if the cluster exposes it: a secondary network interface (for example through Multus), an RDMA or SR-IOV device plugin that advertises the NIC as a resource, and pod settings that allow locked memory. Without this NCCL and NIXL fall back to TCP sockets and the cluster looks mysteriously slow.
- When to use it
- Checking with NCCL_DEBUG=INFO that the transport is IB or RoCE, not sockets.
Router
KV-aware request routing
- What it is
- A plain round-robin Service throws away the cache. A KV-aware router sends a request to the pod that already holds its prefix, balances prefill against decode load and ties the two halves of one request together. llm-d does this through the Gateway API Inference Extension and an InferencePool; NVIDIA Dynamo has its own KV-aware router fed by cache events from the workers.
- When to use it
- Multi-turn chat and shared system prompts, where prefix reuse saves most prefill work.
Autoscaling each pool
Different signals
- What it is
- Scale the pools on different signals, which is the point of splitting them: prefill on request queue length and time to first token; decode on running sequences, KV cache usage and inter-token latency. Use HPA or KEDA on the engine metrics, and scale slowly: a new GPU pod needs minutes to pull the image and load the weights.
- When to use it
- Avoiding both idle decode GPUs and a prefill queue that makes first tokens slow.
llm-d
Kubernetes-native vLLM
- What it is
- An open-source Kubernetes-native distributed inference framework that coordinates a fleet of vLLM instances. Its "well-lit paths" are reference architectures, including prefill/decode disaggregation, intelligent routing and KV-cache-aware scheduling.
- When to use it
- The quickest route to a tested prefill/decode layout on Kubernetes with vLLM.
NVIDIA Dynamo
Operator, router, Grove
- What it is
- NVIDIA's inference framework for disaggregated serving. On Kubernetes it ships an operator with custom resources (DynamoGraphDeployment and others), a KV-aware router, NIXL for the KV transfer, Helm charts and Grove for gang scheduling and topology-aware placement of multi-node deployments.
- When to use it
- Large multi-node deployments on NVIDIA hardware where topology-aware placement matters.
The bandwidth ladder
Four levels, fast to slow
- What it is
- Each step out from the GPU core costs bandwidth and adds latency, so the design rule is to keep chatty traffic as close to the GPU as possible: HBM first, NVLink inside a server, InfiniBand or RoCE between servers, plain Ethernet and TCP for the rest.
- When to use it
- A one-slide summary of the whole map.
Within one GPU
GPU compute to HBM
- What it is
- GPU compute talks to HBM memory: terabytes per second.
- When to use it
- Weights and KV cache live here.
Between GPUs in a server
NVLink / NVSwitch
- What it is
- NVLink and NVSwitch provide high-speed GPU-to-GPU communication inside one machine.
- When to use it
- Tensor parallelism and expert parallelism inside a node.
Between servers
InfiniBand / RoCE + RDMA
- What it is
- InfiniBand or RoCE with RDMA gives fast inter-server communication with little CPU involvement.
- When to use it
- Multi-node inference and training, pipeline parallelism across nodes.
General networking
Ethernet + TCP/IP
- What it is
- Ethernet with TCP/IP carries standard communication: users, APIs, storage and monitoring.
- When to use it
- Everything that is not a tensor exchange.
Interview: TCP vs RDMA
A 30-second answer
- What it is
- TCP goes through the OS networking stack, which adds CPU overhead, kernel processing and extra memory copies. RDMA lets network adapters move data directly between registered memory regions on different machines with minimal CPU involvement, cutting latency and overhead. That matters for multi-node GPU training and inference, where GPUs constantly exchange tensors. RDMA does not replace TCP for everything.
- When to use it
- Inference-engineering interviews; the follow-up topic is NCCL.
Which fabric for which job
Match link to traffic
- What it is
- A 7B model on one GPU needs none of this. A 70B model on 4 to 8 GPUs of one server wants NVLink for tensor parallelism. A model larger than one server wants InfiniBand or RoCE and pipeline or expert parallelism across nodes. Always measure: link speed is a ceiling, not a result.
- When to use it
- Deciding hardware for a client deployment before quoting it.
KV cache growth and how to shrink it
The cache grows linearly with the number of tokens. For a model with 32 layers, 8 KV heads, head dimension 128 and FP16 it is 1.05 GB at 8,000 tokens and 4.19 GB at 32,000 tokens, per sequence. These are the main ways to make it smaller.
| Technique | What it does | Effect |
|---|---|---|
| FP16 | Stores each value in 2 bytes | The baseline |
| INT8 / FP8 | Stores each value in about 1 byte | About half the memory of FP16 |
| INT4 | Stores each value in about 0.5 byte | About a quarter of FP16, with some quality risk |
| GQA | Several query heads share one set of KV heads | Fewer KV heads, so a proportionally smaller cache |
| Sliding window | Keeps only a limited recent context | The cache stops growing past the window |
| PagedAttention | Manages the cache in blocks instead of one large contiguous allocation | Less fragmentation and waste, more concurrent requests |
The bandwidth ladder as a graph
Each step away from the GPU cores costs bandwidth. Peak vendor figures, GB/s, on a linear scale.
Six inference architectures compared
Pick by prompt length, generation length, concurrency, and GPU memory, memory bandwidth and network bandwidth.
| Architecture | Best for | Advantages | Disadvantages | Use when |
|---|---|---|---|---|
| 1. Combined prefill + decode | Simplicity | No KV transfer, simple scheduling, easy to debug | Prefill and decode compete for the GPU; cannot scale each stage alone | Small or medium load, low concurrency, short prompts |
| 2. Disaggregated prefill / decode | Independent scaling | Dedicated resources, control of TTFT and token latency, different GPUs per stage | KV transfer overhead, harder scheduling, needs fast networking | High concurrency, long prompts, sustained traffic, predictable targets |
| 3. Data parallelism | Horizontal scaling | Easy to scale, request and fault isolation, no KV transfer | Full weights in every replica, KV duplicated across sessions, waste when traffic is uneven | Many independent users and enough GPUs to replicate the model |
| 4. Tensor parallelism | Large models | Fits models larger than one GPU, spreads compute, can cut latency | Needs GPU-to-GPU traffic, communication overhead, benefits from NVLink | The model does not fit one GPU, or you want speed inside a node |
| 5. Pipeline parallelism | Spreading layers | Spreads weights and activations, can span nodes, suits very large models | Pipeline bubbles leave GPUs idle, stage-to-stage traffic, harder scheduling | Large models across nodes when tensor parallelism over the network is too heavy |
| 6. Hybrid | Large production clusters | Independent scaling, large models, flexible allocation, good use at scale | Complex infrastructure, sophisticated scheduling, higher network and operating cost | Large providers, high concurrency, mixed workloads |
Prefill and decode: the request flow
Prefill reads the prompt and builds the KV cache; decode generates the tokens one by one. They stress different resources, so they can be given different GPUs and scaled separately.
| Prefill | Decode | |
|---|---|---|
| What it does | Processes the whole prompt at once and builds the KV cache | Generates one token at a time, reading and growing the KV cache |
| Main limit | Compute (matrix multiplications) | Memory bandwidth and KV cache capacity |
| Latency it sets | Time to first token (TTFT) | Time between tokens |
| Scale on | Request queue length, TTFT | Running sequences, KV cache usage, inter-token latency |
| GPU choice | Strong compute, tensor parallelism inside a node | Large and fast memory, many replicas |
Kubernetes and Helm topology
One layout that makes sense for a cluster: CPU nodes for the gateway and router, labelled GPU nodes for each pool, an RDMA fabric between them, and one Helm release with a values block per pool.
| Piece | Role | Notes |
|---|---|---|
| Ingress / gateway | Terminates TLS, authenticates, applies limits | CPU nodes; an AI gateway fits here |
| Router | Picks the prefill and decode pod, KV-cache aware | llm-d (Inference Gateway) or the Dynamo router |
| Prefill Deployment | Builds the KV cache from the prompt | Fewer, larger pods; tensor parallel inside a node |
| Decode Deployment | Generates tokens from the transferred cache | More pods; scale on KV cache usage and latency |
| GPU node pools | Hold the pods; labelled and tainted per role | NVIDIA device plugin or GPU Operator |
| RDMA fabric | Carries the KV cache between pools | InfiniBand or RoCE; TCP works but is slow |
| Autoscaler | HPA or KEDA on engine metrics, per pool | Scale slowly: model loading takes minutes |
Sources, read 2026-11-19: the author's own study notes on Q/K/V, the KV cache, TCP against RDMA and the transport ladder; the NVIDIA H100 datasheet; NVIDIA's NVLink and Blackwell pages; the NCCL user guide; PCI-SIG PCIe 5.0 figures; the FlashAttention and PagedAttention papers; "Attention Is All You Need"; the vLLM NixlConnector guide and the llm-d and NVIDIA Dynamo documentation. Bandwidth numbers are vendor peak figures and real workloads reach less. Products and generations change: check the datasheet of the GPU you deploy.