"include/vscode:/vscode.git/clone" did not exist on "79643f51ed835bc8c897fb429a9d77a41701d7ad"
build.sh 8.94 KB
Newer Older
1
#!/bin/bash -e
Neelay Shah's avatar
Neelay Shah committed
2
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
# SPDX-License-Identifier: Apache-2.0
4
5
6
7
8
9
10
11
12
13
14
15
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
16

17

18
19
20
TAG=
RUN_PREFIX=
PLATFORM=linux/amd64
21
22
23
24

# Get short commit hash
commit_id=$(git rev-parse --short HEAD)

25
26
# if COMMIT_ID matches a TAG use that
current_tag=$(git describe --tags --exact-match 2>/dev/null | sed 's/^v//') || true
27

28
29
# Get latest TAG and add COMMIT_ID for dev
latest_tag=$(git describe --tags --abbrev=0 $(git rev-list --tags --max-count=1 main) | sed 's/^v//') || true
30
31
32
33
if [[ -z ${latest_tag} ]]; then
    latest_tag="0.0.1"
    echo "No git release tag found, setting to unknown version: ${latest_tag}"
fi
34

35
36
37
38
# Use tag if available, otherwise use latest_tag.dev.commit_id
VERSION=v${current_tag:-$latest_tag.dev.$commit_id}

PYTHON_PACKAGE_VERSION=${current_tag:-$latest_tag.dev+$commit_id}
39
40
41
42
43
44

# Frameworks
#
# Each framework has a corresponding base image.  Additional
# dependencies are specified in the /container/deps folder and
# installed within framework specific sections of the Dockerfile.
45

46
47
48
49
50
51
52
53
54
declare -A FRAMEWORKS=(["STANDARD"]=1 ["TENSORRTLLM"]=2 ["VLLM"]=3)
DEFAULT_FRAMEWORK=STANDARD

SOURCE_DIR=$(dirname "$(readlink -f "$0")")
DOCKERFILE=${SOURCE_DIR}/Dockerfile
BUILD_CONTEXT=$(dirname "$(readlink -f "$SOURCE_DIR")")

# Base Images

55
STANDARD_BASE_VERSION=25.01
56
57
58
STANDARD_BASE_IMAGE=nvcr.io/nvidia/tritonserver
STANDARD_BASE_IMAGE_TAG=${STANDARD_BASE_VERSION}-py3

59
TENSORRTLLM_BASE_VERSION=25.01
60
61
TENSORRTLLM_BASE_IMAGE=nvcr.io/nvidia/tritonserver
TENSORRTLLM_BASE_IMAGE_TAG=${TENSORRTLLM_BASE_VERSION}-trtllm-python-py3
62
63
# IMPORTANT NOTE: Ensure the repo tag complies with the TRTLLM backend version
# used in the base image above.
64
TENSORRTLLM_BACKEND_REPO_TAG=triton-llm/v0.17.0
65
66
67
# Set this as 1 to rebuild and replace trtllm backend bits in the container.
# This will allow building triton distributed container image with custom
# trt-llm backend repo branch.
68
TENSORRTLLM_BACKEND_REBUILD=1
69

70
71
VLLM_BASE_IMAGE="nvcr.io/nvidia/cuda-dl-base"
VLLM_BASE_IMAGE_TAG="25.01-cuda12.8-devel-ubuntu24.04"
72
73
74
75
76
77
78
79

get_options() {
    while :; do
        case $1 in
        -h | -\? | --help)
            show_help
            exit
            ;;
80
        --platform)
81
82
83
84
            if [ "$2" ]; then
                PLATFORM=$2
                shift
            else
85
                missing_requirement $1
86
87
            fi
            ;;
88
        --framework)
89
90
91
92
            if [ "$2" ]; then
                FRAMEWORK=$2
                shift
            else
93
                missing_requirement $1
94
95
            fi
            ;;
96
        --tensorrtllm-backend-repo-tag)
97
98
99
100
            if [ "$2" ]; then
                TRTLLM_BACKEND_COMMIT=$2
                shift
            else
101
                missing_requirement $1
102
103
            fi
            ;;
