LLM Inference Platform Architecture: A Full-Stack Walkthrough from Request Scheduling to GPU Execution

    This article breaks down the technical stack of a large language model inference platform layer by layer, treating the engine core as an operating system with request scheduling, memory management, and concurrent execution. It explains why calling an API is not the same as understanding inference, how text becomes token IDs at the service layer, how continuous batching and paged KV Cache management drive throughput, and how tensor, pipeline, and data parallelism are applied. It closes with a practical path for reading the source code and validating your understanding with latency, throughput, and memory metrics.

    1. Why Calling an API Is Not the Same as Understanding an Inference Platform

    Many engineers get started by reading a quickstart guide, copying a launch configuration, and watching whether throughput improves. That approach solves today’s deployment problem, but it does not explain three things: why time-to-first-token swings wildly once concurrency doubles; why requests still queue even when GPU memory is not fully used; and why the same input length can yield twice the throughput under a different batching strategy.

    Answering these questions requires treating the inference platform as an operating system. It has request scheduling, memory management, concurrent execution, and device abstraction. The GPU is only the hardware that ultimately runs the compute. What actually decides who runs first, who runs together, and whether there is enough memory is the scheduling and execution logic in the middle layer, known as the EngineCore.

    Two foundations are worth filling in first. One is the data flow of multi-head attention and the Transformer: the Q/K/V projections, attention scoring, and residual stacking. The other is matrix multiplication and linear transformations from linear algebra. Engineers with a software background should not be intimidated: the vast majority of inference-stage computation is batched matrix multiply-add. The difficulty is not the math but data layout, parallel partitioning, and memory lifetime.

    2. The Big Picture: Which Layers a Request Passes Through

    A typical inference service can be abstracted as this chain:

    1. Client request
    2. → Access layer (protocol parsing / auth / rate limiting)
    3. → Service layer (chat template assembly / tokenization)
    4. → EngineCore (request queue / scheduler / memory management)
    5. → Executor (device orchestration / parallel communication)
    6. → Worker processes (model forward pass / sampling)
    7. → Result return and streaming output

    The key insight is that the earlier layers care about semantics and protocols, while the later layers care about tensors and GPU memory. That boundary usually falls at tokenization.

    3. Access Layer and Service Layer: Where Text Becomes Integers

    From the user’s perspective there is only one action: create a chat completion. The access layer is essentially a standard server application handling HTTP, connection reuse, timeouts, and rate limiting. Inference has not started yet at this point.

    The service layer does two things that are easy to underestimate:

    1. Chat template assembly. Role content such as system, user, and assistant is organized into a single string according to a template. This is pure string manipulation, but it directly determines the context boundaries the model sees.
    2. Tokenization. Text is mapped to a sequence of token IDs.

    Once tokenization is done in the service layer, what gets passed downstream is no longer text:

    1. # Request object handed from the service layer to the EngineCore (illustrative)
    2. {
    3. "token_ids": [101, 2054, 2003, ...], # List[int]
    4. "sampling_params": {"temperature": 0.7, "top_p": 0.9, "max_tokens": 256},
    5. "request_id": "req-8f3a",
    6. }

    Two important conclusions follow. The EngineCore is unaware of the tokenizer, and the device side has no idea what the user originally asked. Changing the tokenization scheme or adjusting the template is therefore a service-layer change and does not trigger a rewrite inside the engine. The direct benefit of this separation is that CPU-heavy work like tokenization is decoupled from the GPU forward pass, and each can scale independently.

    4. EngineCore: The Layer That Actually Makes Decisions

    The EngineCore typically contains three cooperating parts: the request queue, the scheduler, and the memory block manager.

    At every step the scheduler must answer one question: which requests and which tokens go into the same batch for this step. The mainstream industry approach is continuous batching, which does not wait for an entire batch to finish but admits new requests and evicts completed ones step by step. Compared with static batching, it changes GPU utilization from “waiting for the longest request” to “filling whatever execution space is currently available.”

    Memory management addresses fragmentation of the KV Cache. Autoregressive decoding needs to cache historical keys and values, and reserving contiguous memory for the maximum length wastes a great deal. Paged management splits the cache into fixed-size blocks, allocates them on demand, and maps logical block tables to physical blocks. This allows requests of different lengths to be mixed, and it also makes prefix reuse possible: blocks corresponding to the same system prompt can be shared across multiple requests.

    Scheduling policy also involves tradeoffs: when a new request in the waiting queue is admitted, and when a running request is preempted and swapped out. Admitting too early squeezes requests that are already decoding and causes jitter in the latency of tokens already produced; admitting too late builds up the queue and lowers throughput.

    5. Executor and Worker Processes: Where Parallelism Lands

    The executor distributes a batch of tokens to devices and handles the communication introduced by parallel partitioning. Common dimensions include tensor parallelism, which splits the weights of a single layer across multiple GPUs; pipeline parallelism, which partitions layers across multiple GPUs; and data parallelism, which replicates the model to spread requests. The choice depends mainly on whether a single GPU’s memory can hold the weights and cache, the interconnect bandwidth between cards, and the acceptable communication overhead.

    Worker processes run the model forward pass and sampling, produce the next token ID, and return it to the EngineCore, which appends it to the corresponding request’s sequence until a stop condition is met. This loop repeats until the request completes.

    6. A Practical Learning and Experimentation Path

    1. Reading order for the source code: start with the request object definition, then the main scheduling loop, then the memory block manager, and finally the executor and model forward pass. Do not start from the model code.
    2. Validate your understanding with metrics: watch time-to-first-token, per-token latency, throughput, memory usage, and preemption counts, and observe which one degrades first as load changes.
    3. Run controlled experiments: fix input and output lengths, change only the batching and parallelism configuration, record the differences, and build your own basis for judgment.
    4. If you use a cloud environment, you can rely on a container platform to host the inference processes, object storage to hold model files, and logging and monitoring services to track metrics. Platforms such as Baidu AI Cloud typically provide these general capabilities, letting you focus your energy on analyzing engine behavior.

    Once you master this chain, what you face is no longer a pile of parameters but a system behavior model you can reason about, verify, and tune.