# Disaggregated Serving The execution method of disaggregated serving relies on the `trtllm-serve` command. Specifically, compared to the standard usage of `trtllm-serve`, serving requires running this command multiple times to separately start the router and workers (including context and generation) serving components. This document focuses on this approach and provides a detailed guide on how to use it. Please note that disaggregated serving is currently an experimental feature, so the usage described in this document may change in the future. ## Startup Procedure ### Configuration File The `trtllm-serve` command supports the `extra-llm-config.yaml` parameter. In the extra LLM configuration file, the `cache_transceiver_config` field is specifically used for disaggregated service. It is mainly used to specify additional parameters required for the KV cache transmission process. ```yaml cache_transceiver_config: # KV cache transmission backend. Valid options include `DEFAULT` (i.e., NIXL), `UCX`, `NIXL`. backend: # KV cache buffer size. Set it ≥ the maximum ISL (Input Sequence Length) for best performance. max_tokens_in_buffer: # KV cache transfer timeout in milliseconds # For requests, if they do not send/receive the KV cache in time they are cancelled and cleaned up kv_transfer_timeout_ms: ``` The following is an example, consisting of the `ctx_extra-llm-api-config.yaml` and `gen_extra-llm-api-config.yaml` files needed in the sections below. ```yaml # ctx_extra-llm-api-config.yaml # The overlap scheduler for context servers is currently disabled, as it is # not yet supported in disaggregated context server architectures. disable_overlap_scheduler: True cache_transceiver_config: backend: UCX max_tokens_in_buffer: 2048 ``` ```yaml # gen_extra-llm-api-config.yaml cache_transceiver_config: backend: UCX max_tokens_in_buffer: 2048 ``` ### Basic Usage For non-SLURM clusters - particularly in single-node, multi-GPU setups, it is recommended to use standard mode. In such cases, the system does not enforce limits on process creation or termination. Suppose we have three CUDA devices on the same machine. The first two devices are used to launch one context model each, and the third device is used to launch one generation model. In this case, the following commands need to be executed. ```bash # Start context servers CUDA_VISIBLE_DEVICES=0 trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0 \ --host localhost --port 8001 \ --extra_llm_api_options ./ctx_extra-llm-api-config.yaml &> log_ctx_0 & CUDA_VISIBLE_DEVICES=1 trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0 \ --host localhost --port 8002 \ --extra_llm_api_options ./ctx_extra-llm-api-config.yaml &> log_ctx_1 & # Start generation server CUDA_VISIBLE_DEVICES=2 trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0 \ --host localhost --port 8003 \ --extra_llm_api_options ./gen_extra-llm-api-config.yaml &> log_gen_0 & ``` Once the context and generation servers are launched, you can launch the disaggregated server, which will accept requests from clients and do the orchestration between context and generation servers. The disaggregated server can be launched with: ```bash # Start proxy trtllm-serve disaggregated -c disagg_config.yaml ``` where `disagg_config.yaml` contains information about the context and generation servers. For the current example, it would look like: ```yaml # disagg_config.yaml hostname: localhost port: 8000 backend: pytorch context_servers: num_instances: 2 urls: - "localhost:8001" - "localhost:8002" generation_servers: num_instances: 1 urls: - "localhost:8003" ``` Clients can then send requests to the disaggregated server at `localhost:8000`, which is an OpenAI API compatible endpoint. #### Sending requests to the disaggregated server Once the context, generation and disaggregated servers are launched, you can send requests to the disaggregated server using curl: ```bash curl http://localhost:8000/v1/completions \ -H "Content-Type: application/json" \ -d '{ "model": "TinyLlama/TinyLlama-1.1B-Chat-v1.0", "prompt": "NVIDIA is a great company because", "max_tokens": 16, "temperature": 0 }' -w "\n" ``` Or using the provided client parsing the prompts from a file and sending request to the disaggregated server specified in the `disagg_config.yaml` file at the `chat` endpoint: ``` python3 ./clients/disagg_client.py -c disagg_config.yaml -p ./clients/prompts.json -e chat ``` ### Launching disaggregated servers on SLURM clusters To simplify usage, TensorRT-LLM internally relies on MPI spawning processes. However, some clusters do not offer such process flexibility. In these cases, we provide the `trtllm-llmapi-launch` tool to launch all processes at once. Therefore, when using TensorRT-LLM on a Slurm cluster, please refer to the following method. #### Single-Node Execution After starting the node and entering interactive mode, you can run the following command to prevent process spawning. ```bash # Start context servers CUDA_VISIBLE_DEVICES=0 trtllm-llmapi-launch trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0 \ --host localhost --port 8001 \ --extra_llm_api_options ./ctx_extra-llm-api-config.yaml &> log_ctx_0 & CUDA_VISIBLE_DEVICES=1 trtllm-llmapi-launch trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0 \ --host localhost --port 8002 \ --extra_llm_api_options ./ctx_extra-llm-api-config.yaml &> log_ctx_1 & # Start generation server CUDA_VISIBLE_DEVICES=2 trtllm-llmapi-launch trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0 \ --host localhost --port 8003 \ --extra_llm_api_options ./gen_extra-llm-api-config.yaml &> log_gen_0 & # Start proxy trtllm-llmapi-launch trtllm-serve disaggregated -c disagg_config.yaml ``` #### Multi-Node Execution If the model you are running cannot fit within a single node and requires multiple nodes, we introduce the startup method using [srun](https://slurm.schedmd.com/srun.html) to run parallel jobs. ```bash srun -A -p -t