agg.sh 3.15 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
6
7
8
set -e
trap 'echo Cleaning up...; kill 0' EXIT

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
9
10
source "$SCRIPT_DIR/../../../common/gpu_utils.sh"   # build_trtllm_override_args_with_mem
source "$SCRIPT_DIR/../../../common/launch_utils.sh" # print_launch_banner, wait_any_exit
11

12
# Environment variables with defaults
13
export DYNAMO_HOME=${DYNAMO_HOME:-"/workspace"}
14
15
export MODEL_PATH=${MODEL_PATH:-"Qwen/Qwen3-0.6B"}
export SERVED_MODEL_NAME=${SERVED_MODEL_NAME:-"Qwen/Qwen3-0.6B"}
16
export AGG_ENGINE_ARGS=${AGG_ENGINE_ARGS:-"$DYNAMO_HOME/examples/backends/trtllm/engine_configs/qwen3/agg.yaml"}
17
18
19
export MODALITY=${MODALITY:-"text"}
# If you want to use multimodal, set MODALITY to "multimodal"
#export MODALITY=${MODALITY:-"multimodal"}
20
21


22
ENABLE_OTEL=false
23
USE_UNIFIED=false
24
EXTRA_ARGS=()
25
26
27
28
29
30
while [[ $# -gt 0 ]]; do
    case $1 in
        --enable-otel)
            ENABLE_OTEL=true
            shift
            ;;
31
32
33
34
        --unified)
            USE_UNIFIED=true
            shift
            ;;
35
36
37
38
        -h|--help)
            echo "Usage: $0 [OPTIONS]"
            echo "Options:"
            echo "  --enable-otel        Enable OpenTelemetry tracing"
39
            echo "  --unified            Use unified_main entry point (Worker)"
40
41
            echo "  -h, --help           Show this help message"
            echo ""
42
            echo "Any additional options are passed through to dynamo.trtllm."
43
44
45
            exit 0
            ;;
        *)
46
47
            EXTRA_ARGS+=("$1")
            shift
48
49
50
51
            ;;
    esac
done

52
TRTLLM_OVERRIDE_ARGS=()
53
54
55
56
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}
57
58
59
60
61
62
63
64
65
66
67
    OTEL_JSON="{\"return_perf_metrics\": true, \"otlp_traces_endpoint\": \"${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}\"}"
    # Merge GPU mem config with OTEL config
    OVERRIDE_JSON=$(build_trtllm_override_args_with_mem --merge-with-json "$OTEL_JSON")
else
    # Just GPU mem config (if any)
    OVERRIDE_JSON=$(build_trtllm_override_args_with_mem)
fi

# Add --override-engine-args if we have JSON
if [[ -n "$OVERRIDE_JSON" ]]; then
    TRTLLM_OVERRIDE_ARGS=(--override-engine-args "$OVERRIDE_JSON")
68
69
fi

70
71
HTTP_PORT="${DYN_HTTP_PORT:-8000}"
print_launch_banner "Launching Aggregated Serving" "$MODEL_PATH" "$HTTP_PORT"
72

73
# run frontend
74
# dynamo.frontend accepts either --http-port flag or DYN_HTTP_PORT env var (defaults to 8000)
75
OTEL_SERVICE_NAME=dynamo-frontend \
76
python3 -m dynamo.frontend &
77
78

# run worker
79
# Additional command line args can be passed
80
81
82
83
WORKER_MODULE="dynamo.trtllm"
if [ "$USE_UNIFIED" = true ]; then
    WORKER_MODULE="dynamo.trtllm.unified_main"
fi
84
OTEL_SERVICE_NAME=dynamo-worker \
85
python3 -m "$WORKER_MODULE" \
86
87
  --model-path "$MODEL_PATH" \
  --served-model-name "$SERVED_MODEL_NAME" \
88
  --modality "$MODALITY" \
89
  --extra-engine-args "$AGG_ENGINE_ARGS" \
90
  "${TRTLLM_OVERRIDE_ARGS[@]}" \
91
92
93
94
  "${EXTRA_ARGS[@]}" &

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