".github/vscode:/vscode.git/clone" did not exist on "11bb84983a0b284d6e94fc13918119e90ae71dc2"
build.sh 18 KB
Newer Older
Carsten Csiky's avatar
Carsten Csiky committed
1
#!/usr/bin/env bash
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
21
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
    echo "Error: Bash version 4.0 or higher is required. Current version: ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}"
    exit 1
fi

Carsten Csiky's avatar
Carsten Csiky committed
22
set -e
23

24
25
26
TAG=
RUN_PREFIX=
PLATFORM=linux/amd64
27
28
29
30

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

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

34
# Get latest TAG and add COMMIT_ID for dev
Carsten Csiky's avatar
Carsten Csiky committed
35
latest_tag=$(git describe --tags --abbrev=0 "$(git rev-list --tags --max-count=1 main)" | sed 's/^v//') || true
36
37
38
39
if [[ -z ${latest_tag} ]]; then
    latest_tag="0.0.1"
    echo "No git release tag found, setting to unknown version: ${latest_tag}"
fi
40

41
42
43
44
# 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}
45
46
47
48
49
50

# 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.
51

52
declare -A FRAMEWORKS=(["VLLM"]=1 ["TENSORRTLLM"]=2 ["NONE"]=3 ["SGLANG"]=4 ["VLLM_V1"]=5)
53
DEFAULT_FRAMEWORK=VLLM
54
55
56
57
58
59

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

# Base Images
60
TENSORRTLLM_BASE_IMAGE=nvcr.io/nvidia/pytorch
61
TENSORRTLLM_BASE_IMAGE_TAG=25.04-py3
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

# Important Note: Because of ABI compatibility issues between TensorRT-LLM and NGC PyTorch,
# we need to build the TensorRT-LLM wheel from source.
#
# There are two ways to build the dynamo image with TensorRT-LLM.
# 1. Use the local TensorRT-LLM wheel directory.
# 2. Use the TensorRT-LLM wheel on artifactory.
#
# If using option 1, the TENSORRTLLM_PIP_WHEEL_DIR must be a path to a directory
# containing TensorRT-LLM wheel file along with commit.txt file with the
# <arch>_<commit ID> as contents. If no valid trtllm wheel is found, the script
# will attempt to build the wheel from source and store the built wheel in the
# specified directory. TRTLLM_COMMIT from the TensorRT-LLM main branch will be
# used to build the wheel.
#
# If using option 2, the TENSORRTLLM_PIP_WHEEL must be the TensorRT-LLM wheel
# package that will be installed from the specified TensorRT-LLM PyPI Index URL.
# This option will ignore the TRTLLM_COMMIT option. As the TensorRT-LLM wheel from PyPI
# is not ABI compatible with NGC PyTorch, you can use TENSORRTLLM_INDEX_URL to specify
# a private PyPI index URL which has your pre-built TensorRT-LLM wheel.
#
# By default, we will use option 1. If you want to use option 2, you can set
# TENSORRTLLM_PIP_WHEEL to the TensorRT-LLM wheel on artifactory.
#
# Path to the local TensorRT-LLM wheel directory or the wheel on artifactory.
TENSORRTLLM_PIP_WHEEL_DIR="/tmp/trtllm_wheel/"
# TensorRT-LLM commit to use for building the trtllm wheel if not provided.
# Important Note: This commit is not used in our CI pipeline. See the CI
# variables to learn how to run a pipeline with a specific commit.
91
92
DEFAULT_EXPERIMENTAL_TRTLLM_COMMIT="137fe35539ea182f1495f5021bfda97c729e50c3"
TRTLLM_COMMIT=""
93

94
95
# TensorRT-LLM PyPI index URL
TENSORRTLLM_INDEX_URL="https://pypi.python.org/simple"
96
DEFAULT_TENSORRTLLM_PIP_WHEEL="tensorrt-llm==0.21.0rc0"
97
98
99
TENSORRTLLM_PIP_WHEEL=""


