1
+ #! /bin/bash
2
+
3
+ echo " ===> LocalAI All-in-One (AIO) container starting..."
4
+
5
+ GPU_ACCELERATION=false
6
+ GPU_VENDOR=" "
7
+
8
+ function detect_gpu() {
9
+ case " $( uname -s) " in
10
+ Linux)
11
+ if lspci | grep -E ' VGA|3D' | grep -iq nvidia; then
12
+ echo " NVIDIA GPU detected"
13
+ # nvidia-smi should be installed in the container
14
+ if nvidia-smi; then
15
+ GPU_ACCELERATION=true
16
+ GPU_VENDOR=nvidia
17
+ else
18
+ echo " NVIDIA GPU detected, but nvidia-smi is not installed. GPU acceleration will not be available."
19
+ fi
20
+ elif lspci | grep -E ' VGA|3D' | grep -iq amd; then
21
+ echo " AMD GPU detected"
22
+ # Check if ROCm is installed
23
+ if [ -d /opt/rocm ]; then
24
+ GPU_ACCELERATION=true
25
+ GPU_VENDOR=amd
26
+ else
27
+ echo " AMD GPU detected, but ROCm is not installed. GPU acceleration will not be available."
28
+ fi
29
+ elif lspci | grep -E ' VGA|3D' | grep -iq intel; then
30
+ echo " Intel GPU detected"
31
+ if [ -d /opt/intel ]; then
32
+ GPU_ACCELERATION=true
33
+ else
34
+ echo " Intel GPU detected, but Intel GPU drivers are not installed. GPU acceleration will not be available."
35
+ fi
36
+ fi
37
+ ;;
38
+ Darwin)
39
+ if system_profiler SPDisplaysDataType | grep -iq ' Metal' ; then
40
+ echo " Apple Metal supported GPU detected"
41
+ GPU_ACCELERATION=true
42
+ GPU_VENDOR=apple
43
+ fi
44
+ ;;
45
+ esac
46
+ }
47
+
48
+ function detect_gpu_size() {
49
+ if [ " $GPU_ACCELERATION " = true ]; then
50
+ GPU_SIZE=gpu-8g
51
+ fi
52
+
53
+ # Attempting to find GPU memory size for NVIDIA GPUs
54
+ if echo " $gpu_model " | grep -iq nvidia; then
55
+ echo " NVIDIA GPU detected. Attempting to find memory size..."
56
+ nvidia_sm=($( nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits) )
57
+ if [ ! -z " $nvidia_sm " ]; then
58
+ echo " Total GPU Memory: ${nvidia_sm[0]} MiB"
59
+ else
60
+ echo " Unable to determine NVIDIA GPU memory size."
61
+ fi
62
+ # if bigger than 8GB, use 16GB
63
+ # if [ "$nvidia_sm" -gt 8192 ]; then
64
+ # GPU_SIZE=gpu-16g
65
+ # fi
66
+ else
67
+ echo " Non-NVIDIA GPU detected. GPU memory size detection for non-NVIDIA GPUs is not supported in this script."
68
+ fi
69
+
70
+ # default to cpu if GPU_SIZE is not set
71
+ if [ -z " $GPU_SIZE " ]; then
72
+ GPU_SIZE=cpu
73
+ fi
74
+ }
75
+
76
+ function check_vars() {
77
+ if [ -z " $MODELS " ]; then
78
+ echo " MODELS environment variable is not set. Please set it to a comma-separated list of model YAML files to load."
79
+ exit 1
80
+ fi
81
+
82
+ if [ -z " $SIZE " ]; then
83
+ echo " SIZE environment variable is not set. Please set it to one of the following: cpu, gpu-8g, gpu-16g, apple"
84
+ exit 1
85
+ fi
86
+ }
87
+
88
+ detect_gpu
89
+ detect_gpu_size
90
+
91
+ SIZE=${SIZE:- $GPU_SIZE } # default to cpu
92
+ MODELS=${MODELS:-/ aio/ ${SIZE} / embeddings.yaml,/ aio/ ${SIZE} / text-to-speech.yaml,/ aio/ ${SIZE} / image-gen.yaml,/ aio/ ${SIZE} / text-to-text.yaml,/ aio/ ${SIZE} / speech-to-text.yaml,/ aio/ ${SIZE} / vision.yaml}
93
+
94
+ check_vars
95
+
96
+ echo " Starting LocalAI with the following models: $MODELS "
97
+
98
+ /build/entrypoint.sh " $@ "
0 commit comments