File size: 2,031 Bytes
d0ef71c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4973b5
 
 
d0ef71c
 
 
 
b4973b5
 
 
 
 
 
 
 
2e464cc
 
b4973b5
2e464cc
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
#!/bin/bash
set -eo pipefail

echo "=========================================================="
echo " vLLM dual-model + PP-DocLayoutV3 (CPU) on HF Space (T4) "
echo "=========================================================="

# 1. GPU & CUDA environment validation
echo "[1/4] Validating GPU and CUDA environment..."
if ! python3 /scripts/gpu_detect.py; then
    echo "[CRITICAL ERROR] GPU environment validation failed."
    echo "Deployment requires >= ${MIN_VRAM_MB:-15000} MB VRAM and CUDA >= ${MIN_CUDA_MAJOR:-11}.${MIN_CUDA_MINOR:-8}."
    exit 1
fi
echo "[OK] GPU environment verified."

# 2. Authentication configuration
echo "[2/4] Configuring Nginx Basic Authentication..."
if [ -z "${NGINX_PASSWORD:-}" ]; then
    echo "[CRITICAL ERROR] NGINX_PASSWORD is not defined."
    echo "Set NGINX_PASSWORD in Hugging Face Space Secrets."
    exit 1
fi
python3 /scripts/generate_htpasswd.py
echo "[OK] Nginx authentication configured."

# 3. Model cache on LOCAL disk (fast); /data bucket stays mounted for other persistent data
echo "[3/5] Preparing local model cache at ${HF_HOME:-/tmp/hf}..."
mkdir -p "${HF_HOME:-/tmp/hf}" \
         /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi \
         /tmp/torch_extensions /tmp/.cache /var/log/nginx
echo "[OK] Cache directory ready."

# 4. Preload models from the HF Hub (hf_xet, fast, parallel) into local disk — avoids
#    slow reads through the FUSE-mounted bucket (was ~12 Mo/s, >10 min per model)
echo "[4/5] Preloading models from HF Hub into ${HF_HOME:-/tmp/hf} (hf_xet)..."
if ! /scripts/preload_models.sh; then
    echo "[WARNING] preload failed; vLLM will fall back to downloading on the fly"
fi

# 5. Hand over to supervisord: vllm-ocr, layout (CPU), vllm-vlm, warmup, nginx
# supervisord comes from pip (/usr/local/bin, Python 3.12 compatible), NOT from apt
# (the apt package 4.2.1 crashes on Python 3.12: asynchat was removed from the stdlib)
echo "[5/5] Starting supervisord..."
exec supervisord -n -c /etc/supervisord.conf