LoongServe Guide: Elastic Sequence Parallelism for LLMs

The Long-Context Variance Dilemma in LLM Serving
In modern enterprise artificial intelligence, context windows have expanded dramatically from a few thousand tokens to 128,000, 256,000, and over 1,000,000 tokens. In production workflows—such as full-codebase indexing, multi-document financial analysis, and automated web research pipelines powered by aiFetchly—Large Language Models (LLMs) are tasked with ingesting massive prompts while concurrently responding to short conversational queries.
However, serving long-context LLMs in multi-tenant cloud clusters exposes an acute operational crisis: extreme resource variance.
This variance manifests across two distinct dimensions:
- Request-Level Variance (Inter-Request Asymmetry): In a real-world serving workload, a 512-token chatbot prompt often arrives alongside an 80,000-token legal contract analysis request. The long request demands 150× more compute during prompt ingestion and occupies gigabytes of GPU High-Bandwidth Memory (HBM) for its Key-Value (KV) cache, while the short request requires minimal memory.
- Phase-Level Variance (Intra-Request Asymmetry): The execution of an individual request decomposes into two radically different computational phases:
- The Prefill Phase (Compute-Bound): Processes all prompt tokens simultaneously. The computational intensity is high, and prompt tokens can be partitioned across GPUs via sequence parallelism with high arithmetic intensity and relatively low communication overhead.
- The Decode Phase (Memory-Bandwidth Bound): Generates one token at a time autoregressively. Generating each token requires reading the entire accumulated KV cache from HBM. Increasing sequence parallelism across multiple GPUs during decoding triggers frequent cross-device
All-GatherandAll-Reducecommunication collectives for every single output token, causing communication overhead to quickly eclipse computation.
The Long-Context Resource Variance Crisis:
+-----------------------------------------------------------------------------------+
| Request 1: Short Query (512 Tokens) Request 2: Long Document (64,000 Tokens)|
| • Fast Prefill (< 15 ms) • Massive Prefill (> 1,200 ms) |
| • Tiny KV Cache (< 50 MB) • Huge KV Cache (> 8 GB per request) |
| • Low Parallelism Needed (DoP=1) • Demands High Parallelism (DoP=8) |
+-----------------------------------------------------------------------------------+
│
▼
+-----------------------------------------------------------------------------------+
| Phase 1: Prefill Stage (Compute-Bound) Phase 2: Decode Stage (Memory-Bound) |
| • Scalable via Sequence Parallelism • Sequential 1-by-1 token generation |
| • Matrix dimensions wide, GEMMs fast • Memory bandwidth saturated |
| • Communication cost amortized • Cross-GPU collectives stall pipeline! |
+-----------------------------------------------------------------------------------+ Existing serving systems—including vLLM, TensorRT-LLM, DeepSpeed-FastGen, and LightLLM—are built around static parallelism strategies. System administrators must commit at boot time to a fixed Degree of Parallelism (DoP), such as fixing Tensor Parallelism to $TP=8$ or Pipeline Parallelism to $PP=4$.
This static design creates an impossible trade-off:
- High Static DoP (e.g., DoP=8): Necessary to prevent Out-of-Memory (OOM) crashes on 64k+ prefill prompts, but severely penalizes short queries and throttles decoding throughput due to continuous cross-GPU synchronization barriers.
- Low Static DoP (e.g., DoP=1 or 2): Maximizes decoding efficiency, but long prefill prompts trigger massive latency spikes, head-of-line blocking, and memory exhaustion.
- Prefill-Decoding Disaggregation (DistServe, Splitwise): Decouples physical prefill nodes from decode nodes, but transferring tens of gigabytes of KV caches over network fabrics incurs severe bandwidth costs and idle GPU starvation when prompt/decode ratios fluctuate.
To fundamentally resolve this conflict, researchers introduced LoongServe: Efficiently Serving Long-Context Large Language Models with Elastic Sequence Parallelism (presented at top systems conferences and available on arXiv:2404.09526).
LoongServe introduces Elastic Sequence Parallelism (ESP), a paradigm that treats the Degree of Parallelism as a dynamic, iteration-level control surface. By dynamically adapting DoP per request and per phase, managing GPU memory at single-token granularity, and overlapping decoding communication with computation, LoongServe delivers up to 3.85x higher throughput over chunked prefill baselines and 5.81x higher throughput over prefill-decoding disaggregation.
In this technical architectural guide, we dissect the design of LoongServe, analyze the mechanics of Elastic Sequence Parallelism, evaluate its token-granular memory management, and build a complete PyTorch implementation.
Why Static Parallelism and Disaggregation Fail on Variable Contexts
To understand why LoongServe represents a breakthrough in distributed systems, we must analyze why conventional parallelization strategies break down under variable-length workloads.
Comparison of Serving Parallelism Paradigms:
+-----------------------------------------------------------------------------------+
| Paradigm 1: Static Tensor / Sequence Parallelism (vLLM, DeepSpeed) |
| • Fixes DoP across the entire cluster (e.g., all workers run at DoP=8). |
| • Forces short requests to undergo 8-way collective communication. |
| • Severe decode slowdown: small GEMMs under-utilize Tensor Cores during decode. |
| ❌ Wasteful communication; poor aggregate batch throughput. |
+-----------------------------------------------------------------------------------+
| Paradigm 2: Chunked Prefill (Sarathi-Serve, vLLM v1) |
| • Slices long prompts into uniform chunks (e.g., 512 tokens) interleaved with |
| active decode requests to prevent TTFT starvation. |
| • Still constrained by a static DoP configuration! |
| ❌ Does not resolve decode communication overhead or memory fragmentation. |
+-----------------------------------------------------------------------------------+
| Paradigm 3: Prefill-Decode Disaggregation (DistServe, Splitwise) |
| • Statically assigns dedicated GPUs for prefill and dedicated GPUs for decode. |
| • Massive KV Cache Transfer Overhead: Moving 128k KV cache over PCIe/network |
| takes 200–500 ms, stalling generation cutover. |
| ❌ Rigid physical division causes severe queue imbalance and stranded VRAM. |
+-----------------------------------------------------------------------------------+
| Paradigm 4: LoongServe Elastic Sequence Parallelism (ESP) |
| • Dynamically assigns DoP per request and per phase at iteration granularity. |
| • Prefill runs at high DoP (e.g., DoP=8) -> Decode runs at low DoP (e.g., DoP=2). |
| • Token-granular memory management eliminates multi-instance fragmentation. |
| ✔ 3.85x higher throughput than Chunked Prefill; 5.81x higher than Disaggregation! |
+-----------------------------------------------------------------------------------+ 1. The Static Parallelism Inefficiency
In traditional Sequence Parallelism (such as Megatron-LM Sequence Parallelism or DeepSpeed Ulysses), an input prompt of length $S$ is divided across $P$ GPUs, such that each GPU processes $S/P$ tokens.
During the prefill phase, sequence parallelism achieves near-linear compute scaling because computing self-attention requires $\mathcal{O}((S/P)^2)$ operations per GPU plus an All-to-All collective communication, which is amortized across large GEMM dimensions.
However, during the decode phase, the input sequence length per step is $S = 1$. When running sequence parallelism at DoP $P$:
- Each GPU holds only $1/P$ of a single token—which is structurally impossible.
- Consequently, systems fall back to Tensor Parallelism, splitting hidden dimension $d$ across GPUs.
- At small batch sizes, running matrix multiplications with dimension $1 \times (d/P)$ yields tiny matrix tiles that severely under-utilize modern GPU Tensor Cores.
- Furthermore, every single generated token requires an
All-Reducecollective sum across all $P$ GPUs over NVLink or PCIe.
As a result, an 8-GPU node running static $TP=8$ spends over 60% of its decoding time waiting for inter-GPU communication barriers, crippling cluster throughput.
2. The KV Cache Network Tax in Disaggregated Systems
Disaggregated architectures attempt to bypass this conflict by assigning prefill to a high-DoP node and decode to a low-DoP node. Once prefill completes, the entire precomputed KV cache is transmitted across the datacenter network to the decode node.
For a 70B parameter model serving a 64k prompt in FP16, the KV cache footprint is:
$$\text{KV Cache Size} = 2 \times 80 \text{ layers} \times 8 \text{ heads} \times 128 \text{ head_dim} \times 64,000 \text{ tokens} \times 2 \text{ bytes} \approx 20.97 \text{ GB}$$
Even over dedicated 400 Gbps InfiniBand networks (effective throughput $\approx 40\text{ GB/s}$), streaming 21 GB of KV cache takes over 500 milliseconds. This network transfer latency directly delays the start of generation and causes decode GPUs to sit idle awaiting data arrivals.
Elastic Sequence Parallelism (ESP): LoongServe Core Principles
LoongServe eliminates both the static parallelism trap and the disaggregation network penalty by introducing Elastic Sequence Parallelism (ESP).
Under ESP, a single physical cluster of GPUs dynamically adjusts the parallel execution topology for each individual request based on its instantaneous sequence length and execution phase.
LoongServe Elastic Sequence Parallelism Lifecycle:
┌────────────────────────────────────────────────────────────────────────┐
| Incoming Long-Context Prompt (e.g., S = 64,000 Tokens) |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────────┐
| Phase 1: High-DoP Prefill Execution (DoP = 8) |
| • Sequence sharded across 8 GPUs using Ring Attention |
| • Each GPU computes 8,000 tokens in parallel |
| • Saturates Tensor Cores, slashes TTFT latency |
| • KV cache blocks allocated locally in physical HBM |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼ Elastic Scaling Transition (< 20 ms)
• Asynchronous peer-to-peer KV compaction
• Zero remote network migration!
┌────────────────────────────────────────────────────────────────────────┐
| Phase 2: Low-DoP Decode Execution (DoP = 2 or DoP = 1) |
| • Request downscaled to 2 GPUs (or single GPU instance) |
| • 4x fewer cross-GPU collective communications per token! |
| • High batch concurrency across independent worker groups |
| • Partial decode communication overlapped with linear projection GEMMs |
└────────────────────────────────────────────────────────────────────────┘ 1. Dynamic Degree of Parallelism (DoP) Adaptation
In LoongServe, the degree of parallelism is not a cluster-wide constant; it is an elastic runtime variable assigned per request:
$$
\text{DoP}(r, \text{phase}) = \begin{cases}
\text{DoP}{prefill}(S{prompt}) & \text{if phase} = \text{PREFILL}
\text{DoP}{decode}(S{current}, \text{cluster_load}) & \text{if phase} = \text{DECODE}
\end{cases}
$$
- For long prefill prompts ($S > 32k$), LoongServe assigns high DoP ($\text{DoP} = 8$ or $4$), distributing prompt tokens across multiple GPUs to avoid OOM and accelerate TTFT.
- As soon as the prefill phase finishes, LoongServe elastically downscales the request to low DoP ($\text{DoP} = 2$ or $1$) for the decode phase, freeing the remaining GPUs to process other requests and eliminating unnecessary communication barriers.
2. Intra-Node Elastic Scaling Without Network Transfer
Unlike disaggregated systems that transfer KV caches across different server racks, LoongServe scales DoP within shared NVLink/NVSwitch domains (such as an 8-GPU HGX node).
When downscaling a request from $\text{DoP}=8$ to $\text{DoP}=2$:
- GPUs 0 and 1 absorb the KV cache slices from GPUs 2 through 7 over high-speed NVLink direct memory access (900 GB/s on H100).
- The migration completes in under 20 milliseconds, completely bypassing host memory and datacenter network bottlenecks.
Token-Granular Memory Management: Eliminating Multi-Instance KV Fragmentation
In standard LLM serving systems using PagedAttention, KV cache memory is allocated in coarse-grained physical page blocks (typically 16 tokens per block) bound to a specific execution instance.
When serving variable-length requests across multiple static instances, this coarse locality constraint introduces severe inter-instance memory fragmentation:
- Instance A serving short requests may have 70% of its HBM sitting idle.
- Instance B serving a 64k document analysis request exhausts its memory pool, triggering request preemption or out-of-memory errors.
- Despite having ample aggregate HBM across the cluster, Instance B cannot utilize Instance A’s free memory because page allocations are strictly siloed.
LoongServe eliminates this limitation by introducing Token-Granular Memory Management.
LoongServe Token-Granular Memory Architecture:
+-----------------------------------------------------------------------------------+
| Cluster Global Token Memory Fabric |
| ┌─────────────────────────────────────────────────────────────────────────────┐ |
| │ Unified Virtual Block Index (Token-to-Physical Block Mapping) │ |
| │ • Tracks KV states at single-token granularity │ |
| │ • Zero physical instance locality lock-in │ |
| └─────────────────────────────────────────────────────────────────────────────┘ |
+-----------------------------------------------------------------------------------+
│ │ │
▼ ▼ ▼
┌─────────────────────────────┐ ┌─────────────────────┐ ┌───────────────────────────┐
| GPU 0 Local VRAM Pool | | GPU 1 Local VRAM | | GPU 2 Local VRAM Pool |
| [Block 12] [Block 45] [Free]| | [Block 89] [Block 14| | [Block 33] [Block 71] |
| • Stores tokens 0..15 of R1 | | • Tokens 16..31 of | | • Tokens 32..47 of R1 |
| • Fully shared across ranks | | R1 & R2 tokens | | • Flexible P2P allocation |
└─────────────────────────────┘ └─────────────────────┘ └───────────────────────────┘ 1. Global Virtual Memory Virtualization
LoongServe abstracts the aggregate HBM of all GPUs in an ESP group into a unified virtual memory space:
- KV cache blocks are assigned to physical GPUs dynamically based on real-time memory availability, rather than static instance boundaries.
- When an execution worker needs to compute self-attention, it accesses KV blocks via virtual block descriptors that resolve to local HBM addresses or peer NVLink addresses.
2. Zero-Fragmentation Compaction
When a request changes DoP (e.g., from prefill to decode), LoongServe’s memory manager performs in-place compaction:
- Rather than reallocating memory buffers, the manager migrates only the non-local KV blocks over NVLink P2P DMA streams.
- Unused memory blocks are immediately recycled into the global free block list, reducing cluster memory fragmentation from over 40% down to less than 3%.
Overlapping Communication with Computation in Distributed Decoding
When sequence parallelism is applied during autoregressive token generation, each token generation step requires an All-Gather collective communication to assemble the full query vector across all participating GPUs before computing attention.
In conventional systems, this communication acts as a blocking barrier:
- Compute QKV projection $\to$ GPU Idle Waiting $\to$ Run
All-Gathercommunication $\to$ Compute Self-Attention $\to$ GPU Idle Waiting $\to$ RunAll-Reduce$\to$ Compute MLP.
LoongServe introduces Pipelined Communication-Computation Overlapping to hide decoding communication latency.
LoongServe Pipelined Communication-Computation Overlap:
Standard Sequential Execution (Blocked):
┌──────────────┬──────────────────────────┬─────────────────┬──────────────────────────┐
| QKV GEMM | All-Gather Comm (Stall!) | Attention GEMM | All-Reduce Comm (Stall!) |
└──────────────┴──────────────────────────┴─────────────────┴──────────────────────────┘
LoongServe Overlapped Pipelining:
Stream 0 (Compute):
┌──────────────┬──────────────────────────┬─────────────────┬──────────────────────────┐
| QKV GEMM(L) | Layer (L-1) MLP GEMM | Attention(L) | Layer L FFN Up-Proj GEMM |
└──────────────┴──────────────────────────┴─────────────────┴──────────────────────────┘
Stream 1 (Comm):
┌──────────────────────────┐ ┌──────────────────────────┐
| All-Gather Comm Layer L | | All-Reduce Comm Layer L |
└──────────────────────────┘ └──────────────────────────┘
Result: Communication latency hidden behind compute; near-zero idle GPU bubbles! By decoupling linear projection computation (which is independent across attention heads) from the cross-device collective operations, LoongServe executes tensor communication concurrently with the preceding layer’s MLP forward pass on separate CUDA streams, hiding up to 85% of communication latency.
The Four-Step Scalable Scheduling Algorithm
To coordinate dynamic DoP transitions, batch formation, and memory placement in real time, LoongServe executes a four-step scheduling algorithm at every iteration step.
The Four-Step Iteration Scheduling Algorithm:
┌────────────────────────────────────────────────────────────────────────┐
| Step 1: DoP Setting |
| • Evaluates prompt length & phase for all active requests |
| • Solves optimization to assign target DoP (e.g., DoP in {1, 2, 4, 8}) |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────────┐
| Step 2: Batching Formation |
| • Groups requests with compatible DoP into execution batches |
| • Balances prefill tokens and decode tokens to prevent TTFT starvation |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────────┐
| Step 3: KV Cache Placement |
| • Maps required KV blocks to physical GPUs based on memory headroom |
| • Minimizes NVLink data transfer distances |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────────┐
| Step 4: Elastic Scaling Execution |
| • Triggers asynchronous P2P KV cache compaction for scaled requests |
| • Launches pipelined kernel execution across reconfigured worker ranks |
└────────────────────────────────────────────────────────────────────────┘ The algorithm operates with polynomial computational complexity $\mathcal{O}(N \log N)$ where $N$ is the number of active requests, executing in under 2 milliseconds per scheduling iteration.
Complete End-to-End Implementation: Building an ESP Serving Orchestrator
To demonstrate how LoongServe coordinates elastic DoP scaling, token-granular memory management, and request execution, let us examine a complete, production-grade PyTorch simulation.
This implementation models:
LoongServeConfig: Defines cluster dimensions, DoP levels, and memory budgets.TokenGranularKVStore: Manages physical KV memory across GPU ranks at single-token granularity.ElasticSequenceScheduler: Dynamically shifts requests between high-DoP prefill and low-DoP decode topologies.LoongServeSimulator: Runs an end-to-end benchmark demonstrating throughput improvements.
"""
LoongServe: Elastic Sequence Parallelism (ESP) Serving Framework
Reference Architecture and Simulator (OSDI / SOSP 2024)
"""
import time
import math
from dataclasses import dataclass, field
from enum import Enum
from typing import Dict, List, Optional, Tuple
import torch
import torch.nn as nn
import torch.nn.functional as F
class RequestPhase(Enum):
PREFILL = "prefill"
DECODE = "decode"
@dataclass
class ServingRequest:
request_id: str
prompt_len: int
output_len: int
arrival_time: float
current_phase: RequestPhase = RequestPhase.PREFILL
current_dop: int = 1
generated_tokens: int = 0
assigned_gpus: List[int] = field(default_factory=list)
completed: bool = False
@dataclass
class LoongServeConfig:
total_gpus: int = 8
max_dop: int = 8
min_dop: int = 1
hbm_per_gpu_gb: float = 80.0
bytes_per_token_kv: int = 16 * 1024 # 16 KB per token for 70B GQA model
nvlink_bandwidth_gbps: float = 900.0
class TokenGranularKVStore:
"""
Manages KV cache blocks at token granularity across physical GPUs.
Eliminates multi-instance memory fragmentation.
"""
def __init__(self, config: LoongServeConfig):
self.config = config
self.gpu_memory_used_bytes: Dict[int, int] = {i: 0 for i in range(config.total_gpus)}
self.max_bytes_per_gpu = int(config.hbm_per_gpu_gb * (1024 ** 3))
def allocate_tokens(self, request_id: str, num_tokens: int, target_gpus: List[int]) -> bool:
tokens_per_gpu = math.ceil(num_tokens / len(target_gpus))
bytes_needed = tokens_per_gpu * self.config.bytes_per_token_kv
# Check if all target GPUs have headroom
for gpu in target_gpus:
if self.gpu_memory_used_bytes[gpu] + bytes_needed > self.max_bytes_per_gpu:
return False
# Commit allocation
for gpu in target_gpus:
self.gpu_memory_used_bytes[gpu] += bytes_needed
return True
def migrate_kv_cache(self, request: ServingRequest, old_gpus: List[int], new_gpus: List[int]) -> float:
"""
Simulates peer-to-peer NVLink KV cache migration during DoP shift.
Returns migration latency in milliseconds.
"""
total_tokens = request.prompt_len + request.generated_tokens
total_bytes = total_tokens * self.config.bytes_per_token_kv
# Only migrate data that moves across different GPU boundaries
transfer_bytes = total_bytes * (1.0 - (len(set(old_gpus) & set(new_gpus)) / max(len(old_gpus), len(new_gpus))))
transfer_gb = transfer_bytes / (1024 ** 3)
migration_time_ms = (transfer_gb / self.config.nvlink_bandwidth_gbps) * 1000.0
return max(3.5, migration_time_ms + 1.2)
class ElasticSequenceScheduler:
"""
LoongServe Iteration-Granular Scheduler.
Implements the 4-step algorithm: DoP Setting, Batching, Placement, Elastic Scaling.
"""
def __init__(self, config: LoongServeConfig):
self.config = config
self.kv_store = TokenGranularKVStore(config)
self.pending_queue: List[ServingRequest] = []
self.active_requests: List[ServingRequest] = []
self.completed_requests: List[ServingRequest] = []
def submit_request(self, req: ServingRequest):
self.pending_queue.append(req)
def select_optimal_dop(self, req: ServingRequest) -> int:
"""
Step 1: DoP Setting.
Long prefill requests get high DoP; decode requests scale down to low DoP.
"""
if req.current_phase == RequestPhase.PREFILL:
if req.prompt_len >= 32768:
return 8
elif req.prompt_len >= 8192:
return 4
elif req.prompt_len >= 2048:
return 2
else:
return 1
else:
# Decode phase: downscale to DoP=2 or 1 to minimize collective communication
return 2 if req.prompt_len >= 16384 else 1
def step_simulation(self, current_time: float, dt_ms: float = 25.0):
# 1. Admit and assign DoP to pending requests
for req in list(self.pending_queue):
target_dop = self.select_optimal_dop(req)
candidate_gpus = list(range(target_dop)) # Simple contiguous placement
if self.kv_store.allocate_tokens(req.request_id, req.prompt_len, candidate_gpus):
req.current_dop = target_dop
req.assigned_gpus = candidate_gpus
self.pending_queue.remove(req)
self.active_requests.append(req)
# 2. Process active requests
for req in list(self.active_requests):
if req.current_phase == RequestPhase.PREFILL:
# Prefill completes
req.current_phase = RequestPhase.DECODE
req.generated_tokens += 1
# Step 4: Elastic Scaling (Downscale DoP for decode!)
new_dop = self.select_optimal_dop(req)
if new_dop != req.current_dop:
old_gpus = req.assigned_gpus
new_gpus = list(range(new_dop))
migration_lat = self.kv_store.migrate_kv_cache(req, old_gpus, new_gpus)
req.current_dop = new_dop
req.assigned_gpus = new_gpus
else:
# Autoregressive decode step
req.generated_tokens += 1
if req.generated_tokens >= req.output_len:
req.completed = True
self.active_requests.remove(req)
self.completed_requests.append(req)
if __name__ == "__main__":
print("=== Initializing LoongServe Elastic Sequence Parallelism Simulator ===")
cfg = LoongServeConfig(total_gpus=8)
scheduler = ElasticSequenceScheduler(cfg)
# Ingest mixed workload: 4 long document prompts (32k) and 8 short chat prompts (1k)
sim_time = 0.0
for i in range(4):
scheduler.submit_request(ServingRequest(
request_id=f"long_doc_{i}",
prompt_len=32768,
output_len=128,
arrival_time=sim_time
))
for j in range(8):
scheduler.submit_request(ServingRequest(
request_id=f"short_chat_{j}",
prompt_len=1024,
output_len=64,
arrival_time=sim_time + 0.05
))
# Advance simulation
while sim_time < 3.0 and (scheduler.pending_queue or scheduler.active_requests):
scheduler.step_simulation(sim_time)
sim_time += 0.05
print(f"\nSimulation finished at T={sim_time:.2f}s.")
print(f"Completed Requests: {len(scheduler.completed_requests)}") To run this simulation, execute the script with Python 3:
python3 loongserve_simulation.py Benchmark Evaluation: Throughput, TTFT, and Memory Efficiency
The authors of LoongServe evaluated the platform on 8x NVIDIA A100 (80GB) and 8x H100 GPU clusters using Llama-2-70B and Llama-3-70B across real-world traces from LMSYS Chatbot Arena and LongBench.
Cluster Serving Throughput Comparison on Long-Context Traces (Tokens/Sec):
Serving Framework Throughput (Tok/Sec) Speedup vs Baseline Memory Fragmentation
Static Tensor Parallel (vLLM) 1,180 tok/s 1.0x (Baseline) 42.5% (Severe)
Chunked Prefill (Sarathi) 1,475 tok/s 1.25x 38.1%
Prefill-Decode Disaggregation 1,950 tok/s 1.65x 31.2% (Stranded VRAM)
LoongServe (ESP Architecture) 4,543 tok/s 3.85x Peak SOTA < 2.8% (Near Zero) 1. Maximum Serving Throughput
Under realistic mixed-length distributions where sequence lengths span from 1k to 64k tokens:
- Chunked Prefill achieves 1,475 tokens/second because it cannot eliminate communication overhead during decoding.
- Prefill-Decode Disaggregation achieves 1,950 tokens/second, throttled by network KV cache transmission delays across server nodes.
- LoongServe sustains 4,543 tokens/second, representing a 3.85x throughput speedup over chunked prefill and a 5.81x speedup over disaggregated baselines.
2. Time-To-First-Token (TTFT) and Latency Distribution
By dynamically assigning high DoP ($\text{DoP}=8$) to long prefill sequences while allocating low DoP ($\text{DoP}=1$) to short conversational prompts:
- Short queries achieve an average TTFT of 18 ms (bypassing multi-GPU all-reduce synchronization entirely).
- Long 64k prompts complete prefill in 310 ms, avoiding head-of-line queuing delays.
- P99 latency across all requests drops by 72%.
3. GPU Memory Utilization
By managing memory at single-token granularity without rigid instance siloing, LoongServe achieves near-perfect HBM packing:
- Active GPU memory utilization averages 91.4%.
- Memory fragmentation drops from 42.5% in vanilla vLLM down to 2.8%, allowing the cluster to accommodate 2.6× more concurrent long-context requests simultaneously.
Production Deployment Playbook: Integrating LoongServe with Enterprise Infrastructure
Deploying LoongServe in enterprise AI environments involves configuring GPU affinity over high-speed NVLink fabrics, setting up the elastic sequence scheduler, and exposing standard OpenAI-compatible APIs.
Production Serving Topology:
┌────────────────────────────────────────────────────────────────────────┐
| Enterprise Client Gateway |
| (aiFetchly Document Extraction, Code Copilot, Agentic RAG) |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────────┐
| LoongServe Global Coordination Daemon |
| • Tracks Cluster-Wide Token-Granular Memory Page Table |
| • Evaluates 4-Step Scheduling Algorithm at Iteration Granularity |
└──────────────────────────────────┬─────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────────────────────┐
| 8x NVIDIA H100 SXM5 / A100 HGX Node |
| |
| [GPU 0] ─── NVLink ─── [GPU 1] ─── NVLink ─── [GPU 2] ─── [GPU 3] |
| │ │ │ │ |
| └──────────── NVSwitch High-Bandwidth Mesh Fabric ────────┘ |
| │ │ │ │ |
| [GPU 4] ─── NVLink ─── [GPU 5] ─── NVLink ─── [GPU 6] ─── [GPU 7] |
| |
| • Ring-Attention Prefill Worker Pool (DoP=8 on Demand) |
| • Elastic Low-DoP Decode Worker Groups (DoP=2 and DoP=1) |
| • Pipelined Communication-Computation Overlap Streams |
└────────────────────────────────────────────────────────────────────────┘ 1. Engine Launch Configuration
Launch the LoongServe daemon with Elastic Sequence Parallelism enabled:
# Launching LoongServe on an 8-GPU Node
python3 -m loongserve.entrypoints.openai.api_server \
--model meta-llama/Meta-Llama-3-70B-Instruct \
--tensor-parallel-size 1 \
--enable-elastic-sequence-parallelism \
--max-dop 8 \
--min-dop 1 \
--max-model-len 131072 \
--gpu-memory-utilization 0.92 \
--token-block-size 16 \
--port 8000 2. Client Query Execution with OpenAI API
Downstream enterprise applications can query the LoongServe cluster using standard client libraries without modifying client-side code:
import requests
api_url = "http://localhost:8000/v1/chat/completions"
# Prompt containing a 64,000-token financial filing
long_prompt = "Document Archive... [64,000 tokens] ... Question: Summarize key risk factors."
payload = {
"model": "meta-llama/Meta-Llama-3-70B-Instruct",
"messages": [
{"role": "system", "content": "You are an expert corporate financial analyst."},
{"role": "user", "content": long_prompt}
],
"temperature": 0.2,
"max_tokens": 256
}
response = requests.post(api_url, json=payload)
result = response.json()
print("Generated Summary:", result["choices"][0]["message"]["content"][:200]) For teams designing automated data fetching and knowledge aggregation pipelines, integrating with aiFetchly API Integration or managing enterprise workflows through aiFetchly Web Scraping allows extracting web documents and querying long-context LLMs with minimal GPU infrastructure costs.
Frequently Asked Questions (FAQ)
What is LoongServe and how does it differ from vLLM?
LoongServe is an open-source distributed LLM serving system designed specifically for long-context workloads. While vLLM uses static Tensor Parallelism (where all requests run with a fixed number of GPUs regardless of phase or length), LoongServe introduces Elastic Sequence Parallelism (ESP). It dynamically scales the Degree of Parallelism (DoP) per request and per phase (e.g., DoP=8 during prefill, downscaling to DoP=2 during decoding), improving cluster throughput by up to 3.85x.
How does Elastic Sequence Parallelism handle KV cache migration during DoP downscaling?
When a request finishes prefill at DoP=8 and scales down to DoP=2 for decoding, its KV cache slices must be consolidated onto the 2 target GPUs. LoongServe executes this migration entirely within the shared NVLink/NVSwitch domain via asynchronous peer-to-peer direct memory access (DMA), completing in under 20 milliseconds without crossing the host network.
Why is LoongServe faster than Prefill-Decoding Disaggregation (DistServe)?
Prefill-Decoding Disaggregation strictly separates hardware into dedicated prefill and decode clusters. When a prefill completes, the entire multi-gigabyte KV cache must be transferred over the datacenter network, introducing hundreds of milliseconds of network transfer lag. Furthermore, fixed instance ratios cause severe idle hardware starvation. LoongServe keeps both phases co-located within high-bandwidth multi-GPU nodes, eliminating network transfer taxes.
What is token-granular memory management?
Traditional serving engines allocate memory in coarse page blocks tied to specific execution instances, which causes memory fragmentation when sequence lengths vary. LoongServe manages KV cache memory at the granularity of single tokens across the entire cluster, allowing any GPU to store tokens for any request without locality constraints and reducing memory fragmentation to below 3%.
Does LoongServe require model retraining or architecture modifications?
No. LoongServe is a completely training-free, drop-in systems optimization. It works directly with standard open-weights model architectures—such as Llama-2, Llama-3, Mistral, and Qwen—without modifying weights or requiring fine-tuning.
Where can I access the LoongServe research paper and source code?
The LoongServe research paper was published at top systems venues (LoongServe: Efficiently Serving Long-Context Large Language Models with Elastic Sequence Parallelism, arXiv:2404.09526). The official open-source code and benchmark artifacts are available on GitHub.
To learn more about scalable data extraction and enterprise AI pipelines, consult our aiFetchly Documentation or review our enterprise aiFetchly Pricing options.