forked from huggingface/text-embeddings-inference
-
Notifications
You must be signed in to change notification settings - Fork 4
/
sagemaker-entrypoint-cuda-all.sh
91 lines (81 loc) · 2.73 KB
/
sagemaker-entrypoint-cuda-all.sh
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
91
#!/bin/bash
verlte() {
[ "$1" = "$2" ] && return 1 || [ "$2" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}
if [ -f /usr/local/cuda/compat/libcuda.so.1 ]; then
CUDA_COMPAT_MAX_DRIVER_VERSION=$(readlink /usr/local/cuda/compat/libcuda.so.1 | cut -d"." -f 3-)
echo "CUDA compat package requires Nvidia driver ≤${CUDA_COMPAT_MAX_DRIVER_VERSION}"
cat /proc/driver/nvidia/version
NVIDIA_DRIVER_VERSION=$(sed -n 's/^NVRM.*Kernel Module *\([0-9.]*\).*$/\1/p' /proc/driver/nvidia/version 2>/dev/null || true)
echo "Current installed Nvidia driver version is ${NVIDIA_DRIVER_VERSION}"
if [ $(verlte "$CUDA_COMPAT_MAX_DRIVER_VERSION" "$NVIDIA_DRIVER_VERSION") ]; then
echo "Setup CUDA compatibility libs path to LD_LIBRARY_PATH"
export LD_LIBRARY_PATH=/usr/local/cuda/compat:$LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH
else
echo "Skip CUDA compat libs setup as newer Nvidia driver is installed"
fi
else
echo "Skip CUDA compat libs setup as package not found"
fi
if [[ -z "${HF_MODEL_ID}" ]]; then
echo "HF_MODEL_ID must be set"
exit 1
fi
export MODEL_ID="${HF_MODEL_ID}"
if [[ -n "${HF_MODEL_REVISION}" ]]; then
export REVISION="${HF_MODEL_REVISION}"
fi
if ! command -v nvidia-smi &> /dev/null; then
echo "Error: 'nvidia-smi' command not found."
exit 1
fi
# Query GPU name using nvidia-smi
gpu_name=$(nvidia-smi --query-gpu=gpu_name --format=csv | awk 'NR==2')
if [ $? -ne 0 ]; then
echo "Error: $gpu_name"
echo "Query gpu_name failed"
else
echo "Query gpu_name succeeded. Printing output: $gpu_name"
fi
# Function to get compute capability based on GPU name
get_compute_cap() {
gpu_name="$1"
# Check if the GPU name contains "A10G"
if [[ "$gpu_name" == *"A10G"* ]]; then
echo "86"
# Check if the GPU name contains "A100"
elif [[ "$gpu_name" == *"A100"* ]]; then
echo "80"
# Check if the GPU name contains "H100"
elif [[ "$gpu_name" == *"H100"* ]]; then
echo "90"
# Cover Nvidia T4
elif [[ "$gpu_name" == *"T4"* ]]; then
echo "75"
# Cover Nvidia L4
elif [[ "$gpu_name" == *"L4"* ]]; then
echo "89"
else
echo "80" # Default compute capability
fi
}
if [[ -z "${CUDA_COMPUTE_CAP}" ]]
then
compute_cap=$(get_compute_cap "$gpu_name")
echo "the compute_cap is $compute_cap"
else
compute_cap=$CUDA_COMPUTE_CAP
fi
if [[ ${compute_cap} -eq 75 ]]
then
text-embeddings-router-75 --port 8080 --json-output
elif [[ ${compute_cap} -ge 80 && ${compute_cap} -lt 90 ]]
then
text-embeddings-router-80 --port 8080 --json-output
elif [[ ${compute_cap} -eq 90 ]]
then
text-embeddings-router-90 --port 8080 --json-output
else
echo "cuda compute cap ${compute_cap} is not supported"; exit 1
fi