104
105
106
107
108
        --tensorrtllm-backend-rebuild)
            if [ "$2" ]; then
                TRTLLM_BACKEND_REBUILD=$2
                shift
            else
109
                missing_requirement $1
110
111
            fi
            ;;
112
113
114
115
116
        --base-image)
            if [ "$2" ]; then
                BASE_IMAGE=$2
                shift
            else
117
                missing_requirement $1
118
119
            fi
            ;;
120
        --base-image-tag)
121
122
123
124
            if [ "$2" ]; then
                BASE_IMAGE_TAG=$2
                shift
            else
125
126
127
128
129
130
131
132
133
                missing_requirement $1
            fi
            ;;
        --target)
            if [ "$2" ]; then
                TARGET=$2
                shift
            else
                missing_requirement $1
134
135
136
137
138
139
140
            fi
            ;;
        --build-arg)
            if [ "$2" ]; then
                BUILD_ARGS+="--build-arg $2 "
                shift
            else
141
                missing_requirement $1
142
143
144
145
            fi
            ;;
        --tag)
            if [ "$2" ]; then
146
                TAG="--tag $2"
147
148
                shift
            else
149
                missing_requirement $1
150
151
152
153
154
155
156
157
158
159
            fi
            ;;
        --dry-run)
            RUN_PREFIX="echo"
            echo ""
            echo "=============================="
            echo "DRY RUN: COMMANDS PRINTED ONLY"
            echo "=============================="
            echo ""
            ;;
160
161
        --no-cache)
            NO_CACHE=" --no-cache"
162
            ;;
163
164
        --cache-from)
            if [ "$2" ]; then
165
166
167
                CACHE_FROM="--cache-from $2"
                shift
            else
168
                missing_requirement $1
169
170
            fi
            ;;
171
172
173
174
175
        --)
            shift
            break
            ;;
         -?*)
176
            error 'ERROR: Unknown option: ' $1
177
            ;;
178
179
         ?*)
            error 'ERROR: Unknown option: ' $1
180
181
182
183
184
185
186
187
188
            ;;
        *)
            break
            ;;
        esac
        shift
    done

    if [ -z "$FRAMEWORK" ]; then
189
        FRAMEWORK=$DEFAULT_FRAMEWORK
190
191
192
    fi

    if [ ! -z "$FRAMEWORK" ]; then
193
        FRAMEWORK=${FRAMEWORK^^}
194

195
196
197
        if [[ ! -n "${FRAMEWORKS[$FRAMEWORK]}" ]]; then
            error 'ERROR: Unknown framework: ' $FRAMEWORK
        fi
198

199
200
201
202
        if [ -z $BASE_IMAGE_TAG ]; then
            BASE_IMAGE_TAG=${FRAMEWORK}_BASE_IMAGE_TAG
            BASE_IMAGE_TAG=${!BASE_IMAGE_TAG}
        fi
203

204
205
206
207
        if [ -z $BASE_IMAGE ]; then
            BASE_IMAGE=${FRAMEWORK}_BASE_IMAGE
            BASE_IMAGE=${!BASE_IMAGE}
        fi
208

209
210
211
        if [ -z $BASE_IMAGE ]; then
            error "ERROR: Framework $FRAMEWORK without BASE_IMAGE"
        fi
212

213
214
        BASE_VERSION=${FRAMEWORK}_BASE_VERSION
        BASE_VERSION=${!BASE_VERSION}
215
216
217
218

    fi

    if [ -z "$TAG" ]; then
219
        TAG="--tag triton-distributed:${VERSION}-${FRAMEWORK,,}"
220
221
222
        if [ ! -z ${TARGET} ]; then
            TAG="${TAG}-${TARGET}"
        fi
223
224
225
226
227
228
    fi

    if [ ! -z "$PLATFORM" ]; then
        PLATFORM="--platform ${PLATFORM}"
    fi

229
230
231
    if [ ! -z "$TARGET" ]; then
        TARGET_STR="--target ${TARGET}"
    fi
232
233
234
235
236
237
238
239
240
241
}