100
VLLM_BASE_IMAGE="nvcr.io/nvidia/cuda-dl-base"
101
102
103
104
105
# FIXME: NCCL will hang with 25.03, so use 25.01 for now
# Please check https://github.com/ai-dynamo/dynamo/pull/1065
# for details and reproducer to manually test if the image
# can be updated to later versions.
VLLM_BASE_IMAGE_TAG="25.01-cuda12.8-devel-ubuntu24.04"
106

107
108
109
NONE_BASE_IMAGE="ubuntu"
NONE_BASE_IMAGE_TAG="24.04"

110
111
112
SGLANG_BASE_IMAGE="nvcr.io/nvidia/cuda-dl-base"
SGLANG_BASE_IMAGE_TAG="25.01-cuda12.8-devel-ubuntu24.04"

113
114
115
VLLM_V1_BASE_IMAGE="nvcr.io/nvidia/cuda-dl-base"
VLLM_V1_BASE_IMAGE_TAG="25.01-cuda12.8-devel-ubuntu24.04"

116
NIXL_COMMIT=16348080f5bdeb9fe6058a23be140cec020ef3f3
117
118
NIXL_REPO=ai-dynamo/nixl.git

119
120
NIXL_UCX_EFA_REF=7ec95b95e524a87e81cac92f5ca8523e3966b16b

121
122
NO_CACHE=""

123
124
125
126
127
128
129
get_options() {
    while :; do
        case $1 in
        -h | -\? | --help)
            show_help
            exit
            ;;
130
        --platform)
131
132
133
134
            if [ "$2" ]; then
                PLATFORM=$2
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
135
                missing_requirement "$1"
136
137
            fi
            ;;
138
        --framework)
139
140
141
142
            if [ "$2" ]; then
                FRAMEWORK=$2
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
143
                missing_requirement "$1"
144
145
            fi
            ;;
146
        --tensorrtllm-pip-wheel-dir)
147
            if [ "$2" ]; then
148
149
150
151
152
153
154
155
156
157
158
159
160
161
                TENSORRTLLM_PIP_WHEEL_DIR=$2
                shift
            else
                missing_requirement "$1"
            fi
            ;;
        --tensorrtllm-commit)
            if [ "$2" ]; then
                TRTLLM_COMMIT=$2
                shift
            else
                missing_requirement "$1"
            fi
            ;;
162
163
164
165
166
167
168
        --use-default-experimental-tensorrtllm-commit)
            if [ -n "$2" ] && [[ "$2" != --* ]]; then
                echo "ERROR: --use-default-experimental-tensorrtllm-commit does not take any argument"
                exit 1
            fi
            USE_DEFAULT_EXPERIMENTAL_TRTLLM_COMMIT=true
            ;;
169
170
171
172
173
174
175
176
177
178
179
        --tensorrtllm-pip-wheel)
            if [ "$2" ]; then
                TENSORRTLLM_PIP_WHEEL=$2
                shift
            else
                missing_requirement "$1"
            fi
            ;;
        --tensorrtllm-index-url)
            if [ "$2" ]; then
                TENSORRTLLM_INDEX_URL=$2
180
181
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
182
                missing_requirement "$1"
183
184
            fi
            ;;
185
186
187
188
189
        --base-image)
            if [ "$2" ]; then
                BASE_IMAGE=$2
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
190
                missing_requirement "$1"
191
192
            fi
            ;;
193
        --base-image-tag)
194
195
196
197
            if [ "$2" ]; then
                BASE_IMAGE_TAG=$2
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
198
                missing_requirement "$1"
199
200
201
202
203
204
205
            fi
            ;;
        --target)
            if [ "$2" ]; then
                TARGET=$2
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
206
                missing_requirement "$1"
207
208
209
210
211
212
213
            fi
            ;;
        --build-arg)
            if [ "$2" ]; then
                BUILD_ARGS+="--build-arg $2 "
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
214
                missing_requirement "$1"
215
216
217
218
            fi
            ;;
        --tag)
            if [ "$2" ]; then
219
                TAG="--tag $2"
