Parallel Architectures and Cache Optimization for Large-Model Inference Deployment

    As model size, context length, and concurrency grow, inference bottlenecks shift among memory capacity, bandwidth, interconnect, compute utilization, and scheduling. This article explains data, tensor, expert, and pipeline parallelism, how attention compression and parallel-domain width change deployment scale, why prefill and decode need separate tuning, how to estimate KV cache, and how to balance throughput with latency in production.

    1. Background: How Deployment Constraints Change as Models Scale

    Deploying large-model inference is not simply a matter of loading a model onto more GPUs. As parameter count, context length, and concurrent requests increase, bottlenecks move among memory capacity, memory bandwidth, inter-node communication, compute utilization, and request scheduling.

    From an engineering standpoint, an inference service usually has to meet four goals at once:

    1. The model must load completely and run stably.
    2. Long-context requests must not exhaust cache memory quickly.
    3. Throughput should keep rising under high concurrency.
    4. Per-request latency and tail latency must stay within acceptable bounds.

    These goals trade off against each other. Larger batches often improve throughput, but they increase KV cache usage and queue time. Wider parallelism reduces per-GPU memory pressure, yet it adds cross-device communication. More cache capacity supports longer contexts, but it competes with model weights and intermediate activations for memory.

    A sound deployment plan therefore treats model structure, hardware topology, parallelism, and scheduling as one system. Parameter count or GPU count alone is not enough.

    2. Building Blocks of Parallelism

    2.1 Data Parallelism: Replicate the Model and Split Requests

    In data parallelism, each replica holds a full copy of the model, and different replicas serve different requests or batches.

    It is relatively simple to implement. Replicas do not need frequent layer-by-layer communication, so it fits when:

    • One replica fits on the target device or node.
    • Request volume is high and requests are independent.
    • The service cares more about aggregate throughput than about extremely low single-request latency.
    • Cluster network bandwidth is limited and cannot support frequent cross-device synchronization.

    Data parallelism does not solve the case where a single replica cannot hold the model. If weights, runtime buffers, and KV cache together exceed one device or one node, model-splitting parallelism is required.

    2.2 Tensor Parallelism: Split Computation Inside a Layer

    Tensor parallelism typically shards linear layers, attention projections, or other large matrix operations across devices. Each device stores only part of the weights and exchanges the intermediate results it needs.

    The main gains are lower per-GPU weight memory and more compute for a single request. The cost is frequent communication, especially between attention and feed-forward layers, which can trigger multiple collective operations. Tensor-parallel width should not grow without limit. It is usually best kept inside a high-speed interconnect domain.

    When tensor parallelism crosses nodes, bandwidth, latency, and topology directly affect performance. If shards are too fine and communication cannot keep up, device utilization drops, pipeline bubbles grow, and tail latency becomes jittery.

    2.3 Expert Parallelism: For Sparse Mixture-of-Experts Models

    For models with a sparse expert structure, expert parallelism places different experts on different devices. Each input activates only some experts, so total parameter count can stay large while the compute per token stays limited.

    Splitting experts is not enough. Token routing, cross-device exchange, load balance, and capacity limits all matter. If a few experts are selected too often, those devices become hot spots, other devices idle, and overall performance is capped.

    Watch in particular:

    • Whether each expert receives a balanced token count.
    • Whether routing communication dominates runtime.
    • Whether expert capacity limits drop tokens or add delay.
    • Whether routing stays stable across requests under high concurrency.

    2.4 Pipeline Parallelism: Split the Model by Layer

    Pipeline parallelism assigns successive layers or modules to different device groups. That reduces the weights each device must store, but it adds stage-to-stage transfers and pipeline bubbles.

    It fits very large models with heavy per-layer compute and large batches. If the batch is too small, stages cannot stay busy, early and late stages wait on each other, and utilization falls short of expectations.

    In practice, data parallelism is often combined with model splitting. One replica may use tensor or expert parallelism, while replicas themselves are data-parallel. A useful way to think about device count is:

    1. Total devices ≈ data-parallel degree × tensor-parallel degree × expert-parallel scale

    There is no fixed mix that fits every model. Weights, layer structure, device memory, and network topology all have to be measured.

    3. What Changes Across Model Generations

    Generational upgrades are not only about parameter count. They show up most clearly in attention structure, parallel-domain width, and cache layout.

    3.1 Attention Compression Changes Long-Context Cost

    Standard multi-head attention usually stores keys and values separately for each head. Longer context means faster KV cache growth and more memory pressure.

    With multi-head latent attention or similar compression, heads can share or compress part of the key-value state, so cache bytes per token drop sharply. Source comparisons across generations show cache use falling from about 70 KB/token to on the order of 890 B/token. Those figures depend on data type, implementation, layer count, cache layout, and how the numbers were measured. They are not a universal result for every system.

    The benefit shows up most in long-context and high-concurrency serving:

    • The same memory holds a longer history.
    • One device can host more concurrent sessions.
    • Requests are less often split because cache runs out.
    • History produced in prefill can be reused for longer.

    3.2 Parallel-Domain Width Sets the Minimum Deployment Size

    Weight size and per-replica memory demand set the minimum parallel domain: the smallest device group on which the model can run stably.

    Larger models usually need a higher mix of data parallelism and expert parallelism. One high-capacity configuration, for example, uses a data-parallel degree of 8 plus expert parallelism. A compressed or lighter version may drop the data-parallel degree to 4 while keeping a similar expert layout.

    The point is not any single number. The relationships are:

    • Larger weights mean more devices per replica.
    • Larger activations and KV cache mean more runtime headroom.
    • Higher parallelism means more communication and scheduling overhead.
    • The smallest runnable size is not the same as the size that maximizes throughput.

    Starting the model only means the capacity constraint is met. Stable throughput still requires checking communication efficiency, batching, and scheduling.

    4. Prefill and Decode Must Be Tuned Separately

    Inference is usually split into two phases.

    4.1 Prefill

    Prefill consumes the full user context and computes the initial state in one pass. It is compute-heavy: longer inputs generally mean more matrix work.

    Focus on:

    • Better batching efficiency.
    • A cap on input tokens per batch.
    • An efficient attention implementation.
    • Less useless padding.
    • Scheduling long and short inputs in separate groups.

    An oversized prefill batch can raise device utilization, but it also increases time to first token and temporary memory use. Online services usually need both an input-token limit and a prefill concurrency limit.

    4.2 Decode

    Decode typically emits only a few new tokens at a time, but it repeatedly reads the historical KV cache. It is therefore more sensitive to memory bandwidth, cache access, and the number of active requests.

    Focus on:

    • Continuous batching.
    • A limit on active sequences.
    • KV cache layout.
    • Less padding across sequences of different lengths.
    • Speculative decoding where the service can tolerate it.

    The best concurrency for prefill and decode is usually different. One shared batch limit can leave prefill hogging resources while decode queues, or leave decode devices idle. Separate resource pools, concurrency thresholds, and schedulers for the two phases are more effective.

    5. Estimating KV Cache Memory

    KV cache is the central resource for long-context inference. A simplified estimate is:

    1. KV cache size
    2. ≈ number of tokens × cache bytes per token × number of active sequences

    Bytes per token depend on:

    • Number of layers.
    • Number of key-value heads.
    • Dimension per head.
    • Cache data type.
    • Whether keys and values are shared or stored in a compressed latent space.
    • Whether the cache is quantized or paged.

    At an extreme of one million tokens of context, cache optimization matters much more. Source material for one newer model at that scale reports about 27% of the older version’s per-token compute and about 10% of its KV cache. Structural changes can cut both compute cost and runtime state.

    Theory is not the full budget. Also reserve space for:

    • Model weights.
    • CUDA or other compute runtime.
    • Intermediate activations.
    • Communication buffers.
    • Scheduler and cache metadata.
    • Fragmentation and a safety margin.

    Without that headroom, memory can still run out under high concurrency or long outputs even when the theoretical cache fits.

    6. Throughput and Latency Are Not One Metric

    Throughput is usually tokens generated per unit time. Latency breaks down further into:

    • Time to first token.
    • Inter-token interval.
    • End-to-end request latency.
    • P95 or P99 tail latency.

    Throughput and latency do not simply rise together. More concurrency often raises utilization and aggregate throughput, but it also increases queue time. Smaller batches can improve single-request response at the cost of lower utilization.

    Results depend on:

    1. Compute and memory bandwidth. Devices differ in FLOPs, bandwidth, and interconnect.
    2. Input and output length. Long inputs mainly hit prefill; long outputs keep decode busy.
    3. Cache hit rate. Prefix-cache hits avoid repeated compute, but they consume more cache.
    4. Speculative decoding. A high acceptance rate cuts main-model steps; a low rate can make extra verification cost more than it saves.
    5. Scheduling. Continuous batching, priority queues, and isolating long and short requests all change the outcome.
    6. Communication topology. Cross-node traffic can erase a theoretical compute advantage.

    Reports should include throughput, time to first token, average per-token latency, and tail latency, and they should state input length, output length, concurrency, data type, cache hit rate, and parallel configuration.

    7. Deployment Recommendations

    7.1 Plan Capacity Before Choosing Parallelism

    Start with a memory budget:

    1. Total memory
    2. = weights
    3. + KV cache
    4. + activations and temporary buffers
    5. + communication buffers
    6. + runtime overhead
    7. + safety margin

    Decide how many devices one replica needs, then choose the mix of data, tensor, and expert parallelism. Do not reverse-engineer the model layout from the number of devices you happen to have.

    7.2 Keep Frequent Communication Inside the Fast Interconnect

    Where the fabric is hierarchical, put tensor and expert parallelism inside the high-speed group, and scale data-parallel replicas more widely. That limits the latency impact of cross-node collectives.

    7.3 Isolate Prefill and Decode

    With long inputs and high concurrency, put prefill and decode in separate pools so each phase can scale on its own. Online services should also cap maximum input length, maximum output length, per-request cache, and queue wait time.

    7.4 Measure What Matters

    At a minimum, collect:

    • Device compute utilization.
    • Memory usage and cache occupancy.
    • Prefill and decode time.
    • Cross-device communication time.
    • Request queue time.
    • Time to first token and tail latency.
    • Cache hit rate.
    • Speculative-decoding acceptance rate.
    • Per-expert load.

    These signals show whether the limit is compute, communication, cache, or scheduling.

    8. Limits When Moving Across Platforms

    The same settings are not automatically optimal on different hardware. Compute, bandwidth, memory capacity, interconnect, and operator support all differ, so parallel width, batch size, and cache policy need to be recalibrated.

    Deterministic inference can also shift with reduction order, floating-point precision, operator implementation, and schedule timing. If the service requires consistent results, set the precision mode, control randomness, and define evaluation tolerance. Comparing final text for an exact match is not enough.

    Cross-system comparisons need a shared protocol: model version, weight precision, context length, output length, concurrency, cache state, and percentile. Throughput and latency are comparable only when those conditions match.

    Efficient deployment is not just adding devices. Model structure, parallel domains, cache hierarchy, request scheduling, and hardware topology have to work together. For enterprise services, a cloud platform’s container runtime, monitoring and alerting, and elastic resource management—such as those on Baidu AI Cloud—can close the loop from capacity planning and load testing through production observation.