Skip to content
Posts en inglés. Usá el traductor del navegador para leerlos en tu idioma.

How to Distribute Large Language Model Inference Across Multiple Nodes

Yammbo
· 8 min read
tensor parallelism pipeline parallelism data parallelism multi-node llm distributed llm inference
How to Distribute Large Language Model Inference Across Multiple Nodes

Deploying large language models (LLMs) in production often extends beyond the capabilities of a single server. When dealing with models in the 70B parameter range, complex Mixture-of-Experts (MoE) architectures, or workloads requiring extensive context, the entire model footprint can quickly exceed a single node's memory capacity. This situation transforms LLM inference into a distributed systems challenge, requiring careful consideration of how to split the model and its workload across multiple GPUs and nodes. This tutorial guides you through the process of choosing appropriate tensor, pipeline, and data parallelism degrees based on your model size, hardware topology, latency requirements, and traffic patterns.

Understand When Single-Node Serving Becomes Insufficient

The primary trigger for moving beyond single-node LLM serving is when the total memory footprint of your model and its operational overhead can no longer comfortably fit on a single node with adequate headroom. It's crucial to understand that this footprint extends far beyond just the model weights.

A production serving replica requires GPU memory for:

  • Model Weights: The parameters of the LLM itself.
  • KV Cache (Key-Value Cache): Stores intermediate attention outputs for efficient token generation. This can become the dominant memory component, scaling with context length, batch size, and the number of tokens generated.
  • Activation Buffers: Memory needed for intermediate computations during forward and backward passes.
  • NCCL Communication Buffers: Used by NVIDIA Collective Communications Library for inter-GPU data exchange.
  • Scheduler State and Runtime Metadata: Information managed by the inference server.
  • CUDA Graphs: Optimized execution paths for GPU operations.
  • Quantization Metadata: If using quantized models, additional data for de-quantization.
  • Speculative Decoding Buffers: If enabled, memory for generating speculative tokens.
  • Fragmentation and Safety Margin: Essential for stable operation under bursty traffic or varying workloads.

For many 70B-class models, model weights might fit on a single node, but long-context prompts, high concurrency, or large output lengths can push the KV cache memory requirement beyond a single GPU's capacity. For models exceeding 100B parameters or large MoE models, even the weights alone may not fit. A good rule of thumb is to avoid designing for 100% of nominal GPU memory. Insufficient headroom leads to instability under real-world conditions. The practical threshold for multi-node inference is not a specific parameter count, but rather the point where the total serving footprint no longer fits comfortably on a single node with reliable production headroom.

Grasp the Fundamentals of Parallelism Strategies

When a single node can no longer host your LLM, you must distribute the model and its computation. Three primary parallelism strategies are commonly employed:

Tensor Parallelism (TP)

Tensor parallelism involves splitting the computation within individual layers of the model across multiple GPUs. For example, a large matrix multiplication operation in a transformer layer might be divided, with each GPU computing a portion of the output. This requires frequent, high-bandwidth communication between the GPUs involved in the same layer's computation. TP is highly effective for reducing the memory footprint of individual layers and is typically applied within a single node where inter-GPU communication is fast (e.g., via NVLink).

Pipeline Parallelism (PP)

Pipeline parallelism assigns different groups of transformer layers to different GPUs, effectively creating a pipeline of computation stages. Each GPU (or a small group of GPUs) is responsible for processing a specific segment of the model's layers. A batch of data (or micro-batch) flows sequentially through these stages. While PP reduces the memory requirement per GPU by distributing layers, it can introduce pipeline bubbles (idle time) if not managed efficiently. It is generally more tolerant of higher communication latency than TP and can be used across nodes.

Data Parallelism (DP)

Data parallelism involves replicating the entire model (or a pipeline/tensor-parallelized segment of it) across multiple GPUs or nodes. Each replica processes a different batch of independent requests simultaneously. This strategy primarily boosts throughput by allowing many requests to be handled in parallel. Updates to model weights (during training) or shared states (less common in inference) are synchronized periodically. For inference, DP is often used as the outermost layer of parallelism, scaling the number of concurrent requests a system can handle.

Evaluate Your Model and Workload Characteristics

