-
Notifications
You must be signed in to change notification settings - Fork 7k
[docs][serve][llm] Add comprehensive architecture documentation for Ray Serve LLM #57830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kouroshHakha
merged 38 commits into
ray-project:master
from
kouroshHakha:kh/llm-docs-phase-2
Oct 20, 2025
Merged
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
97abd27
[docs] Convert serve/llm/quick-start.rst to MyST Markdown
kouroshHakha 5b02921
[docs] Phase 1: Create LLM docs directory structure
kouroshHakha 0e0ee93
[docs] Add examples.md for LLM documentation
kouroshHakha 90821cb
[docs] Add troubleshooting.md with FAQs
kouroshHakha 32aa562
[docs] Add multi-lora user guide
kouroshHakha 34a4e2e
[docs] Remove Multi-LoRA section from quick-start
kouroshHakha 00c950a
[docs] Add routing policy documentation
kouroshHakha 4e69405
[docs] Add navigation structure for LLM docs
kouroshHakha e8aabdb
[docs] Apply Ray docs style and rename routing images
kouroshHakha 5400efc
[docs] Remove old prefix-aware-request-router.md
kouroshHakha 7f831dd
[docs] Add prefill/decode disaggregation user guide
kouroshHakha 869f476
[docs] Add vLLM compatibility user guide
kouroshHakha 31bad71
wip
kouroshHakha 27b3c60
[docs] Add model loading user guide
kouroshHakha ccfd38e
[docs] Remove extracted content from quick-start
kouroshHakha 7d09a33
wip
kouroshHakha f408ba7
wip
kouroshHakha 5942202
[docs] Clean up .gitkeep files and remove empty api/ directory
kouroshHakha 0be378e
wip
kouroshHakha 9c21149
Merge branch 'master' into kh/llm-docs-phase-1
kouroshHakha 1202fa7
[docs] Add architecture overview and core components documentation
kouroshHakha dc543ee
[docs] Add prefill-decode architecture and images
kouroshHakha 9cc37a7
[docs] Apply Ray style guide to prefill-decode architecture
kouroshHakha 583782c
[docs] Update data-parallel architecture for MoE models
kouroshHakha 982c046
[docs] Apply Ray style guide to data-parallel and DeepSeek-V3
kouroshHakha 2a04e40
[docs] Add observability guide and refine documentation overview
kouroshHakha 881de7f
Merge branch 'kh/llm-docs-phase-1' into kh/llm-docs-phase-2
kouroshHakha 31f4ea7
Apply suggestions from code review
kouroshHakha c622ec6
Apply suggestions from code review
kouroshHakha 6c35085
fix comments
kouroshHakha 0f8aa88
Merge branch 'kh/llm-docs-phase-1' into kh/llm-docs-phase-2
kouroshHakha ebf5a16
Merge branch 'master' into kh/llm-docs-phase-2
kouroshHakha aa02ac0
Remove references to DeepSeek-V3 pattern from documentation and delet…
kouroshHakha 3791b96
Wip
kouroshHakha c0d36b4
Wip
kouroshHakha dbab715
wip
kouroshHakha 9e8bf55
some clarifications
kouroshHakha 2a473c5
wip
kouroshHakha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| # Architecture | ||
|
|
||
| Technical details and design documentation for Ray Serve LLM. | ||
| Technical documentation for Ray Serve LLM architecture, components, and patterns. | ||
|
|
||
| ```{toctree} | ||
| :maxdepth: 1 | ||
|
|
||
| Architecture overview <overview> | ||
| Core components <core> | ||
| Serving patterns <serving-patterns/index> | ||
| Request routing <routing-policies> | ||
| ``` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| (serve-llm-architecture-overview)= | ||
| # Architecture overview | ||
|
|
||
| Ray Serve LLM is a framework that specializes Ray Serve primitives for distributed LLM serving workloads. This guide explains the core components, serving patterns, and routing policies that enable scalable and efficient LLM inference. | ||
|
|
||
| ## What Ray Serve LLM provides | ||
|
|
||
| Ray Serve LLM takes the performance of a single inference engine (such as vLLM) and extends it to support: | ||
|
|
||
| - **Horizontal scaling**: Replicate inference across multiple GPUs on the same node or across nodes. | ||
| - **Advanced distributed strategies**: Coordinate multiple engine instances for prefill-decode disaggregation, data parallelism, and expert parallelism. | ||
| - **Modular deployment**: Separate infrastructure logic from application logic for clean, maintainable deployments. | ||
|
|
||
| Ray Serve LLM excels at highly distributed multi-node inference workloads where the unit of scale spans multiple nodes: | ||
|
|
||
| - **Pipeline parallelism across nodes**: Serve large models that don't fit on a single node. | ||
| - **Disaggregated prefill and decode**: Scale prefill and decode phases independently for better resource utilization. | ||
| - **Cluster-wide parallelism**: Combine data parallelism with expert parallelism for serving large-scale sparse MoE architectures such as Deepseek-v3, GPT OSS, etc. | ||
|
|
||
|
|
||
| ## Ray Serve primitives | ||
|
|
||
| Before diving into the architecture, you should understand these Ray Serve primitives: | ||
|
|
||
| - **Deployment**: A class that defines the unit of scale. | ||
| - **Replica**: An instance of a deployment which corresponds to a Ray actor. Multiple replicas can be distributed across a cluster. | ||
| - **Deployment handle**: An object that allows one replica to call into replicas of other deployments. | ||
|
|
||
| For more details, see the {ref}`Ray Serve core concepts <serve-key-concepts>`. | ||
|
|
||
| ## Core components | ||
|
|
||
| Ray Serve LLM provides two primary components that work together to serve LLM workloads: | ||
|
|
||
| ### LLMServer | ||
|
|
||
| `LLMServer` is a Ray Serve _deployment_ that manages a single inference engine instance. _Replicas_ of this _deployment_ can operate in three modes: | ||
|
|
||
| - **Isolated**: Each _replica_ handles requests independently (horizontal scaling). | ||
| - **Coordinated within deployment**: Multiple _replicas_ work together (data parallelism). | ||
| - **Coordinated across deployments**: Replicas coordinate with different deployments (prefill-decode disaggregation). | ||
|
|
||
|
|
||
| The following example demonstrates the sketch of how to use `LLMServer` standalone: | ||
|
|
||
| ```python | ||
| from ray import serve | ||
| from ray.serve.llm import LLMConfig | ||
| from ray.serve.llm.deployment import LLMServer | ||
|
|
||
| llm_config = LLMConfig(...) | ||
|
|
||
| # Get deployment options (placement groups, etc.) | ||
| serve_options = LLMServer.get_deployment_options(llm_config) | ||
|
|
||
| # Decorate with serve options | ||
| server_cls = serve.deployment(LLMServer).options( | ||
| stream=True, **serve_options) | ||
|
|
||
| # Bind the decorated class to its constructor parameters | ||
| server_app = server_cls.bind(llm_config) | ||
|
|
||
| # Run the application | ||
| serve_handle = serve.run(server_app) | ||
|
|
||
| # Use the deployment handle | ||
| result = serve_handle.chat.remote(request=...).result() | ||
| ``` | ||
|
|
||
| #### Physical placement | ||
|
|
||
| `LLMServer` controls physical placement of its constituent actors through placement groups. By default, it uses: | ||
|
|
||
| - `{CPU: 1}` for the replica actor itself (no GPU resources). | ||
| - `world_size` number of `{GPU: 1}` bundles for the GPU workers. | ||
|
|
||
| The `world_size` is computed as `tensor_parallel_size × pipeline_parallel_size`. The vLLM engine allocates TP and PP ranks based on bundle proximity, prioritizing TP ranks on the same node. | ||
|
|
||
| The PACK strategy tries to place all resources on a single node, but provisions different nodes when necessary. This works well for most deployments, though heterogeneous model deployments might occasionally run TP across nodes. | ||
|
|
||
| ```{figure} ../images/placement.png | ||
| --- | ||
| width: 600px | ||
| name: placement | ||
| --- | ||
| Physical placement strategy for GPU workers | ||
| ``` | ||
|
|
||
| #### Engine management | ||
|
|
||
| When `LLMServer` starts, it: | ||
|
|
||
| 1. Creates a vLLM engine client. | ||
| 2. Spawns a background process that uses Ray's distributed executor backend. | ||
| 3. Uses the parent actor's placement group to instantiate child GPU worker actors. | ||
| 4. Executes the model's forward pass on these GPU workers. | ||
|
|
||
| ```{figure} ../images/llmserver.png | ||
| --- | ||
| width: 600px | ||
| name: llmserver | ||
| --- | ||
| Illustration of `LLMServer` managing vLLM engine instance. | ||
| ``` | ||
|
|
||
| ### OpenAiIngress | ||
|
|
||
| `OpenAiIngress` provides an OpenAI-compatible FastAPI ingress that routes traffic to the appropriate model. It handles: | ||
|
|
||
| - **Standard endpoint definitions**: `/v1/chat/completions`, `/v1/completions`, `/v1/embeddings`, etc. | ||
| - **Request routing logic**: The execution of custom router logic (for example, prefix-aware or session-aware routing). | ||
| - **Model multiplexing**: LoRA adapter management and routing. | ||
|
|
||
| The following example shows a complete deployment with `OpenAiIngress`: | ||
|
|
||
| ```python | ||
| from ray import serve | ||
| from ray.serve.llm import LLMConfig | ||
| from ray.serve.llm.deployment import LLMServer | ||
| from ray.serve.llm.ingress import OpenAiIngress, make_fastapi_ingress | ||
|
|
||
| llm_config = LLMConfig(...) | ||
|
|
||
| # Construct the LLMServer deployment | ||
| serve_options = LLMServer.get_deployment_options(llm_config) | ||
| server_cls = serve.deployment(LLMServer).options(**serve_options) | ||
| llm_server = server_cls.bind(llm_config) | ||
|
|
||
| # Get ingress default options | ||
| ingress_options = OpenAiIngress.get_deployment_options([llm_config]) | ||
|
|
||
| # Decorate with FastAPI app | ||
| ingress_cls = make_fastapi_ingress(OpenAiIngress) | ||
|
|
||
| # Make it a serve deployment with the right options | ||
| ingress_cls = serve.deployment(ingress_cls, **ingress_options) | ||
|
|
||
| # Bind with llm_server deployment handle | ||
| ingress_app = ingress_cls.bind([llm_server]) | ||
|
|
||
| # Run the application | ||
| serve.run(ingress_app) | ||
| ``` | ||
|
|
||
| :::{note} | ||
| You can create your own ingress deployments and connect them to existing LLMServer deployments. This is useful when you want to customize request tracing, authentication layers, etc. | ||
| ::: | ||
|
|
||
| #### Network topology and RPC patterns | ||
|
|
||
| When the ingress makes an RPC call to `LLMServer` through the deployment handle, it can reach any replica across any node. However, the default request router prioritizes replicas on the same node to minimize cross-node RPC overhead, which is insignificant in LLM serving applications (only a few milliseconds impact on TTFT at high concurrency). | ||
|
|
||
| The following figure illustrates the data flow: | ||
|
|
||
| ```{figure} ../images/llmserver-ingress-rpc.png | ||
| --- | ||
| width: 600px | ||
| name: llmserver-ingress-rpc | ||
| --- | ||
| Request routing from ingress to LLMServer replicas. Solid lines represent preferred local RPC calls; dashed lines represent potential cross-node RPC calls when local replicas are busy. | ||
| ``` | ||
|
|
||
| #### Scaling considerations | ||
|
|
||
| **Ingress-to-LLMServer ratio**: The ingress event loop can become the bottleneck at high concurrency. In such situations, upscaling the number of ingress replicas can mitigate CPU contention. We recommend keeping at least a 2:1 ratio between the number of ingress replicas and LLMServer replicas. This architecture allows the system to dynamically scale the component that is the bottleneck. | ||
|
|
||
| **Autoscaling coordination**: To maintain proper ratios during autoscaling, configure `target_ongoing_requests` proportionally: | ||
|
|
||
| - Profile your vLLM configuration to find the maximum concurrent requests (for example, 64 requests). | ||
| - Choose an ingress-to-LLMServer ratio (for example, 2:1). | ||
| - Set LLMServer's `target_ongoing_requests` to say 75% of max capacity (for example, 48). | ||
kouroshHakha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Set ingress's `target_ongoing_requests` to maintain the ratio (for example, 24). | ||
|
|
||
| ## Architecture patterns | ||
|
|
||
| Ray Serve LLM supports several deployment patterns for different scaling scenarios: | ||
|
|
||
| ### Data parallel pattern | ||
|
|
||
| Create multiple inference engine instances that process requests in parallel while coordinating across expert layers. Useful for serving sparse MoE models for high-throughput workloads. | ||
|
|
||
| **When to use**: High request volume, kv-cache limited, need to maximize throughput. | ||
kouroshHakha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| See: {doc}`serving-patterns/data-parallel` | ||
|
|
||
| ### Prefill-decode disaggregation | ||
|
|
||
| Separate prefill and decode phases to optimize resource utilization and scale each phase independently. | ||
|
|
||
| **When to use**: Prefill-heavy workloads where there's tension between prefill and decode, cost optimization with different GPU types. | ||
|
|
||
| See: {doc}`serving-patterns/prefill-decode` | ||
|
|
||
| ### Custom request routing | ||
|
|
||
| Implement custom routing logic for specific optimization goals such as cache locality or session affinity. | ||
|
|
||
| **When to use**: Workloads with repeated prompts, session-based interactions, or specific routing requirements. | ||
|
|
||
| See: {doc}`routing-policies` | ||
|
|
||
| ## Design principles | ||
|
|
||
| Ray Serve LLM follows these key design principles: | ||
|
|
||
| 1. **Engine-agnostic**: Support multiple inference engines (vLLM, SGLang, etc.) through the `LLMEngine` protocol. | ||
| 2. **Composable patterns**: Combine serving patterns (data parallel, prefill-decode, custom routing) for complex deployments. | ||
| 3. **Builder pattern**: Use builders to construct complex deployment graphs declaratively. | ||
| 4. **Separation of concerns**: Keep infrastructure logic (placement, scaling) separate from application logic (routing, processing). | ||
| 5. **Protocol-based extensibility**: Define clear protocols for engines, servers, and ingress to enable custom implementations. | ||
|
|
||
| ## See also | ||
|
|
||
| - {doc}`core` - Technical implementation details and extension points | ||
| - {doc}`serving-patterns/index` - Detailed serving pattern documentation | ||
| - {doc}`routing-policies` - Request routing architecture and patterns | ||
| - {doc}`../user-guides/index` - Practical deployment guides | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.