ToolingFrameworks

vLLM, SGLang or Ray: picking a serving engine

Compare leading LLM inference frameworks including vLLM, SGLang, and Ray Serve. Understand PagedAttention and when to buy managed AI infrastructure.

, AI Researcher8 min read
In this article8
  1. Understanding the LLM inference stack
  2. The autoregressive bottleneck and PagedAttention
  3. Evaluating vLLM for high-throughput serving
  4. Evaluating SGLang for structured generation
  5. Scaling engines with Ray Serve
  6. Self-hosting versus managed dedicated inference
  7. Frequently asked questions
  8. Sources
A row of brightly liveried Cray XE6 supercomputer cabinets at HLRS Stuttgart
Cray XE6 cabinets at HLRS Stuttgart. A serving framework's job is deciding how machines like these are kept busy between requests. Photo: ThE cRaCkEr, CC BY-SA 3.0, via Wikimedia Commons

Understanding the LLM inference stack

Serving large language models in production requires a specialized software layer designed to convert model weights into responsive, high-concurrency API endpoints. As software development and enterprise workflows integrate generative AI, developer speed gains - such as the 25% boost reported by Duolingo engineers adopting GitHub Copilot[1] - have accelerated demand for robust model serving. Raw deep learning frameworks like standard PyTorch cannot meet production demands because they lack the memory management and batching techniques required to handle concurrent token generation efficiently.

Execution engines versus orchestration layers

The inference architecture splits into two primary tiers: low-level execution engines and distributed orchestration platforms. Execution engines operate directly at the device level, compiling model graphs, managing GPU memory structures, and scheduling compute operations across tensor cores. Orchestration systems sit above these engines, handling request routing, replica autoscaling, multi-model pipelines, and distributed cluster coordination.

  • Inference execution engine: Manages key-value memory paging, kernel execution, and continuous request batching on single or multi-GPU instances.
  • Distributed runtime: Coordinates multi-node communication, dynamic worker scaling, and health monitoring across heterogeneous hardware.
  • Application interface layer: Exposes OpenAI-compatible REST and streaming endpoints, enforcing rate limits, token counting, and client authentication.

The primary operational bottleneck in model serving is hardware utilization. Generating text token by token is memory-bandwidth bound rather than compute bound. Without optimized serving runtimes, accelerator memory stalls while waiting for weights and key-value tensors to transfer, leaving expensive silicon underutilized and driving up serving costs.

The autoregressive bottleneck and PagedAttention

Autoregressive transformer inference generates output sequentially, where each new token depends on all preceding tokens in the sequence. During generation, the attention mechanism computes key and value vectors for every token and stores them in high-bandwidth memory (HBM) as the Key-Value (KV) cache. This avoids recomputing representations for earlier tokens, but the cache expands dynamically with every generated step, creating severe memory management challenges.

Virtual memory paging for GPU memory

In legacy serving architectures, memory for the maximum possible sequence length had to be pre-allocated contiguously for each request. This led to internal and external fragmentation: profiling of earlier serving systems found that only 20.4% to 38.2% of the KV cache memory actually held token states, with the rest lost to reservation and fragmentation[2]. The vLLM project addressed this limitation by introducing PagedAttention, an attention algorithm the team describes as inspired by the classic idea of virtual memory and paging in operating systems[3].

  1. Logical block mapping: Dividing the sequence KV cache into fixed-size logical blocks containing key-value vectors for a fixed number of tokens.
  2. Physical page table allocation: Allocating physical memory blocks on demand across non-contiguous GPU memory pages as new tokens generate.
  3. Dynamic block sharing: Enabling parallel sampling and branched generation paths to share common prompt blocks without duplicating tensor data in memory.

By confining memory waste for a request to its last block, PagedAttention brings KV cache waste under 4% in practice and allows batch sizes to scale dynamically, which improved throughput by 2-4x at the same level of latency compared with state-of-the-art systems such as FasterTransformer and Orca[2]. As the vLLM team puts it, that memory efficiency gain allows the system to batch more sequences together, increase GPU utilization and thereby significantly increase throughput[3].

Evaluating vLLM for high-throughput serving

vLLM has established itself as a reference open-source engine for high-throughput LLM serving, described in its own documentation as a fast, easy-to-use library for LLM inference and serving[4]. Maintained under the PyTorch Foundation and backed by industry contributors, the framework focuses on maximizing hardware throughput across open-weight model architectures.

Hardware support and standard interfaces

The engine provides a drop-in OpenAI-compatible API, allowing teams to swap proprietary cloud endpoints for self-hosted instances with minimal configuration adjustments. Its hardware backend support extends beyond standard NVIDIA CUDA environments to diverse accelerator ecosystems[5].

PlatformDriver / Runtime BackendSupported Architectures
NVIDIA GPUsCUDA 13.0 and CUDA 12.9DeepSeek, Llama, Mistral, Qwen, Gemma
AMD GPUsROCm 6.xLlama, Mistral, Qwen, Gemma
Intel HardwareGaudi and Intel XPULlama, Mistral, Qwen
Google CloudTPU RuntimeGemma, Llama, Qwen

For standard chatbot interfaces, summarization workflows, and general generation tasks, vLLM provides a balance of operational stability, active community maintenance, and verifiable throughput on published inference benchmarks.

Evaluating SGLang for structured generation

While vLLM excels at uniform batch generation, complex AI applications require structured outputs, multi-call agent workflows, few-shot prompting, and multimodal inputs. SGLang was built for exactly these patterns: it consists of a frontend language that simplifies programming with primitives for generation and parallelism control, plus a runtime that accelerates execution[6]. The project positions itself as a high-performance serving framework for both LLMs and multimodal models, from a single GPU up to distributed clusters[7].