220
221
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
222
                missing_requirement "$1"
223
224
225
226
227
228
229
230
231
232
            fi
            ;;
        --dry-run)
            RUN_PREFIX="echo"
            echo ""
            echo "=============================="
            echo "DRY RUN: COMMANDS PRINTED ONLY"
            echo "=============================="
            echo ""
            ;;
233
234
        --no-cache)
            NO_CACHE=" --no-cache"
235
            ;;
236
237
        --cache-from)
            if [ "$2" ]; then
238
239
240
                CACHE_FROM="--cache-from $2"
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
241
                missing_requirement "$1"
242
243
            fi
            ;;
244
245
246
247
248
        --cache-to)
            if [ "$2" ]; then
                CACHE_TO="--cache-to $2"
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
249
                missing_requirement "$1"
250
251
            fi
            ;;
ptarasiewiczNV's avatar
ptarasiewiczNV committed
252
253
254
255
256
        --build-context)
            if [ "$2" ]; then
                BUILD_CONTEXT_ARG="--build-context $2"
                shift
            else
Carsten Csiky's avatar
Carsten Csiky committed
257
                missing_requirement "$1"
ptarasiewiczNV's avatar
ptarasiewiczNV committed
258
259
            fi
            ;;
260
261
262
        --release-build)
            RELEASE_BUILD=true
            ;;
263
264
265
        --make-efa)
            NIXL_UCX_REF=$NIXL_UCX_EFA_REF
            ;;
266
267
268
269
270
        --)
            shift
            break
            ;;
         -?*)
Carsten Csiky's avatar
Carsten Csiky committed
271
            error 'ERROR: Unknown option: ' "$1"
272
            ;;
273
         ?*)
Carsten Csiky's avatar
Carsten Csiky committed
274
            error 'ERROR: Unknown option: ' "$1"
275
276
277
278
279
280
281
282
283
            ;;
        *)
            break
            ;;
        esac
        shift
    done

    if [ -z "$FRAMEWORK" ]; then
284
        FRAMEWORK=$DEFAULT_FRAMEWORK
285
286
    fi

Carsten Csiky's avatar
Carsten Csiky committed
287
    if [ -n "$FRAMEWORK" ]; then
288
        FRAMEWORK=${FRAMEWORK^^}
289

Carsten Csiky's avatar
Carsten Csiky committed
290
291
        if [[ -z "${FRAMEWORKS[$FRAMEWORK]}" ]]; then
            error 'ERROR: Unknown framework: ' "$FRAMEWORK"
292
        fi
293

Carsten Csiky's avatar
Carsten Csiky committed
294
        if [ -z "$BASE_IMAGE_TAG" ]; then
295
296
297
            BASE_IMAGE_TAG=${FRAMEWORK}_BASE_IMAGE_TAG
            BASE_IMAGE_TAG=${!BASE_IMAGE_TAG}
        fi
298

Carsten Csiky's avatar
Carsten Csiky committed
299
        if [ -z "$BASE_IMAGE" ]; then
300
301
302
            BASE_IMAGE=${FRAMEWORK}_BASE_IMAGE
            BASE_IMAGE=${!BASE_IMAGE}
        fi
303

Carsten Csiky's avatar
Carsten Csiky committed
304
        if [ -z "$BASE_IMAGE" ]; then
305
306
            error "ERROR: Framework $FRAMEWORK without BASE_IMAGE"
        fi
307

308
309
        BASE_VERSION=${FRAMEWORK}_BASE_VERSION
        BASE_VERSION=${!BASE_VERSION}
310
311
312
313

    fi

    if [ -z "$TAG" ]; then
314
        TAG="--tag dynamo:${VERSION}-${FRAMEWORK,,}"
Carsten Csiky's avatar
Carsten Csiky committed
315
        if [ -n "${TARGET}" ]; then
316
317
            TAG="${TAG}-${TARGET}"
        fi
318
319
    fi

Carsten Csiky's avatar
Carsten Csiky committed
320
    if [ -n "$PLATFORM" ]; then
