services:
  compute-api:
    image: ${COMPUTE_API_IMAGE:-yg-ft-compute-api:latest}
    container_name: yg-ft-compute-api
    gpus: all
    ports:
      - "${COMPUTE_API_PORT:-19100}:9100"
      - "${FILE_GATEWAY_PORT:-19101}:9100"
    environment:
      COMPUTE_ENV: ${COMPUTE_ENV:-prod}
      COMPUTE_HOST_ID: ${COMPUTE_HOST_ID:-gpu-node-01}
      COMPUTE_EXECUTION_MODE: ${COMPUTE_EXECUTION_MODE:-real}
      MODELTF_ROUTE_PREFIX: ${MODELTF_ROUTE_PREFIX:-/modelTF}
      COMPUTE_AUTH_ENABLED: ${COMPUTE_AUTH_ENABLED:-true}
      COMPUTE_SERVICE_TOKEN: ${COMPUTE_SERVICE_TOKEN:-change_me}
      ENABLE_APP_CALLBACK: ${ENABLE_APP_CALLBACK:-false}
      LLAMA_FACTORY_HOME: ${LLAMA_FACTORY_HOME:-/app/LLaMA-Factory}
      YG_FT_DATA_ROOT: ${YG_FT_DATA_ROOT:-/data/yg-ft}
      YG_FT_MODEL_ROOT: ${YG_FT_MODEL_ROOT:-/data/yg-ft/models}
      YG_FT_DATASET_ROOT: ${YG_FT_DATASET_ROOT:-/data/yg-ft/datasets}
      YG_FT_OUTPUT_ROOT: ${YG_FT_OUTPUT_ROOT:-/data/yg-ft/outputs}
      TRAINING_LOG_ROOT: ${TRAINING_LOG_ROOT:-/opt/yg-ft/logs/training}
      COMPUTE_GPU_COUNT: ${COMPUTE_GPU_COUNT:-0}
      COMPUTE_GPU_NAME: ${COMPUTE_GPU_NAME:-NVIDIA A800-SXM4-80GB}
      COMPUTE_GPU_MEMORY_GB: ${COMPUTE_GPU_MEMORY_GB:-80}
      COMPUTE_GPU_POWER_LIMIT_W: ${COMPUTE_GPU_POWER_LIMIT_W:-300}
      MIN_TRAINING_GPU_MEMORY_GB: ${MIN_TRAINING_GPU_MEMORY_GB:-4}
      LOG_DIR: ${LOG_DIR:-/opt/yg-ft/logs/compute}
      CUDA_VISIBLE_DEVICES: ${CUDA_VISIBLE_DEVICES:-all}
      NVIDIA_VISIBLE_DEVICES: ${NVIDIA_VISIBLE_DEVICES:-all}
      NVIDIA_DRIVER_CAPABILITIES: ${NVIDIA_DRIVER_CAPABILITIES:-compute,utility}
      PYTHONPATH: /app
    volumes:
      - ../../compute:/app/compute:ro
      - ${YG_FT_DATA_ROOT_HOST:-./data/yg-ft}:${YG_FT_DATA_ROOT:-/data/yg-ft}
      - ${YG_FT_MODEL_ROOT_HOST:-./data/yg-ft/models}:${YG_FT_MODEL_ROOT:-/data/yg-ft/models}
      - ${YG_FT_DATASET_ROOT_HOST:-./data/yg-ft/datasets}:${YG_FT_DATASET_ROOT:-/data/yg-ft/datasets}
      - ${YG_FT_OUTPUT_ROOT_HOST:-./data/yg-ft/outputs}:${YG_FT_OUTPUT_ROOT:-/data/yg-ft/outputs}
      - ${COMPUTE_LOG_ROOT_HOST:-./data/yg-ft/logs/compute}:${LOG_DIR:-/opt/yg-ft/logs/compute}
      - ${TRAINING_LOG_ROOT_HOST:-./data/yg-ft/logs/training}:${TRAINING_LOG_ROOT:-/opt/yg-ft/logs/training}
    networks:
      - yg-ft-compute
    healthcheck:
      test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:9100/modelTF/health', timeout=3).read()\""]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s
    restart: unless-stopped

networks:
  yg-ft-compute:
    name: yg-ft-compute