RadixAttention and constrained decoding

The core innovation of SGLang is RadixAttention, which maintains a radix tree data structure over the KV cache across multiple generation requests. When multiple requests share prefix tokens - such as system prompts, few-shot demonstration examples, or intermediate reasoning history - RadixAttention matches and reuses the existing KV cache blocks automatically without recomputation. In empirical evaluations across agent control, logical reasoning, JSON decoding, retrieval-augmented generation and multi-turn chat, SGLang achieved up to 6.4x higher throughput compared to state-of-the-art inference systems[6].

  • Radix tree KV cache: Automatic LRU eviction and reuse of cached prefix states across divergent request trees.
  • Compressed finite state machine: A runtime optimization for faster structured output decoding, used alongside RadixAttention for KV cache reuse[6].
  • Disaggregated execution: Separation of prefill and decode phases to isolate compute-heavy prompt processing from memory-bound token decoding.

SGLang is particularly suited for agent architectures where recursive prompt structures and structured output schemas would otherwise cause severe latency degradation under standard execution engines.

Scaling engines with Ray Serve

Single-node serving engines provide high single-instance efficiency, but production platforms require multi-node scaling, load balancing, and pipeline composition. Ray Serve, built on the open-source Ray distributed compute engine, provides the distributed orchestration layer needed to manage inference clusters across diverse hardware configurations[8].

Fractional resource allocation and request routing

Ray Serve abstracts Python functions and classes into distributed actors. Resource requirements are declared per replica through ray_actor_options and can be fractional: the documentation's own example gives two models that each fail to saturate a GPU an allocation of 0.5 GPUs apiece so they share the device, while a deployment that needs a full accelerator reserves one GPU per replica[9].

Stack ComponentPrimary RoleScaling BoundaryHardware Allocation
Inference Engine (vLLM / SGLang)Token generation and KV cache managementSingle node or tensor-parallel groupDirect GPU physical memory
Distributed Runtime (Ray Serve)Routing, autoscaling, and pipeline DAGsMulti-node clusterFractional and multi-device allocation
API GatewayAuthentication, rate limiting, and metricsEdge / ingress tierHost CPU and network interface

By embedding low-level engines like vLLM within Ray Serve actors, infrastructure teams build endpoints that scale with demand: the Serve autoscaler reacts to traffic spikes by monitoring queue sizes and making scaling decisions to add or remove replicas, and it asks the underlying Ray autoscaler for additional nodes when the cluster lacks the resources to place them[10]. That keeps heterogeneous data processing and token generation inside a single Python deployment.

Self-hosting versus managed dedicated inference

Engineering teams evaluating inference deployment face a core build-versus-buy decision. Operating self-hosted serving infrastructure on raw GPU instances gives full architectural control but introduces substantial engineering overhead. Teams must handle GPU driver maintenance, continuous engine updates, memory fragmentation tuning, dynamic batch calibration, and multi-node failure recovery, which can complicate total LLM cost per token calculations.

Managed open-source runtimes and sovereign deployment

Managed infrastructure provides an alternative by packaging optimized open-source engines behind managed endpoints.

  • Operational overhead: Self-hosting requires ongoing kernel tuning and cluster maintenance, whereas managed endpoints abstract infrastructure operations.
  • Stack consistency: Managed providers deploy standard open-source engines like vLLM, ensuring API compatibility with standard tooling without vendor lock-in.
  • Jurisdiction and residency: Deploying inference on European infrastructure provides legal certainty under EU privacy regulations compared to foreign hyperscaler regions.

For European organizations with strict compliance requirements, hosting inference infrastructure within a named EU region ensures that enterprise data and prompt tokens remain fully governed by European standards, maintaining verifiable data sovereignty across the entire AI pipeline.

Frequently asked questions

What is an LLM inference framework?

An inference framework is the software layer that executes a large language model and serves its predictions to applications. It manages GPU memory, batches incoming requests, and handles the decoding process. Engines like vLLM focus on memory efficiency, while tools like Ray Serve orchestrate these engines across distributed clusters.

What is the difference between vLLM and SGLang?

vLLM is optimized for general-purpose, high-throughput text generation using PagedAttention to manage memory. SGLang co-designs the frontend and backend to accelerate structured generation, using RadixAttention to reuse the key-value cache across complex workflows, achieving up to 6.4x higher throughput on those specific tasks.

How does PagedAttention improve inference?

PagedAttention resolves memory fragmentation by storing continuous keys and values in non-contiguous memory blocks. This allows the inference engine to dynamically allocate memory per token rather than reserving large contiguous chunks upfront, enabling larger batch sizes and higher hardware utilization.

When should I use Ray Serve for LLM inference?

Ray Serve is necessary when scaling inference beyond a single machine. While vLLM and SGLang handle the actual token generation on the GPU, Ray Serve wraps them to manage API routing, fractional GPU resource allocation, and distributed orchestration across multiple nodes in a large deployment.

Which inference framework supports the most open-source models?

Frameworks like vLLM are designed for universal compatibility and support a vast catalog of open-weight models, including those from DeepSeek, Llama, and Qwen.

Sources

  1. github.com
  2. arxiv.org
  3. blog.vllm.ai
  4. docs.vllm.ai
  5. docs.vllm.ai
  6. arxiv.org
  7. sglang.ai
  8. docs.ray.io
  9. docs.ray.io
  10. docs.ray.io

Rankings and scores on Optinest cannot be bought — no commercial relationship changes how a provider is assessed. How we score

Related reading

All Tooling →