disagg.sh 3.62 KB
Newer Older
1
#!/bin/bash
2
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
# SPDX-License-Identifier: Apache-2.0
4
5
6
#
# Disaggregated serving: prefill on GPU 0, decode on GPU 1.
# GPUs: 2
7

8
9
10
11
set -e
trap 'echo Cleaning up...; kill 0' EXIT

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
12
source "$SCRIPT_DIR/../../../common/gpu_utils.sh"   # build_sglang_gpu_mem_args
13
source "$SCRIPT_DIR/../../../common/launch_utils.sh" # print_launch_banner, wait_any_exit
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Parse command line arguments
ENABLE_OTEL=false
while [[ $# -gt 0 ]]; do
    case $1 in
        --enable-otel)
            ENABLE_OTEL=true
            shift
            ;;
        -h|--help)
            echo "Usage: $0 [OPTIONS]"
            echo "Options:"
            echo "  --enable-otel        Enable OpenTelemetry tracing"
            echo "  -h, --help           Show this help message"
            echo ""
            echo "Note: System metrics are enabled by default on ports 8081 (prefill), 8082 (decode)"
            exit 0
            ;;
        *)
            echo "Unknown option: $1"
            echo "Use --help for usage information"
            exit 1
            ;;
    esac
done

# Enable tracing if requested
41
TRACE_ARGS=()
42
43
44
45
if [ "$ENABLE_OTEL" = true ]; then
    export DYN_LOGGING_JSONL=true
    export OTEL_EXPORT_ENABLED=1
    export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-http://localhost:4317}
46
    TRACE_ARGS+=(--enable-trace --otlp-traces-endpoint localhost:4317)
47
fi
48

49
MODEL="Qwen/Qwen3-0.6B"
50

51
GPU_MEM_ARGS=$(build_sglang_gpu_mem_args)
52
53

DISAGG_BOOTSTRAP_PORT="${DYN_DISAGG_BOOTSTRAP_PORT:-12345}"
54

55
HTTP_PORT="${DYN_HTTP_PORT:-8000}"
56
print_launch_banner "Launching Disaggregated Serving (2 GPUs)" "$MODEL" "$HTTP_PORT"
57

58
# run ingress
59
# dynamo.frontend accepts either --http-port flag or DYN_HTTP_PORT env var (defaults to 8000)
60
OTEL_SERVICE_NAME=dynamo-frontend \
61
python3 -m dynamo.frontend &
62

63
64
#AssertionError: Prefill round robin balance is required when dp size > 1. Please make sure that the prefill instance is launched with `--load-balance-method round_robin` and `--prefill-round-robin-balance` is set for decode server.

65
# run prefill worker
66
67
68
# NOTE: Each worker picks a random NCCL port (get_free_port) for torch.distributed.
# This has a TOCTOU race — the port can be grabbed before init_process_group binds it,
# causing sporadic EADDRINUSE.  Pass --nccl-port <unique_port> per worker to avoid this.
69
70
71
# Use DYN_SYSTEM_PORT1/2 instead of *_PREFILL/*_DECODE env names so test
# harnesses can set one simple pair for disaggregated deployments.
OTEL_SERVICE_NAME=dynamo-worker-prefill DYN_SYSTEM_PORT=${DYN_SYSTEM_PORT1:-8081} \
72
python3 -m dynamo.sglang \
73
74
  --model-path "$MODEL" \
  --served-model-name "$MODEL" \
75
  --page-size 16 \
76
  --tp 1 \
77
78
  --trust-remote-code \
  --disaggregation-mode prefill \
79
  --disaggregation-bootstrap-port "$DISAGG_BOOTSTRAP_PORT" \
80
  --host 0.0.0.0 \
81
  --port 40000 \
82
  --disaggregation-transfer-backend nixl \
83
  --enable-metrics \
84
  --disable-piecewise-cuda-graph \
85
  $GPU_MEM_ARGS \
86
  "${TRACE_ARGS[@]}" &
87
88

# run decode worker
89
OTEL_SERVICE_NAME=dynamo-worker-decode DYN_SYSTEM_PORT=${DYN_SYSTEM_PORT2:-8082} \
90
CUDA_VISIBLE_DEVICES=1 python3 -m dynamo.sglang \
91
92
  --model-path "$MODEL" \
  --served-model-name "$MODEL" \
93
  --page-size 16 \
94
  --tp 1 \
95
96
  --trust-remote-code \
  --disaggregation-mode decode \
97
  --disaggregation-bootstrap-port "$DISAGG_BOOTSTRAP_PORT" \
98
  --host 0.0.0.0 \
99
  --disaggregation-transfer-backend nixl \
100
  --enable-metrics \
101
  --disable-piecewise-cuda-graph \
102
  $GPU_MEM_ARGS \
103
104
105
106
  "${TRACE_ARGS[@]}" &

# Exit on first worker failure; kill 0 in the EXIT trap tears down the rest
wait_any_exit