321
322
323
        PLATFORM="--platform ${PLATFORM}"
    fi

Carsten Csiky's avatar
Carsten Csiky committed
324
    if [ -n "$TARGET" ]; then
325
        TARGET_STR="--target ${TARGET}"
326
    else
327
        TARGET_STR="--target dev"
328
    fi
329
330
331
332
333
}


show_image_options() {
    echo ""
334
    echo "Building Dynamo Image: '${TAG}'"
335
336
337
338
    echo ""
    echo "   Base: '${BASE_IMAGE}'"
    echo "   Base_Image_Tag: '${BASE_IMAGE_TAG}'"
    if [[ $FRAMEWORK == "TENSORRTLLM" ]]; then
339
        echo "   Tensorrtllm_Pip_Wheel: '${TENSORRTLLM_PIP_WHEEL}'"
340
341
342
343
344
345
346
347
348
349
    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]"
Carsten Csiky's avatar
Carsten Csiky committed
350
    echo "  [--base-image-tag base image tag]"
351
    echo "  [--platform platform for docker build"
Carsten Csiky's avatar
Carsten Csiky committed
352
    echo "  [--framework framework one of ${!FRAMEWORKS[*]}]"
353
354
    echo "  [--tensorrtllm-pip-wheel-dir path to tensorrtllm pip wheel directory]"
    echo "  [--tensorrtllm-commit tensorrtllm commit to use for building the trtllm wheel if the wheel is not provided]"
355
    echo "  [--use-default-experimental-tensorrtllm-commit] Use the default experimental commit (${DEFAULT_EXPERIMENTAL_TRTLLM_COMMIT}) to build TensorRT-LLM. This is a flag (no argument). Do not combine with --tensorrtllm-commit or --tensorrtllm-pip-wheel."
356
357
    echo "  [--tensorrtllm-pip-wheel tensorrtllm pip wheel on artifactory]"
    echo "  [--tensorrtllm-index-url tensorrtllm PyPI index URL if providing the wheel from artifactory]"
358
    echo "  [--build-arg additional build args to pass to docker build]"
359
360
    echo "  [--cache-from cache location to start from]"
    echo "  [--cache-to location where to cache the build output]"
361
362
363
    echo "  [--tag tag for image]"
    echo "  [--no-cache disable docker build cache]"
    echo "  [--dry-run print docker commands without running]"
ptarasiewiczNV's avatar
ptarasiewiczNV committed
364
    echo "  [--build-context name=path to add build context]"
365
366
    echo "  [--release-build perform a release build]"
    echo "  [--make-efa Enables EFA support for NIXL]"
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    exit 0
}

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

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

get_options "$@"

381
# Automatically set ARCH and ARCH_ALT if PLATFORM is linux/arm64
382
ARCH="amd64"
383
if [[ "$PLATFORM" == *"linux/arm64"* ]]; then
384
    ARCH="arm64"
385
386
387
    BUILD_ARGS+=" --build-arg ARCH=arm64 --build-arg ARCH_ALT=aarch64 "
fi

388
389
390
# Update DOCKERFILE if framework is VLLM
if [[ $FRAMEWORK == "VLLM" ]]; then
    DOCKERFILE=${SOURCE_DIR}/Dockerfile.vllm
391
392
elif [[ $FRAMEWORK == "TENSORRTLLM" ]]; then
    DOCKERFILE=${SOURCE_DIR}/Dockerfile.tensorrt_llm
393
394
elif [[ $FRAMEWORK == "NONE" ]]; then
    DOCKERFILE=${SOURCE_DIR}/Dockerfile.none
395
396
elif [[ $FRAMEWORK == "SGLANG" ]]; then
    DOCKERFILE=${SOURCE_DIR}/Dockerfile.sglang
397
398
elif [[ $FRAMEWORK == "VLLM_V1" ]]; then
    DOCKERFILE=${SOURCE_DIR}/Dockerfile.vllm_v1
399
400
fi

401
402
403
404
405
406
407
408
NIXL_DIR="/tmp/nixl/nixl_src"