show_image_options() {
    echo ""
    echo "Building Triton Distributed Image: '${TAG}'"
    echo ""
    echo "   Base: '${BASE_IMAGE}'"
    echo "   Base_Image_Tag: '${BASE_IMAGE_TAG}'"
    if [[ $FRAMEWORK == "TENSORRTLLM" ]]; then
242
        echo "   Tensorrtllm Backend Repo Tag: '${TENSORRTLLM_BACKEND_REPO_TAG}'"
243
        echo "   Tensorrtllm Backend Rebuild: '${TENSORRTLLM_BACKEND_REBUILD}'"
244
245
246
247
248
249
250
251
252
253
254
255
256
    fi
    echo "   Build Context: '${BUILD_CONTEXT}'"
    echo "   Build Arguments: '${BUILD_ARGS}'"
    echo "   Framework: '${FRAMEWORK}'"
    echo ""
}

show_help() {
    echo "usage: build.sh"
    echo "  [--base base image]"
    echo "  [--base-imge-tag base image tag]"
    echo "  [--platform platform for docker build"
    echo "  [--framework framework one of ${!FRAMEWORKS[@]}]"
257
258
    echo "  [--tensorrtllm-backend-repo-tag commit or tag]"
    echo "  [--tensorrtllm-backend-rebuild whether or not to rebuild the backend]"
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    echo "  [--build-arg additional build args to pass to docker build]"
    echo "  [--tag tag for image]"
    echo "  [--no-cache disable docker build cache]"
    echo "  [--dry-run print docker commands without running]"
    exit 0
}

missing_requirement() {
    error "ERROR: $1 requires an argument."
}

error() {
    printf '%s %s\n' "$1" "$2" >&2
    exit 1
}

get_options "$@"


278
279
280
281
282
# Update DOCKERFILE if framework is VLLM
if [[ $FRAMEWORK == "VLLM" ]]; then
    DOCKERFILE=${SOURCE_DIR}/Dockerfile.vllm
fi

283
284
# BUILD DEV IMAGE

285
BUILD_ARGS+=" --build-arg BASE_IMAGE=$BASE_IMAGE --build-arg BASE_IMAGE_TAG=$BASE_IMAGE_TAG --build-arg FRAMEWORK=$FRAMEWORK --build-arg ${FRAMEWORK}_FRAMEWORK=1 --build-arg VERSION=$VERSION --build-arg PYTHON_PACKAGE_VERSION=$PYTHON_PACKAGE_VERSION"
286
287
288
289
290
291
292
293
294

if [ ! -z ${GITHUB_TOKEN} ]; then
    BUILD_ARGS+=" --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} "
fi

if [ ! -z ${GITLAB_TOKEN} ]; then
    BUILD_ARGS+=" --build-arg GITLAB_TOKEN=${GITLAB_TOKEN} "
fi

295
296
297
if [[ $FRAMEWORK == "TENSORRTLLM" ]] && [ ! -z ${TENSORRTLLM_BACKEND_REPO_TAG} ]; then
    BUILD_ARGS+=" --build-arg TENSORRTLLM_BACKEND_REPO_TAG=${TENSORRTLLM_BACKEND_REPO_TAG} "
    BUILD_ARGS+=" --build-arg TENSORRTLLM_BACKEND_REBUILD=${TENSORRTLLM_BACKEND_REBUILD} "
298
299
300
301
302
303
fi

if [ ! -z ${HF_TOKEN} ]; then
    BUILD_ARGS+=" --build-arg HF_TOKEN=${HF_TOKEN} "
fi

304
LATEST_TAG="--tag triton-distributed:latest-${FRAMEWORK,,}"
305
306
307
if [ ! -z ${TARGET} ]; then
    LATEST_TAG="${LATEST_TAG}-${TARGET}"
fi
308

309
310
311
312
313
314
show_image_options

if [ -z "$RUN_PREFIX" ]; then
    set -x
fi

315
$RUN_PREFIX docker build -f $DOCKERFILE $TARGET_STR $PLATFORM $BUILD_ARGS $CACHE_FROM $TAG $LATEST_TAG $BUILD_CONTEXT $NO_CACHE
316
317
318
319
320
321
322
323

{ set +x; } 2>/dev/null

if [ -z "$RUN_PREFIX" ]; then
    set -x
fi

{ set +x; } 2>/dev/null