dsr1_dep.sh 4.63 KB
Newer Older
Alec's avatar
Alec committed
1
#!/bin/bash
2
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Alec's avatar
Alec committed
3
4
5
6
7
8
9
10
11
12
# SPDX-License-Identifier: Apache-2.0

set -ex

# Default values
NUM_NODES=""
NODE_RANK=""
GPUS_PER_NODE=""
MASTER_ADDR="localhost"
LOG_DIR="./logs"
13
MODEL="deepseek-ai/DeepSeek-R1"
Alec's avatar
Alec committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

# Parse command line arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        --num-nodes)
            NUM_NODES="$2"
            shift 2
            ;;
        --node-rank)
            NODE_RANK="$2"
            shift 2
            ;;
        --gpus-per-node)
            GPUS_PER_NODE="$2"
            shift 2
            ;;
        --master-addr)
            MASTER_ADDR="$2"
            shift 2
            ;;
        --log-dir)
            LOG_DIR="$2"
            shift 2
            ;;
38
39
40
41
        --model)
            MODEL="$2"
            shift 2
            ;;
Alec's avatar
Alec committed
42
43
44
45
46
47
48
49
        -h|--help)
            echo "Usage: $0 [OPTIONS]"
            echo "Options:"
            echo "  --num-nodes N         Number of nodes in the cluster (required, int)"
            echo "  --node-rank M         Rank of this node (0-based, required, int)"
            echo "  --gpus-per-node L     Number of GPUs per node (required, int)"
            echo "  --master-addr ADDR    Master node address (default: localhost)"
            echo "  --log-dir DIR         Directory for log files (default: ./logs)"
50
51
            echo "  --model MODEL         Model name to use (default: ${MODEL})"
            echo "  -h, --help            Show this help message"
Alec's avatar
Alec committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
            exit 0
            ;;
        *)
            echo "Unknown option: $1"
            echo "Use --help for usage information"
            exit 1
            ;;
    esac
done

# Validate required arguments
if [ -z "$NUM_NODES" ] || [ -z "$NODE_RANK" ] || [ -z "$GPUS_PER_NODE" ]; then
    echo "Error: Missing required arguments"
    echo "Required: --num-nodes, --node-rank, --gpus-per-node"
    echo "Use --help for usage information"
    exit 1
fi

# Calculate data parallel size
DATA_PARALLEL_SIZE=$((NUM_NODES * GPUS_PER_NODE))

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
HTTP_PORT="${DYN_HTTP_PORT:-8000}"
echo "=========================================="
echo "Launching DeepSeek-R1 Data Parallel (Multi-Node)"
echo "=========================================="
echo "Model:       $MODEL"
if [ "$NODE_RANK" -eq 0 ]; then
echo "Frontend:    http://localhost:$HTTP_PORT"
fi
echo "Number of nodes: $NUM_NODES"
echo "Node rank:       $NODE_RANK"
echo "GPUs per node:   $GPUS_PER_NODE"
echo "Data parallel:   $DATA_PARALLEL_SIZE"
echo "Master address:  $MASTER_ADDR"
echo "Log directory:   $LOG_DIR"
echo "=========================================="
if [ "$NODE_RANK" -eq 0 ]; then
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\": \"Explain why Roger Federer is considered one of the greatest tennis players of all time\"}],"
echo "      \"max_tokens\": 32"
echo "    }'"
echo ""
echo "=========================================="
fi
Alec's avatar
Alec committed
102
103
104
105

trap 'echo Cleaning up...; kill 0' EXIT

# run ingress if it's node 0
106
# dynamo.frontend accepts either --http-port flag or DYN_HTTP_PORT env var (defaults to 8000)
Alec's avatar
Alec committed
107
if [ $NODE_RANK -eq 0 ]; then
108
    DYN_LOG=debug python -m dynamo.frontend --router-mode kv 2>&1 | tee $LOG_DIR/dsr1_dep_ingress.log &
Alec's avatar
Alec committed
109
110
111
112
113
114
fi

mkdir -p $LOG_DIR

# Data Parallel Attention / Expert Parallelism
# Routing to DP workers managed by Dynamo
115
116
117
118
# [NOTE] depending on the warmup and KV allocation setting of vLLM,
# the GPU memory requires for vLLM reservation and runtime spike (not
# reserved by vLLM) can be different and cause model fails to start,
# adjust '--gpu-memory-utilization' as needed
Alec's avatar
Alec committed
119
120
121
for ((i=0; i<GPUS_PER_NODE; i++)); do
    dp_rank=$((i + NODE_RANK * GPUS_PER_NODE))
    CUDA_VISIBLE_DEVICES=$i \
122
        VLLM_NIXL_SIDE_CHANNEL_PORT=$((20096 + i)) \
Alec's avatar
Alec committed
123
124
125
        VLLM_ALL2ALL_BACKEND="deepep_low_latency" \
        VLLM_USE_DEEP_GEMM=1 \
        VLLM_RANDOMIZE_DP_DUMMY_INPUTS=1 \
Alec's avatar
Alec committed
126
        python3 -m dynamo.vllm \
127
        --model $MODEL \
Alec's avatar
Alec committed
128
129
130
        --data_parallel_size $DATA_PARALLEL_SIZE \
        --data-parallel-rank $dp_rank \
        --enable-expert-parallel \
131
        --max-model-len 4096 \
Alec's avatar
Alec committed
132
133
        --data-parallel-address $MASTER_ADDR \
        --data-parallel-rpc-port 13345 \
134
        --gpu-memory-utilization 0.91 \
135
136
        --enforce-eager \
        --kv-events-config "{\"publisher\":\"zmq\",\"topic\":\"kv-events\",\"endpoint\":\"tcp://*:$((20080 + i))\",\"enable_kv_cache_events\":true}" 2>&1 | tee $LOG_DIR/dsr1_dep_${dp_rank}.log &
Alec's avatar
Alec committed
137
138
139
140
done

echo "All workers starting. (press Ctrl+C to stop)..."
wait