AI Infrastructure Interview Guide: Core LLM Topics, Formulas, and Trade-Offs
This guide explains the concepts most frequently tested in large language model infrastructure interviews, from attention complexity and KV-cache sizing to long-context architectures, distributed execution, memory optimization, and inference serving. It provides practical formulas, bottleneck-analysis methods, and a framework for answering questions through derivation, estimation, diagnosis, and trade-off analysis.
1. The Interview Map: What AI Infrastructure Roles Really Test
Every long-context conversation and every near-instant first-token response is part of an ongoing efficiency battle around attention. Early mainstream models typically supported context windows of roughly 2,048 tokens. Today, 128K- and 256K-token contexts are common configurations for flagship models.
This progress is not simply the result of adding more parameters. It reflects years of architectural and systems engineering across dozens of core papers, covering the transition from multi-head attention to grouped-query attention and from quadratic costs toward near-linear overhead. Each step is driven by practical production constraints: GPU memory, memory bandwidth, and latency.
AI infrastructure interviews may appear to cover unrelated topics, but most questions test four abilities:
- Can you derive the computational complexity?
- Can you estimate resource requirements?
- Can you identify the bottleneck?
- Can you propose solutions with clear trade-offs?
A useful preparation plan is to organize the material into the following layers.
2. Layer One: The Foundation of Attention
2.1 Why Recurrent Architectures Had to Give Way
Before the Transformer, recurrent neural networks were the dominant approach to sequence modeling. They had two critical weaknesses.
First, computation had to proceed sequentially, one time step at a time. This left much of the GPU’s parallel capacity unused, and training on long documents could take months. Second, long-range dependencies weakened as information passed through many recurrent steps, making it difficult to connect information at the beginning and end of a sequence.
A foundational paper published in 2017 introduced multi-head attention. It split Q, K, and V across multiple heads so that different heads could capture grammatical, referential, logical, and other types of dependencies in parallel.
Attention has a complexity of O(N²), but it enables full parallelism across the sequence dimension. On the same hardware, this can improve training efficiency by more than an order of magnitude compared with recurrent structures. It was the first successful trade of additional compute for reduced elapsed time and became the starting point for subsequent optimizations.
2.2 You Must Be Able to Derive the Complexity
Interviewers often ask candidates to derive attention complexity on a whiteboard. In single-head attention, QKᵀ produces an N × N score matrix. Each element is a dot product over d dimensions, so the time complexity is O(N² · d), while the intermediate memory requirement is O(N²). Multi-head attention divides d across h heads, but the total asymptotic cost remains the same.
Two important conclusions follow:
- When the sequence length doubles, the attention computation increases fourfold, while the linear layers increase only twofold. In long-context workloads, the bottleneck therefore shifts from matrix multiplication toward attention.
- The N × N intermediate matrix is a major memory burden. The first engineering priority is to avoid materializing it through tiling and online softmax, rather than merely optimizing the matrix multiplication itself.
2.3 KV Cache: The Most Common Calculation Question
Autoregressive decoding stores historical keys and values in a KV cache. Its memory consumption can be estimated as follows:
KV_bytes = 2 × L × H_kv × D_head × S × B × bytes# 2: K and V; L: number of layers; H_kv: number of KV heads; D_head: head dimension# S: sequence length; B: concurrent batch size; bytes: bytes per value
def kv_cache_gb(layers, kv_heads, head_dim, seq_len, batch, dtype_bytes=2):return 2 * layers * kv_heads * head_dim * seq_len * batch * dtype_bytes / 1e9# 80 layers, 8 KV heads, head dimension 128, 128K context, concurrency 16, FP16print(round(kv_cache_gb(80, 8, 128, 128 * 1024, 16), 1))
The value of this exercise is not just the arithmetic. It tests whether a candidate can translate “longer context” into “linearly increasing memory consumption and reduced concurrency.” It also naturally leads to grouped-query attention, or GQA, in which multiple query heads share a group of KV heads. The KV-cache size decreases in proportion to the number of KV groups, at the cost of some representational capacity.
A deeper discussion can cover approaches that compress KV information into low-rank latent variables. The underlying principle is the same: use approximation to reduce memory requirements.
3. Layer Two: Three Technical Paths to Long Context
If an interviewer asks how to extend a context window from 2K to 256K, a strong answer should cover three technical paths and how they can be combined.
Path 1: Positional-Encoding Extrapolation
The frequencies used by rotary position embeddings determine how the model represents sequence length. Direct extrapolation can distort the attention distribution.
Common approaches include adjusting the base frequency, interpolating different frequency bands by dimension, or performing continued pretraining on a limited amount of long-context data. The key point is that extrapolation is a training-side modification: it is relatively inexpensive, but its stability must be validated. It is typically evaluated with retrieval-style “needle-in-a-haystack” tests on long documents.
Path 2: Sparse and Localized Attention
Real attention matrices often contain large regions with values close to zero. This observation has led to sliding-window attention, block-sparse attention, and hybrid patterns that combine global tokens with local windows.
The benefit is a reduction from quadratic complexity toward near-linear complexity. The risk is that cross-block information may be lost. Hierarchical stacking or global tokens are needed to preserve long-distance dependencies, and insufficient depth can still limit information propagation.
Path 3: Linear Attention and State-Space Models
Kernel decompositions or fixed-size states can compress historical information into constant-size memory, making the complexity linear in sequence length.
The limitation is weaker exact-recall capability. As a result, current practical designs often use hybrid architectures: a small number of layers retain full attention for precise retrieval, while most layers use linear or sparse structures for more economical long-range modeling.
4. Layer Three: Kernels, Parallelism, and Memory Engineering
- IO-aware tiled attention kernels: Partition Q into blocks, perform local softmax operations in on-chip SRAM, and accumulate results online without writing the N × N matrix to memory. This is a prerequisite for making long-context training practical. In an interview, emphasize that the main benefit is reducing HBM traffic, not reducing FLOPs.
- Activation recomputation and memory usage: Attention activations grow quadratically with sequence length. Selective recomputation trades additional computation for lower memory consumption.
- Context parallelism and sequence parallelism: Split a sequence across multiple devices and use ring-based communication to pass K/V blocks between devices during ultra-long-sequence training. Important considerations include communication volume, partitioning strategy, and load balance.
- Paged KV management and prefix reuse: Divide the KV cache into fixed-size blocks and map them through a page table. This reduces fragmentation and allows requests with identical prefixes to share cached data, substantially lowering time to first token.
- General cloud infrastructure: Training and inference clusters commonly rely on container platforms for elastic scheduling, object storage for datasets and checkpoints, and logging, monitoring, and alerting systems for observing throughput and failures. Cloud providers such as Baidu AI Cloud offer this type of general infrastructure capability; specific choices should be validated through workload benchmarking.
5. Layer Four: Inference Serving and Metrics
Common follow-up questions focus on the trade-off between throughput and latency.
Continuous batching, also called iteration-level scheduling, improves GPU utilization compared with static batching. Chunked prefill divides a long prompt into smaller pieces so that one long request does not block decoding for other requests. Separating prefill and decode into different deployments allows compute-intensive and bandwidth-intensive workloads to scale independently.
Speculative decoding uses a smaller model to draft tokens and a larger model to verify them, reducing the number of expensive decoding steps. Weight quantization and KV quantization can directly increase the maximum batch size.
Metrics should be discussed as a group:
- TTFT: Time to first token, influenced by prefill and queueing.
- TPOT or ITL: Time per output token, influenced by memory bandwidth and batch size.
- Overall throughput: Measured in tokens per second.
- Memory usage and concurrency limits: Key indicators of serving capacity.
A strong answer should connect metrics to causes: under long-context workloads, TTFT is dominated by the quadratic attention term, while TPOT is largely governed by KV-cache bandwidth.
6. Frequently Asked Questions: Key Points
Why move away from RNNs?
Sequential dependencies, limited parallelism, and long-range information decay.Where does attention complexity come from?
The N × N score matrix produces O(N²d) computation.What is the trade-off from MHA to MQA to GQA?
A balance between KV-cache capacity and representational capability.What is the most expensive part of long-context processing?
The quadratic attention term and the linear growth of the KV cache.How can you avoid materializing the N × N matrix?
Use tiling, online softmax, and recomputation.Why can positional-encoding extrapolation fail, and how can it be improved?
The frequency distribution becomes mismatched with the longer sequence length. Adjusting the base frequency, applying interpolation, or using continued pretraining can help.What can sparse attention lose?
Long-distance dependencies across blocks. Global tokens or deeper layer stacking can compensate.Why is linear attention less suitable for exact retrieval?
It compresses information into a fixed-size state. A hybrid architecture may be needed as a fallback.Where is the communication bottleneck in context parallelism?
Ring-based K/V transfers and load imbalance.How can serving concurrency be increased?
Use paged KV management, prefix reuse, quantization, and continuous batching.How should performance bottlenecks be located?
Start with operator-level profiling and HBM utilization, then determine whether the workload is compute-bound or bandwidth-bound.How should long-context support be validated before launch?
Use retrieval-based long-document evaluations and stress-test curves for TTFT, TPOT, and throughput.
7. Preparation Strategy
Organize every answer around four steps:
- Derive: Start with the relevant formula or mechanism.
- Estimate: Substitute realistic numbers from your own project or workload.
- Diagnose: Identify whether the bottleneck is computation, memory, bandwidth, communication, or scheduling.
- Evaluate trade-offs: Present two or three possible solutions and explain their costs.
This framework applies to attention, parallel execution, inference optimization, and nearly every other AI infrastructure topic. It demonstrates engineering judgment much more effectively than memorizing isolated conclusions.