# Clone original NIXL to temp directory
if [ -d "$NIXL_DIR" ]; then
    echo "Warning: $NIXL_DIR already exists, skipping clone"
else
    if [ -n "${GITHUB_TOKEN}" ]; then
        git clone "https://oauth2:${GITHUB_TOKEN}@github.com/${NIXL_REPO}" "$NIXL_DIR"
409
    else
410
411
412
413
        # Try HTTPS first with credential prompting disabled, fall back to SSH if it fails
        if ! GIT_TERMINAL_PROMPT=0 git clone https://github.com/${NIXL_REPO} "$NIXL_DIR"; then
            echo "HTTPS clone failed, falling back to SSH..."
            git clone git@github.com:${NIXL_REPO} "$NIXL_DIR"
414
415
        fi
    fi
416
fi
417

418
419
420
421
422
423
cd "$NIXL_DIR" || exit
if ! git checkout ${NIXL_COMMIT}; then
    echo "ERROR: Failed to checkout NIXL commit ${NIXL_COMMIT}. The cached directory may be out of date."
    echo "Please delete $NIXL_DIR and re-run the build script."
    exit 1
fi
424

425
BUILD_CONTEXT_ARG+=" --build-context nixl=$NIXL_DIR"
426

427
428
# Add NIXL_COMMIT as a build argument to enable caching
BUILD_ARGS+=" --build-arg NIXL_COMMIT=${NIXL_COMMIT} "
429

430
431
432
433
if [[ $TARGET == "local-dev" ]]; then
    BUILD_ARGS+=" --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) "
fi

434
435
# BUILD DEV IMAGE

436
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"
437

Carsten Csiky's avatar
Carsten Csiky committed
438
if [ -n "${GITHUB_TOKEN}" ]; then
439
440
441
    BUILD_ARGS+=" --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} "
fi

Carsten Csiky's avatar
Carsten Csiky committed
442
if [ -n "${GITLAB_TOKEN}" ]; then
443
444
445
    BUILD_ARGS+=" --build-arg GITLAB_TOKEN=${GITLAB_TOKEN} "
fi

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485

