agg_router.sh 3.68 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
#
# Two aggregated workers behind a KV-aware router.
# GPUs: 2
7
8
9
10

# Setup cleanup trap
cleanup() {
    echo "Cleaning up background processes..."
11
12
    kill $DYNAMO_PID $WORKER_PID 2>/dev/null || true
    wait $DYNAMO_PID $WORKER_PID 2>/dev/null || true
13
14
15
16
    echo "Cleanup complete."
}
trap cleanup EXIT INT TERM

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

# Enable tracing if requested
49
TRACE_ARGS=()
50
51
52
53
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}
54
    TRACE_ARGS+=(--enable-trace --otlp-traces-endpoint localhost:4317)
55
fi
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
MODEL="Qwen/Qwen3-0.6B"
HTTP_PORT="${DYN_HTTP_PORT:-8000}"
echo "=========================================="
echo "Launching Aggregated Router (2 workers)"
echo "=========================================="
echo "Model:       $MODEL"
echo "Frontend:    http://localhost:$HTTP_PORT"
echo "=========================================="
echo ""
echo "Example test command:"
echo ""
echo "  curl http://localhost:${HTTP_PORT}/v1/chat/completions \\"
echo "    -H 'Content-Type: application/json' \\"
echo "    -d '{"
echo "      \"model\": \"${MODEL}\","
echo "      \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}],"
echo "      \"max_tokens\": 32"
echo "    }'"
echo ""
echo "=========================================="

78
# run ingress
79
# dynamo.frontend accepts either --http-port flag or DYN_HTTP_PORT env var (defaults to 8000)
80
81
82
83
FRONTEND_ARGS=(--router-mode kv)
if [ "$APPROX_MODE" = true ]; then
    FRONTEND_ARGS+=(--no-kv-events)
fi
84
OTEL_SERVICE_NAME=dynamo-frontend \
85
python3 -m dynamo.frontend "${FRONTEND_ARGS[@]}" &
86
87
88
DYNAMO_PID=$!

# run worker
89
90
91
92
93
94
95
96
# Build KV events args conditionally (only when not in approx mode)
KV_EVENTS_ARGS_1=()
KV_EVENTS_ARGS_2=()
if [ "$APPROX_MODE" = false ]; then
    KV_EVENTS_ARGS_1=(--kv-events-config '{"publisher":"zmq","topic":"kv-events","endpoint":"tcp://*:5557"}')
    KV_EVENTS_ARGS_2=(--kv-events-config '{"publisher":"zmq","topic":"kv-events","endpoint":"tcp://*:5558"}')
fi

97
OTEL_SERVICE_NAME=dynamo-worker-1 DYN_SYSTEM_PORT=${DYN_SYSTEM_PORT_WORKER1:-8081} \
98
python3 -m dynamo.sglang \
99
100
  --model-path Qwen/Qwen3-0.6B \
  --served-model-name Qwen/Qwen3-0.6B \
101
102
103
  --page-size 16 \
  --tp 1 \
  --trust-remote-code \
104
  "${KV_EVENTS_ARGS_1[@]}" \
105
106
  --enable-metrics \
  "${TRACE_ARGS[@]}" &
107
108
WORKER_PID=$!

109
OTEL_SERVICE_NAME=dynamo-worker-2 DYN_SYSTEM_PORT=${DYN_SYSTEM_PORT_WORKER2:-8082} \
110
CUDA_VISIBLE_DEVICES=1 python3 -m dynamo.sglang \
111
112
  --model-path Qwen/Qwen3-0.6B \
  --served-model-name Qwen/Qwen3-0.6B \
113
114
115
  --page-size 16 \
  --tp 1 \
  --trust-remote-code \
116
  "${KV_EVENTS_ARGS_2[@]}" \
117
118
  --enable-metrics \
  "${TRACE_ARGS[@]}"