disagg_same_gpu.sh 3.79 KB
Newer Older
1
#!/bin/bash
2
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
4
# SPDX-License-Identifier: Apache-2.0
#
5
# Disaggregated prefill/decode on a SINGLE GPU.
6
# Per-worker VRAM is controlled via build_vllm_gpu_mem_args (see gpu_utils.sh).
7
# Override individual knobs (MAX_MODEL_LEN, MAX_CONCURRENT_SEQS) via env vars.
8
9
10
11
12
13
14
#
# Measured reference (Qwen/Qwen3-0.6B, --max-model-len 4096, RTX 6000 Ada 48 GiB):
#   estimate (from gpu_utils.sh) : ~4.0 GiB per worker (~8.0 GiB total)
#   actual (nvidia-smi)          : ~3.4 GiB per worker (~6.7 GiB total)
#   fraction per worker (for 48 GiB) : 0.09
#   The ~1.3 GiB pad comes from the overhead term (CUDA ctx + activations).
#   Overestimating is intentional -- better to pad than OOM.
15

16
17
18
set -e
trap 'echo Cleaning up...; kill 0' EXIT

19
20
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
source "$SCRIPT_DIR/../../../common/gpu_utils.sh"
21

22
MODEL="Qwen/Qwen3-0.6B"
23

24
25
26
# ---- Tunable (override via env vars) ----
MAX_MODEL_LEN="${MAX_MODEL_LEN:-4096}"
MAX_CONCURRENT_SEQS="${MAX_CONCURRENT_SEQS:-2}"
27
28
29
30
31
32
33
34
35
# Inherit GPU from parent (profiler/test harness sets CUDA_VISIBLE_DEVICES);
# default to GPU 0 for standalone use.
CUDA_VISIBLE_DEVICES="${CUDA_VISIBLE_DEVICES:-0}"
# Per-worker KV cache byte cap (deterministic, GPU-size independent).
# Profiled safe value: 1_023_525_000 bytes (~976 MiB, 2x over min 512 MiB).
# --gpu-memory-utilization 0.01 prevents vLLM's startup free-memory check from
# rejecting the launch when a co-resident worker already holds VRAM.
# The profiler/parallel runner overrides via _PROFILE_OVERRIDE_VLLM_KV_CACHE_BYTES.
DEFAULT_KV_CACHE_BYTES="${DEFAULT_KV_CACHE_BYTES:-1023525000}"
36

37
GPU_MEM_ARGS=$(build_vllm_gpu_mem_args)
38
39
40
if [[ -z "$GPU_MEM_ARGS" ]]; then
    GPU_MEM_ARGS="--kv-cache-memory-bytes $DEFAULT_KV_CACHE_BYTES --gpu-memory-utilization 0.01"
fi
41

42
source "$SCRIPT_DIR/../../../common/launch_utils.sh"
43

44
HTTP_PORT="${DYN_HTTP_PORT:-8000}"
45
print_launch_banner "Launching Disaggregated on Same GPU (1 GPU)" "$MODEL" "$HTTP_PORT" \
46
    "Workers:     2 (prefill + decode, fraction is per worker)"
47

48
# run ingress
49
50
# dynamo.frontend accepts either --http-port flag or DYN_HTTP_PORT env var (defaults to 8000)
python3 -m dynamo.frontend &
51
52
53

# run decode worker with metrics on port 8081
# --enforce-eager is added for quick deployment. for production use, need to remove this flag
54
55
# For disaggregated deployments we standardize on DYN_SYSTEM_PORT1/2 instead of
# *_PREFILL/*_DECODE env names so test harnesses can set one simple pair.
56
CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES \
57
DYN_SYSTEM_PORT=${DYN_SYSTEM_PORT1:-8081} \
58
python3 -m dynamo.vllm \
59
  --model "$MODEL" \
60
  --enforce-eager \
61
  --disaggregation-mode decode \
62
  --kv-transfer-config '{"kv_connector":"NixlConnector","kv_role":"kv_both"}' \
63
  $GPU_MEM_ARGS \
64
  --max-model-len "$MAX_MODEL_LEN" &
65

66
67
68
69
70
71
# Wait for decode worker to initialize before starting prefill worker.
# Both workers share one GPU; without this wait they compete for GPU memory
# during model loading and the scheduler OOMs.
# || true: don't let set -e kill the script on timeout (wait_for_ready returns 1).
DECODE_SYSTEM_PORT="${DYN_SYSTEM_PORT1:-8081}"
wait_for_ready "http://localhost:${DECODE_SYSTEM_PORT}/health" 45 || true
72

73
# run prefill worker with metrics on port 8082
74
CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES \
75
DYN_SYSTEM_PORT=${DYN_SYSTEM_PORT2:-8082} \
76
77
VLLM_NIXL_SIDE_CHANNEL_PORT=20097 \
python3 -m dynamo.vllm \
78
  --model "$MODEL" \
79
  --enforce-eager \
80
  --disaggregation-mode prefill \
81
  --kv-transfer-config '{"kv_connector":"NixlConnector","kv_role":"kv_both"}' \
82
  $GPU_MEM_ARGS \
83
  --max-model-len "$MAX_MODEL_LEN" \
84
85
86
87
  --kv-events-config '{"publisher":"zmq","topic":"kv-events","endpoint":"tcp://*:20081","enable_kv_cache_events":true}' &

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