Triển khai toàn bộ service bằng một docker compose
chandra + kie (vLLM, weights mount từ CHANDRA_MODEL_DIR/KIE_MODEL_DIR) và api + worker (image build từ Dockerfile, network_mode host, đọc .env) thay cho hai tmux run-api.sh/run-worker.sh và docker run chandra riêng. Worker mount native-hdfs của gói portable, đợi hai model healthy mới nhận trang. GPU chọn bằng GPU_DEVICE (driver nvidia) thay cho CDI GPU_UUID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,32 +1,57 @@
|
||||
# Hai model của service trên cùng một card GPU:
|
||||
# chandra (DLA/OCR từng trang) → cổng ${PORT:-9222}, served name "chandra"
|
||||
# kie (bóc trường, Qwen3.5-4B) → cổng ${KIE_PORT:-9224}, served name "qwen3.5-4b"
|
||||
# Toàn bộ service trên một host, một card GPU: `cp .env.example .env`, sửa .env, rồi
|
||||
# docker compose up -d --build
|
||||
#
|
||||
# .env cần GPU_UUID (nvidia-smi -L). Mặc định hai model dùng ~80% card (GPU_UTIL 0.55 +
|
||||
# KIE_GPU_UTIL 0.3); card có tiến trình khác thì hạ tổng xuống dưới phần còn trống.
|
||||
# kie chỉ khởi động sau khi chandra healthy để hai vLLM không đo bộ nhớ GPU cùng lúc.
|
||||
# chandra DLA/OCR từng trang, vLLM cổng ${PORT:-9222}, served name "chandra"
|
||||
# kie bóc trường Qwen3.5-4B, vLLM cổng ${KIE_PORT:-9224}, served name "qwen3.5-4b"
|
||||
# api HTTP API cổng ${IDP_PORT:-8001}
|
||||
# worker hàng đợi trang, KIE, finalize, callback; tải PDF từ HDFS
|
||||
#
|
||||
# Weights chandra đóng sẵn trong image IMAGE_TAG. Weights Qwen nằm trong volume
|
||||
# ${KIE_VOLUME:-qwen35_4b}, nạp một lần từ snapshot HF (tar -h để theo symlink):
|
||||
# docker volume create qwen35_4b
|
||||
# tar -C <snapshot Qwen/Qwen3.5-4B> -chf - . | docker run --rm -i -v qwen35_4b:/model \
|
||||
# --entrypoint tar vllm/vllm-openai:v0.23.0 -C /model -xf -
|
||||
# api/worker chạy network_mode host nên .env giữ nguyên như khi chạy run-api.sh/run-worker.sh:
|
||||
# IDP_OCR_URL=http://127.0.0.1:9222/..., IDP_KIE_URL mặc định http://localhost:9224/...,
|
||||
# namenode/KDC phân giải theo /etc/hosts của host.
|
||||
# kie chỉ khởi động sau khi chandra healthy để hai vLLM không đo bộ nhớ GPU cùng lúc;
|
||||
# worker đợi cả hai model healthy mới nhận trang.
|
||||
|
||||
x-gpu: &gpu
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
device_ids: ["${GPU_DEVICE:-0}"] # như `docker run --gpus device=0`
|
||||
capabilities: [gpu]
|
||||
|
||||
x-vllm-env: &vllm-env
|
||||
HF_HUB_OFFLINE: "1"
|
||||
TRANSFORMERS_OFFLINE: "1"
|
||||
VLLM_LOGGING_LEVEL: "${VLLM_LOG_LEVEL:-INFO}"
|
||||
|
||||
x-health: &health
|
||||
test: ["CMD-SHELL", "python3 -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 600s
|
||||
|
||||
x-app: &app
|
||||
image: ${APP_IMAGE:-idp-parsing-service:0.2.0}
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
env_file: .env
|
||||
|
||||
services:
|
||||
chandra:
|
||||
image: ${IMAGE_TAG:-chandra-dla-api:v2-20260906-024126}
|
||||
container_name: chandra-ocr
|
||||
restart: unless-stopped
|
||||
gpus: &gpu
|
||||
- driver: cdi
|
||||
device_ids: ["nvidia.com/gpu=${GPU_UUID:?dat GPU_UUID trong .env}"]
|
||||
deploy: *gpu
|
||||
ipc: host
|
||||
shm_size: "16gb"
|
||||
ports:
|
||||
- "${PORT:-9222}:8000"
|
||||
environment: &env
|
||||
HF_HUB_OFFLINE: "1"
|
||||
TRANSFORMERS_OFFLINE: "1"
|
||||
VLLM_LOGGING_LEVEL: "${VLLM_LOG_LEVEL:-INFO}"
|
||||
environment: *vllm-env
|
||||
volumes:
|
||||
- ${CHANDRA_MODEL_DIR:?dat CHANDRA_MODEL_DIR trong .env}:/model:ro
|
||||
command:
|
||||
- --model=/model
|
||||
- --served-model-name=chandra
|
||||
@@ -41,12 +66,7 @@ services:
|
||||
- --seed=42
|
||||
# PHẢI khớp lúc train (IMAGE_MAX_TOKEN_NUM=1792) — đổi là bbox lệch.
|
||||
- --mm-processor-kwargs={"min_pixels":65536,"max_pixels":1835008}
|
||||
healthcheck: &health
|
||||
test: ["CMD-SHELL", "python3 -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 20
|
||||
start_period: 600s
|
||||
healthcheck: *health
|
||||
|
||||
kie:
|
||||
image: ${KIE_IMAGE:-vllm/vllm-openai:v0.23.0}
|
||||
@@ -55,14 +75,14 @@ services:
|
||||
depends_on:
|
||||
chandra:
|
||||
condition: service_healthy
|
||||
gpus: *gpu
|
||||
deploy: *gpu
|
||||
ipc: host
|
||||
shm_size: "8gb"
|
||||
ports:
|
||||
- "${KIE_PORT:-9224}:8000"
|
||||
environment: *env
|
||||
environment: *vllm-env
|
||||
volumes:
|
||||
- kie_model:/model:ro
|
||||
- ${KIE_MODEL_DIR:?dat KIE_MODEL_DIR trong .env}:/model:ro
|
||||
command:
|
||||
- --model=/model
|
||||
- --served-model-name=qwen3.5-4b
|
||||
@@ -80,7 +100,31 @@ services:
|
||||
- --mm-processor-kwargs={"min_pixels":65536,"max_pixels":1835008}
|
||||
healthcheck: *health
|
||||
|
||||
volumes:
|
||||
kie_model:
|
||||
external: true
|
||||
name: ${KIE_VOLUME:-qwen35_4b}
|
||||
api:
|
||||
<<: *app
|
||||
container_name: idp-api
|
||||
environment:
|
||||
IDP_DATA_DIR: ${IDP_DATA_DIR:-/data/idp-runtime}
|
||||
volumes:
|
||||
# Cùng đường dẫn trong và ngoài container; SQLite phải nằm trên đĩa local, không NFS.
|
||||
- ${IDP_DATA_DIR:-/data/idp-runtime}:${IDP_DATA_DIR:-/data/idp-runtime}
|
||||
command: ["uvicorn", "idp_service.api:app", "--host=${IDP_HOST:-0.0.0.0}", "--port=${IDP_PORT:-8001}"]
|
||||
|
||||
worker:
|
||||
<<: *app
|
||||
container_name: idp-worker
|
||||
depends_on:
|
||||
chandra:
|
||||
condition: service_healthy
|
||||
kie:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
IDP_DATA_DIR: ${IDP_DATA_DIR:-/data/idp-runtime}
|
||||
# Như run-worker.sh: client HDFS native (Java, Hadoop, conf, keytab) lấy từ gói portable.
|
||||
PATH: /opt/native-hdfs/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
KRB5_CONFIG: /opt/native-hdfs/conf/krb5.conf
|
||||
HDFS_KEYTAB: /opt/native-hdfs/conf/searchengine.headless.keytab
|
||||
volumes:
|
||||
- ${IDP_DATA_DIR:-/data/idp-runtime}:${IDP_DATA_DIR:-/data/idp-runtime}
|
||||
- ${HDFS_NATIVE_DIR:-./native-hdfs}:/opt/native-hdfs:ro
|
||||
command: ["python", "-m", "idp_service.worker"]
|
||||
|
||||
Reference in New Issue
Block a user