Llumnix Documentation

repository·main·Indexed 20 days ago

https://github.com/llumnix-project/llumnix-ray

A cross-instance request scheduling layer for LLM inference engines like vLLM. Llumnix optimizes multi-instance serving performance using KV-cache-aware scheduling and migration to reduce latency and increase throughput. This repository contains Llumnix v0, the Ray-based architecture recommended for local deployments and prototyping. Key features include prefill-decode (PD) disaggregation, auto-scaling, and various dispatch policies and migration backends (gloo, rayrpc, nccl, grpc, kvtransfer).

Tokens
11.2K
Snippets
26
Records
46
Agent score
69%

What's inside Llumnix

  1. What is Prefill-decode Disaggregation?

    main

    Prefill-decode (P-D) disaggregation is an experimental technique where the prefill phase (initial prompt processing) and the decode phase (token-by-token generation) are computed on separate instances.

    How it works:

    1. Prefill Phase: Requests are dispatched to dedicated prefill instances.
    2. Migration: Once the prefill phase is complete, the system migrates the generated Key-Value (KV) cache from the prefill instance to a decode instance.
    3. Decode Phase: The decode instance continues the computation.

    Benefits:

    • Reduced Interference: Separates the two phases to optimize resource utilization.
    • Engine Agnostic: Inference engines (like vLLM) do not need to be aware of the P-D distinction; Llumnix handles the scheduling and migration logic.
    • Native Integration: Leverages Llumnix's built-in KV cache transfer and decoupled API server mechanisms.
  2. What is Llumnix and why use it?

    main

    Llumnix is a cross-instance request scheduling layer built on top of LLM inference engines like vLLM. It is designed to optimize multi-instance serving performance through:

    • Low Latency: Reduces Time-to-First-Token (TTFT) and queuing delays via KV-cache-aware scheduling, and reduces Time-Between-Tokens (TBT) and preemption stalls via better load balancing.
    • High Throughput: Integrates with state-of-the-art engines and supports techniques like prefill-decode disaggregation.

    It achieves this using dynamic, fine-grained, KV-cache-aware scheduling and a near-zero overhead KV cache migration mechanism that enables continuous rescheduling across instances for load balancing, de-fragmentation, and disaggregation.

  3. Choose between Llumnix v0 and Llumnix v1

    main

    Llumnix has two architectural versions:

    • Llumnix v1 (New Repository): A refactored, modular, and cloud-native architecture designed for production environments.
    • Llumnix v0 (This Repository): The Ray-based architecture. This version is recommended for local deployments, quick prototyping, and experimentation with scheduling ideas.
  4. How Llumnix handles component failures

    main
    Llumnix is designed for high service availability and can tolerate the failure of any component or instance. While failures may cause temporary degradation in serving throughput or scheduling quality during the failover period, the system is designed to avoid total service downtime. This architecture also supports elasticity, allowing instances to be started or terminated without impacting overall service availability.
  5. Configure Request Migration

    main

    Migration allows moving requests or KV caches between instances to optimize load or defragment memory.

    Key Migration Settings

    • --enable-routine-migration: Enables migrating requests between instances.
    • --enable-engine-migration-interface: Enables the engine migration interface.
    • --enable-defrag: Enables defragmentation via migration based on virtual usage.
    • --pair-migration-policy: Strategy for pair migration. Choices: balanced, defrag (Default: defrag).
    • --request-migration-policy: Policy for request migration. Choices: LCR, SR, LR, FCW, FCWSR (Default: SR).
    • --migrate-out-threshold: Load threshold that triggers a migration out (Default: 3.0).
    • --max-migration-concurrency: Maximum number of concurrent migrations (Default: 1).

    Migration Backend

    Use --migration-backend to specify the communication protocol:

    • gloo, rayrpc, nccl: Available for vLLM.
    • grpc, kvtransfer: Available for BladeLLM.
    • Default: gloo

    KVTransfer Specifics:

    • --kvtransfer-migration-backend-transfer-type: Choices: ipc, rdma (Default: rdma).
    • --kvtransfer-migration-backend-naming-url: URL for the naming server (Default: file:/tmp/llumnix/naming/).
  6. Fault tolerance limitations for Ray Head

    main

    Llumnix currently has limited support for Ray head fault-tolerance.

    • Impact on running services: If the Ray head fails, existing Llumnix actors that are already alive will continue to run, meaning current service availability is not immediately impacted.
    • Impact on scaling/recovery: During a Ray head failure, Llumnix cannot create or restart any new actors.

    Future versions aim to incorporate Ray's high-availability mechanisms to enable full Ray failover.

  7. Configure Prefill-Decode (PD) Disaggregation

    main

    Llumnix supports disaggregating prefill and decode workloads to improve efficiency.

    Disaggregation Modes

    • --enable-pd-disagg: Enables prefill-decode disaggregation for vLLM.
    • --enable-vllm-v1-engine-pd-disagg: Enables engine-based PD disaggregation for vLLM-V1.
    • --enable-bladellm-engine-pd-disagg: Enables engine-based PD disaggregation for BladeLLM.
    • --enable-adaptive-pd: [Experimental] Enables adaptive prefill-decode disaggregation.

    Configuration

    • --pd-ratio: The P:D ratio used in global launch mode (e.g., 1:1).
    • --instance-type: Defines the role of the engine instance. Choices: prefill, decode, neutral.
  8. Configure Request Dispatching and Load Metrics

    main

    Llumnix allows you to control how requests are distributed across instances using different policies and load metrics.

    Dispatch Policies

    Use --dispatch-policy to select a strategy:

    • balanced: Balanced distribution.
    • load: Based on current load.
    • queue: Based on queue length.
    • rr: Round Robin.
    • Default: load

    Load Metrics

    Many components (dispatch, migration, scaling) use load metrics to make decisions. Available metrics include:

    • remaining_steps: Based on remaining computation steps.
    • kv_blocks_ratio: Based on the ratio of KV cache blocks used.

    Specific Metric Arguments:

    • --dispatch-load-metric: Metric for general instance dispatch (Default: remaining_steps).
    • --dispatch-prefill-load-metric: Metric for prefill instances in PD disaggregation (Default: kv_blocks_ratio).
    • --dispatch-decode-load-metric: Metric for decode instances in PD disaggregation (Default: remaining_steps).
    • --migration-load-metric: Metric for triggering migrations (Default: remaining_steps).
    • --scaling-load-metric: Metric for triggering auto-scaling (Default: remaining_steps).
  9. Manage Ray Cluster lifecycle in Llumnix

    main

    When deploying Llumnix, you can control how the Ray cluster is managed using the --launch-ray-cluster flag:

    • Automatic Creation: Including --launch-ray-cluster tells Llumnix to automatically build a Ray cluster during deployment. Warning: This will overwrite any existing Ray cluster.
    • Existing Cluster: To run Llumnix components within a pre-existing Ray cluster without overwriting it, simply omit the --launch-ray-cluster option.
  10. Fault tolerance behavior for Ray Actors

    main

    Internal Llumnix components are launched as Ray actors. If an actor fails, Ray automatically restarts it. The impact of these failures depends on the specific component:

    • API server: If an API server fails, all requests associated with it are aborted. This includes requests that might be running on other instances not co-located with the failed server.
    • Scheduler: If the scheduler fails, Llumnix enters a scheduler-bypassing mode. In this mode, API servers use simplified internal scheduling logic to maintain service.
    • Instance (llumlet / backend): If an instance (such as a llumlet or a backend engine) fails, all requests currently running on that instance are aborted. This also affects requests dispatched from other API servers that were targeting that specific instance.
  11. Install Llumnix from PyPI or Source

    main

    Requirements

    Llumnix requires Python 3.9~3.10 and is built on top of vLLM (version 0.6.3.post1).

    Install from PyPI

    You can install the package directly using pip:

    pip install llumnix

    Build from Source

    To build and install from the repository:

    git clone https://github.com/AlibabaPAI/llumnix.git
    cd llumnix
    make vllm_install

    Migration Backend Installation

    • rayrpc (Default): No additional steps required.
    • NCCL: Run make cupy-cuda to install cupy-cuda (ensure it matches your CUDA version).
    • Gloo:
      1. Install Bazel >= 5.1.0.
      2. Install cupy-cuda.
      3. Run make pygloo to install pygloo.

    Note: Using conda is not recommended as it may fail to handle pygloo's dependency on gcc libstdc++.so.6: version GLIBCXX_3.4.30.