UnisMindMap/scripts/start-mindmap.sh

40 lines
1.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
DOCKER=${DOCKER:-docker}
API_FLAVOR=${API_FLAVOR:-corex}
VERSION=${VERSION:-2.7.6}
NETWORK=${NETWORK:-unis-ai}
API_NAME=${API_NAME:-mineru-276-api}
WEB_NAME=${WEB_NAME:-mindmap-276-web}
WEB_PORT=${WEB_PORT:-9898}
API_PORT=${API_PORT:-8100}
MINERU_MODEL_DIR=${MINERU_MODEL_DIR:-/data/unis/mineru-models}
case "$API_FLAVOR" in
cuda)
GPU_ARGS=(--gpus "device=${GPU_IDS:-0}")
;;
corex)
GPU_ARGS=(--privileged --pid=host --group-add video
-v /dev:/dev -v /usr/src:/usr/src:ro -v /lib/modules:/lib/modules:ro
-e MINERU_VLLM_DEVICE=corex -e "CUDA_VISIBLE_DEVICES=${GPU_IDS:-0}")
;;
*) echo 'API_FLAVOR must be corex or cuda.' >&2; exit 1 ;;
esac
for name in "$API_NAME" "$WEB_NAME"; do
if "$DOCKER" container inspect "$name" >/dev/null 2>&1; then
echo "Container $name already exists. Set a new name or manage it explicitly." >&2
exit 1
fi
done
if [ ! -d "$MINERU_MODEL_DIR/pipeline" ] || [ ! -d "$MINERU_MODEL_DIR/vlm" ]; then
echo 'Prepare the pipeline and vlm model directories before starting.' >&2
exit 1
fi
"$DOCKER" network inspect "$NETWORK" >/dev/null 2>&1 || "$DOCKER" network create "$NETWORK"
"$DOCKER" run -d --name "$API_NAME" --network "$NETWORK" "${GPU_ARGS[@]}" --ipc=host --shm-size=32g \
-p "127.0.0.1:${API_PORT}:8000" -v "${MINERU_MODEL_DIR}:/models:ro" \
-e MINERU_MODEL_SOURCE=local -e "MINERU_GPU_MEMORY_UTILIZATION=${MINERU_GPU_MEMORY_UTILIZATION:-0.5}" \
"unis-mindmap-api:${VERSION}-${API_FLAVOR}"
"$DOCKER" run -d --name "$WEB_NAME" --network "$NETWORK" -p "${WEB_PORT}:9898" \
-e "MINERU_API_URL=http://${API_NAME}:8000" "unis-mindmap-web:${VERSION}"