build-epp-dynamo.sh 3.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env bash

# SPDX-FileCopyrightText: Copyright (c) 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.
set -e  # Exit on any error

# Configuration - Set these environment variables before running
if [[ -z "${DYNAMO_DIR}" ]]; then
    echo "DYNAMO_DIR environment variable must be set"
    echo "   Example: export DYNAMO_DIR=/path/to/dynamo"
    exit 1
fi

26
27
28
if [[ -z "${GAIE_DIR}" ]]; then
    echo "GAIE_DIR environment variable must be set"
    echo "   Example: export GAIE_DIR=/path/to/gateway-api-inference-extension"
29
30
    exit 1
fi
31
32
DYNAMO_LIB_DIR="${GAIE_DIR}/pkg/epp/scheduling/plugins/dynamo_kv_scorer/lib"
DYNAMO_INCLUDE_DIR="${GAIE_DIR}/pkg/epp/scheduling/plugins/dynamo_kv_scorer/include"
33

34
echo "Building Dynamo KV Router C Library..."
35
36

# Step 1: Build the static library
37
echo "Building static library..."
38
39
40
41
cd "${DYNAMO_DIR}"
cargo build --release -p libdynamo_llm

# Step 2: Generate header file (with fallback)
42
echo "Generating C header..."
43
44
45
46
47
48
49
HEADER_OUTPUT="${DYNAMO_DIR}/lib/bindings/c/include/nvidia/dynamo_llm/llm_engine.h"

if ! cbindgen --config lib/bindings/c/cbindgen.toml --crate libdynamo_llm --output "${HEADER_OUTPUT}"; then
    echo "cbindgen failed, using fallback header..."
    cp "${DYNAMO_DIR}/lib/bindings/c/src/fallback_header.h" "${HEADER_OUTPUT}"
fi

50
51
# Step 3: Ensure directories exist
echo "Preparing directories..."
52
53
54
mkdir -p "${DYNAMO_LIB_DIR}"
mkdir -p "${DYNAMO_INCLUDE_DIR}"

55
56
# Step 4: Copy files to GAIE project
echo "Copying files to the GAIE project..."
57
58
cp "${HEADER_OUTPUT}" "${DYNAMO_INCLUDE_DIR}/"
cp "${DYNAMO_DIR}/target/release/libdynamo_llm_capi.a" "${DYNAMO_LIB_DIR}/"
59
cp "${DYNAMO_DIR}/container/Dockerfile.epp" "${GAIE_DIR}/Dockerfile.dynamo"
60
61
62
63
64
65
66
67
68
69
70
71

# Verify files were copied
if [[ ! -f "${DYNAMO_INCLUDE_DIR}/llm_engine.h" ]]; then
    echo "Header file copy failed!"
    exit 1
fi

if [[ ! -f "${DYNAMO_LIB_DIR}/libdynamo_llm_capi.a" ]]; then
    echo "Library file copy failed!"
    exit 1
fi

72
73
74
75
76
if [[ ! -f "${GAIE_DIR}/Dockerfile.epp" ]]; then
    echo "Docker.epp file copy failed!"
    exit 1
fi

77
78
79
echo "Files copied successfully:"
echo "   Header: ${DYNAMO_INCLUDE_DIR}/llm_engine.h"
echo "   Library: ${DYNAMO_LIB_DIR}/libdynamo_llm_capi.a"
80
echo "   Docker: ${GAIE_DIR}/Dockerfile.epp"
81
82

# Step 5: Apply Dynamo patch (if it exists)
83
84
echo "Applying Dynamo patch..."
cd "${GAIE_DIR}"
85
86
87
88
89
90
91
92
93
94
95
96
97
98

PATCH_FILE="${DYNAMO_DIR}/deploy/inference-gateway/epp-patches/v0.5.1-2/epp-v0.5.1-dyn2.patch"
if [[ -f "${PATCH_FILE}" ]]; then
    if git apply --check "${PATCH_FILE}" 2>/dev/null; then
        git apply "${PATCH_FILE}"
        echo "Patch applied successfully"
    else
        echo "Patch doesn't apply cleanly - may already be applied or need manual resolution"
    fi
else
    echo "No patch file found at ${PATCH_FILE}"
fi

# Step 6: Build the EPP image
99
echo "Building the custom EPP image for GAIE..."
100
101
make dynamo-image-local-load

102
echo "EPP image with Dynamo KV routing built"