check_wheel_file() {
    local wheel_dir="$1"
    # Check if directory exists
    if [ ! -d "$wheel_dir" ]; then
        echo "Error: Directory '$wheel_dir' does not exist"
        return 1
    fi

    # Look for .whl files
    wheel_count=$(find "$wheel_dir" -name "*.whl" | wc -l)

    if [ "$wheel_count" -eq 0 ]; then
        echo "WARN: No .whl files found in '$wheel_dir'"
        return 1
    elif [ "$wheel_count" -gt 1 ]; then
        echo "Warning: Multiple wheel files found in '$wheel_dir'. Will use first one found."
        find "$wheel_dir" -name "*.whl" | head -n 1
        return 0
    else
        echo "Found $wheel_count wheel files in '$wheel_dir'"
        # Check if commit file exists
        commit_file="$wheel_dir/commit.txt"
        if [ ! -f "$commit_file" ]; then
            echo "Error: Commit file '$commit_file' does not exist"
            return 1
        fi

        # Check if commit ID matches, otherwise re-build the wheel
        # Commit ID is of the form <arch>_<commit_id>
        commit_id=$(cat "$commit_file")
        if [ "$commit_id" != "$2" ]; then
            echo "Error: Commit ID mismatch. Expected '$2', got '$commit_id'"
            rm -rf $wheel_dir/*.whl
            return 1
        fi
        return 0
    fi
}

486
if [[ $FRAMEWORK == "TENSORRTLLM" ]]; then
487
488
489
490
491
492
493
494
495
496
497
498
499
    if [ "$USE_DEFAULT_EXPERIMENTAL_TRTLLM_COMMIT" = true ]; then
        if [ -n "$TRTLLM_COMMIT" ] || [ -n "$TENSORRTLLM_PIP_WHEEL" ]; then
            echo "ERROR: When using --use-default-experimental-trtllm-commit, do not set --tensorrtllm-commit or --tensorrtllm-pip-wheel."
            exit 1
        fi
        TRTLLM_COMMIT="$DEFAULT_EXPERIMENTAL_TRTLLM_COMMIT"
    fi

    # If user didn't set both wheel and commit, use default tensorrt_llm pip wheel
    if [ -z "$TENSORRTLLM_PIP_WHEEL" ] && [ -z "$TRTLLM_COMMIT" ]; then
        TENSORRTLLM_PIP_WHEEL="$DEFAULT_TENSORRTLLM_PIP_WHEEL"
    fi

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
    if [ -z "${TENSORRTLLM_PIP_WHEEL}" ]; then
        # Use option 1
        if [ ! -d "${TENSORRTLLM_PIP_WHEEL_DIR}" ]; then
            # Create the directory if it doesn't exist
            mkdir -p ${TENSORRTLLM_PIP_WHEEL_DIR}
        fi
        BUILD_ARGS+=" --build-arg HAS_TRTLLM_CONTEXT=1"
        echo "Checking for TensorRT-LLM wheel in ${TENSORRTLLM_PIP_WHEEL_DIR}"
        if ! check_wheel_file "${TENSORRTLLM_PIP_WHEEL_DIR}" "${ARCH}_${TRTLLM_COMMIT}"; then
            echo "WARN: Valid trtllm wheel file not found in ${TENSORRTLLM_PIP_WHEEL_DIR}, attempting to build from source"
            if ! env -i ${SOURCE_DIR}/build_trtllm_wheel.sh -o ${TENSORRTLLM_PIP_WHEEL_DIR} -c ${TRTLLM_COMMIT} -a ${ARCH}; then
                error "ERROR: Failed to build TensorRT-LLM wheel"
            fi
        fi
        echo "Installing TensorRT-LLM from local wheel directory"
        BUILD_CONTEXT_ARG+=" --build-context trtllm_wheel=${TENSORRTLLM_PIP_WHEEL_DIR}"

    else
        BUILD_ARGS+=" --build-arg HAS_TRTLLM_CONTEXT=0"
        BUILD_ARGS+=" --build-arg TENSORRTLLM_PIP_WHEEL=${TENSORRTLLM_PIP_WHEEL}"
        BUILD_ARGS+=" --build-arg TENSORRTLLM_INDEX_URL=${TENSORRTLLM_INDEX_URL}"

        # Create a dummy directory to satisfy the build context requirement
        # There is no way to conditionally copy the build context in dockerfile.
        mkdir -p /tmp/dummy_dir
        BUILD_CONTEXT_ARG+=" --build-context trtllm_wheel=/tmp/dummy_dir"
526
    fi
527
528
fi

Carsten Csiky's avatar
Carsten Csiky committed
529
if [ -n "${HF_TOKEN}" ]; then
530
531
    BUILD_ARGS+=" --build-arg HF_TOKEN=${HF_TOKEN} "
fi
532
533
534
535
if [  ! -z ${RELEASE_BUILD} ]; then
    echo "Performing a release build!"
    BUILD_ARGS+=" --build-arg RELEASE_BUILD=${RELEASE_BUILD} "
fi
536

537
538
539
540
if [ -n "${NIXL_UCX_REF}" ]; then
    BUILD_ARGS+=" --build-arg NIXL_UCX_REF=${NIXL_UCX_REF} "
fi

541
LATEST_TAG="--tag dynamo:latest-${FRAMEWORK,,}"
Carsten Csiky's avatar
Carsten Csiky committed
542
if [ -n "${TARGET}" ]; then
543
544
    LATEST_TAG="${LATEST_TAG}-${TARGET}"
fi
545

546
547
548
549
550
551
show_image_options

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

552
$RUN_PREFIX docker build -f $DOCKERFILE $TARGET_STR $PLATFORM $BUILD_ARGS $CACHE_FROM $CACHE_TO $TAG $LATEST_TAG $BUILD_CONTEXT_ARG $BUILD_CONTEXT $NO_CACHE
553
554

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