|
#!/bin/bash |
|
|
|
echo "===> LocalAI All-in-One (AIO) container starting..." |
|
|
|
GPU_ACCELERATION=false |
|
GPU_VENDOR="" |
|
|
|
function check_intel() { |
|
if lspci | grep -E 'VGA|3D' | grep -iq intel; then |
|
echo "Intel GPU detected" |
|
if [ -d /opt/intel ]; then |
|
GPU_ACCELERATION=true |
|
GPU_VENDOR=intel |
|
else |
|
echo "Intel GPU detected, but Intel GPU drivers are not installed. GPU acceleration will not be available." |
|
fi |
|
fi |
|
} |
|
|
|
function check_nvidia_wsl() { |
|
if lspci | grep -E 'VGA|3D' | grep -iq "Microsoft Corporation Device 008e"; then |
|
|
|
|
|
echo "NVIDIA GPU detected via WSL2" |
|
|
|
if nvidia-smi; then |
|
GPU_ACCELERATION=true |
|
GPU_VENDOR=nvidia |
|
else |
|
echo "NVIDIA GPU detected via WSL2, but nvidia-smi is not installed. GPU acceleration will not be available." |
|
fi |
|
fi |
|
} |
|
|
|
function check_amd() { |
|
if lspci | grep -E 'VGA|3D' | grep -iq amd; then |
|
echo "AMD GPU detected" |
|
|
|
if [ -d /opt/rocm ]; then |
|
GPU_ACCELERATION=true |
|
GPU_VENDOR=amd |
|
else |
|
echo "AMD GPU detected, but ROCm is not installed. GPU acceleration will not be available." |
|
fi |
|
fi |
|
} |
|
|
|
function check_nvidia() { |
|
if lspci | grep -E 'VGA|3D' | grep -iq nvidia; then |
|
echo "NVIDIA GPU detected" |
|
|
|
if nvidia-smi; then |
|
GPU_ACCELERATION=true |
|
GPU_VENDOR=nvidia |
|
else |
|
echo "NVIDIA GPU detected, but nvidia-smi is not installed. GPU acceleration will not be available." |
|
fi |
|
fi |
|
} |
|
|
|
function check_metal() { |
|
if system_profiler SPDisplaysDataType | grep -iq 'Metal'; then |
|
echo "Apple Metal supported GPU detected" |
|
GPU_ACCELERATION=true |
|
GPU_VENDOR=apple |
|
fi |
|
} |
|
|
|
function detect_gpu() { |
|
case "$(uname -s)" in |
|
Linux) |
|
check_nvidia |
|
check_amd |
|
check_intel |
|
check_nvidia_wsl |
|
;; |
|
Darwin) |
|
check_metal |
|
;; |
|
esac |
|
} |
|
|
|
function detect_gpu_size() { |
|
|
|
if [ "$GPU_ACCELERATION" = true ] && [ "$GPU_VENDOR" = "nvidia" ]; then |
|
echo "NVIDIA GPU detected. Attempting to find memory size..." |
|
|
|
|
|
nvidia_sm=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits | head -n 1) |
|
if [ ! -z "$nvidia_sm" ]; then |
|
echo "Total GPU Memory: $nvidia_sm MiB" |
|
|
|
|
|
|
|
|
|
GPU_SIZE=gpu-8g |
|
|
|
else |
|
echo "Unable to determine NVIDIA GPU memory size. Falling back to CPU." |
|
GPU_SIZE=gpu-8g |
|
fi |
|
elif [ "$GPU_ACCELERATION" = true ] && [ "$GPU_VENDOR" = "intel" ]; then |
|
GPU_SIZE=intel |
|
|
|
elif [ "$GPU_ACCELERATION" = true ]; then |
|
echo "Non-NVIDIA GPU detected. Specific GPU memory size detection is not implemented." |
|
GPU_SIZE=gpu-8g |
|
|
|
|
|
else |
|
echo "GPU acceleration is not enabled or supported. Defaulting to CPU." |
|
GPU_SIZE=cpu |
|
fi |
|
} |
|
|
|
function check_vars() { |
|
if [ -z "$MODELS" ]; then |
|
echo "MODELS environment variable is not set. Please set it to a comma-separated list of model YAML files to load." |
|
exit 1 |
|
fi |
|
|
|
if [ -z "$PROFILE" ]; then |
|
echo "PROFILE environment variable is not set. Please set it to one of the following: cpu, gpu-8g, gpu-16g, apple" |
|
exit 1 |
|
fi |
|
} |
|
|
|
detect_gpu |
|
detect_gpu_size |
|
|
|
PROFILE="${PROFILE:-$GPU_SIZE}" |
|
export MODELS="${MODELS:-/aio/${PROFILE}/embeddings.yaml,/aio/${PROFILE}/rerank.yaml,/aio/${PROFILE}/text-to-speech.yaml,/aio/${PROFILE}/image-gen.yaml,/aio/${PROFILE}/text-to-text.yaml,/aio/${PROFILE}/speech-to-text.yaml,/aio/${PROFILE}/vision.yaml}" |
|
|
|
check_vars |
|
|
|
echo "===> Starting LocalAI[$PROFILE] with the following models: $MODELS" |
|
|
|
exec /build/entrypoint.sh "$@" |
|
|