build_trtllm_wheel.sh 3.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash -e
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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.

17
# Build the TRT-LLM wheel.
18
19
20

# This script builds the TRT-LLM base image for Dynamo with TensorRT-LLM.

21
while getopts "c:o:a:n:u:" opt; do
22
23
  case ${opt} in
    c) TRTLLM_COMMIT=$OPTARG ;;
24
25
    o) OUTPUT_DIR=$OPTARG ;;
    a) ARCH=$OPTARG ;;
26
    n) NIXL_COMMIT=$OPTARG ;;
27
28
    u) TRTLLM_GIT_URL=$OPTARG ;;
    *) echo "Usage: $(basename $0) [-c commit] [-o output_dir] [-a arch] [-n nixl_commit] [-u git_url]"
29
30
31
       echo "  -c: TensorRT-LLM commit to build"
       echo "  -o: Output directory for wheel files"
       echo "  -a: Architecture (amd64 or arm64)"
32
       echo "  -n: NIXL commit"
33
       echo "  -u: TensorRT-LLM git URL"
34
       exit 1 ;;
35
36
37
  esac
done

38
39
40
41
# Set default output directory if not specified
if [ -z "$OUTPUT_DIR" ]; then
    OUTPUT_DIR="/tmp/trtllm_wheel"
fi
42

43
44
45
46
47
# Set default TensorRT-LLM git URL if not specified
if [ -z "$TRTLLM_GIT_URL" ]; then
    TRTLLM_GIT_URL="https://github.com/NVIDIA/TensorRT-LLM.git"
fi

48
49
# Store directory where script is being launched from
MAIN_DIR=$(dirname "$(readlink -f "$0")")
50

51
52
53
(cd /tmp && \
# Clone the TensorRT-LLM repository.
if [ ! -d "TensorRT-LLM" ]; then
54
  git clone "${TRTLLM_GIT_URL}"
55
56
57
58
59
fi

cd TensorRT-LLM

# Checkout the specified commit.
60
61
62
# Switch to the main branch to pull the latest changes.
git checkout main
git pull
63
64
65
66
67
68
git checkout $TRTLLM_COMMIT

# Update the submodules.
git submodule update --init --recursive
git lfs pull

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
VERSION_FILE="tensorrt_llm/version.py"

# Check if file exists
if [ ! -f "$VERSION_FILE" ]; then
    echo "Error: $VERSION_FILE not found"
    exit 1
fi

# Create a backup of the original version file
cp $VERSION_FILE ${VERSION_FILE}.bak

# Check if version line exists
if ! grep -q "^__version__" "$VERSION_FILE"; then
    echo "Error: __version__ not found in $VERSION_FILE"
    exit 1
fi

# Append suffix to version
COMMIT_VERSION=$(git rev-parse --short HEAD)
sed -i "s/__version__ = \"\(.*\)\"/__version__ = \"\1+dev${COMMIT_VERSION}\"/" "$VERSION_FILE"

echo "Updated version:"
grep "__version__" "$VERSION_FILE"

93
94
95
96
97
98
99
100
101
if [ "$ARCH" = "amd64" ]; then
    # Need to build in the Triton Devel Image for NIXL support.
    make -C docker tritondevel_build
    make -C docker wheel_build DEVEL_IMAGE=tritondevel BUILD_WHEEL_OPTS='--extra-cmake-vars NIXL_ROOT=/opt/nvidia/nvda_nixl'
else
    # NIXL backend is not supported on arm64 for TensorRT-LLM.
    # See here: https://github.com/NVIDIA/TensorRT-LLM/blob/main/docker/common/install_nixl.sh
    make -C docker wheel_build
fi
102
103
104
105
106
107
108
109

# Copy the wheel to the host
mkdir -p $OUTPUT_DIR

docker create --name trtllm_wheel_container docker.io/tensorrt_llm/wheel:latest
docker cp trtllm_wheel_container:/src/tensorrt_llm/build $OUTPUT_DIR/
cp $OUTPUT_DIR/build/*.whl $OUTPUT_DIR/
docker rm trtllm_wheel_container || true
110
111
112
113

# Restore the original version file
mv ${VERSION_FILE}.bak $VERSION_FILE

114
)
115

116
117
118
# Store the commit hash in the output directory to ensure the wheel is built from the correct commit.
rm -rf $OUTPUT_DIR/commit.txt
echo ${ARCH}_${TRTLLM_COMMIT} > $OUTPUT_DIR/commit.txt
119

120
echo "TRT-LLM wheel built successfully."
121
ls -al $OUTPUT_DIR