The specific attributes of your LLM and the expected traffic patterns significantly influence the optimal parallelism strategy.

  • Model Size and Type: Larger dense models (e.g., 70B+) and especially Mixture-of-Experts (MoE) models often necessitate both tensor and pipeline parallelism to distribute the sheer volume of parameters and activations. MoE models, with their sparse activation patterns, can introduce unique communication challenges.
  • Context Length: Workloads with very long input prompts or requiring extensive conversation history lead to a proportionally larger KV cache. Since the KV cache scales with context length and concurrency, this often becomes the dominant memory constraint, pushing the need for more parallelism, particularly strategies that distribute KV cache memory (e.g., pipeline parallelism across stages, or data parallelism to reduce per-replica concurrency).
  • Concurrency (Batch Size): The number of simultaneous requests impacts both memory (especially KV cache) and computational throughput. Higher concurrency can push a single node beyond its limits, making data parallelism across multiple replicas essential.
  • Output Length: Generating long outputs also contributes to KV cache growth and increases the total inference time. This can exacerbate latency concerns and further necessitate efficient distribution.
  • Quantization: Using quantized models (e.g., INT8, FP8) significantly reduces the memory footprint of model weights. While this can delay the need for multi-node inference, other memory components like the KV cache may still necessitate distributed approaches.

Verification: Profile your model's memory usage under representative long-context and high-concurrency scenarios on a single node to identify the point of saturation and determine which memory components are most constrained.

Assess Your Hardware Topology and Interconnect

The communication capabilities between your GPUs and nodes are critical determinants for choosing parallelism degrees.

  • Intra-Node Interconnect (e.g., NVLink, PCIe): Within a single server, GPUs are typically connected by high-bandwidth, low-latency interconnects like NVLink. This makes tensor parallelism highly efficient, as the frequent data exchange between GPUs within a layer can occur rapidly. When designing your system, prioritize maximizing the use of these fast links for tightly coupled operations.
  • Inter-Node Interconnect (e.g., InfiniBand, high-speed Ethernet): Communication between different servers (nodes) is inherently slower and has higher latency than intra-node communication. This makes strategies that require less frequent or less bandwidth-intensive inter-node communication more suitable. Pipeline parallelism, which passes activations between stages, and data parallelism, which synchronizes less frequently, are better suited for inter-node distribution.

Considerations:

  • Bandwidth: How much data can be transferred per second? Higher bandwidth supports more aggressive tensor parallelism.
  • Latency: How long does it take for data to travel between components? Low latency is crucial for tensor parallelism to avoid significant slowdowns.

Verification: Use network benchmarking tools (e.g., ib_write_bw for InfiniBand, NCCL tests) to understand the actual bandwidth and latency characteristics of your cluster's interconnects. This empirical data will inform realistic parallelism choices.

Define Your Latency and Throughput Requirements

Your service level agreements (SLAs) for inference latency and desired throughput directly impact how you combine parallelism strategies.

  • Latency SLA: If your application demands very low per-token generation latency, you must minimize communication overheads. Tensor parallelism, while reducing memory, can increase per-token latency if communication is not extremely fast. Pipeline parallelism introduces pipeline bubbles, which can add to overall latency, especially for small batch sizes. Data parallelism, by replicating the model, can reduce the queueing delay for individual requests, indirectly improving perceived latency for users.
  • Throughput: If the primary goal is to serve a high volume of requests per second, data parallelism is often the most effective strategy. By running multiple independent replicas of the model (each potentially using TP and PP internally), you can scale the total number of tokens processed per second.

Trade-offs:

  • Increasing tensor parallelism can reduce the memory footprint on individual GPUs but might increase per-token latency due to communication.
  • Increasing pipeline parallelism can distribute layers across more GPUs/nodes but introduces pipeline bubbles, affecting overall latency.
  • Increasing data parallelism directly scales throughput but requires more total GPU memory as the model is replicated.

Verification: Conduct load testing with different parallelism configurations to measure actual latency and throughput under target traffic patterns. This will reveal the practical impact of your chosen degrees on your specific hardware.

Combine Parallelism Strategies for Optimal Distribution

In most production scenarios, a hybrid approach combining tensor, pipeline, and data parallelism is necessary to achieve optimal performance and resource utilization for large LLMs. The goal is to balance memory distribution, communication overhead, and desired throughput/latency.

Here's a common approach to combining these strategies:

  1. Start with Tensor Parallelism (TP) within a Node: Utilize the fast intra-node interconnects (NVLink) to apply tensor parallelism to individual layers. This is highly effective for reducing the memory footprint of very large layers and activations on a single GPU. Determine the maximum TP degree that keeps per-token latency acceptable.
  2. Add Pipeline Parallelism (PP) across Nodes or within a Node: If the model still doesn't fit within the GPUs of a single node (even with TP), or if you need to further distribute memory, apply pipeline parallelism. This involves assigning groups of layers to different nodes or sets of GPUs. PP is more resilient to higher inter-node latency than TP.
  3. Layer Data Parallelism (DP) on Top: Once you have a single