x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  vllm:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}vllm/vllm-openai:${VLLM_VERSION:-v0.13.0}
    ports:
      - '${VLLM_PORT_OVERRIDE:-8000}:8000'
    volumes:
      - vllm_models:/root/.cache/huggingface
    environment:
      - TZ=${TZ:-UTC}
      - HF_TOKEN=${HF_TOKEN:-}
    command:
      - --model
      - ${VLLM_MODEL:-facebook/opt-125m}
      - --host
      - 0.0.0.0
      - --port
      - '8000'
      - --max-model-len
      - '${VLLM_MAX_MODEL_LEN:-2048}'
      - --gpu-memory-utilization
      - '${VLLM_GPU_MEMORY_UTIL:-0.9}'
    deploy:
      resources:
        limits:
          cpus: ${VLLM_CPU_LIMIT:-4.0}
          memory: ${VLLM_MEMORY_LIMIT:-8G}
        reservations:
          cpus: ${VLLM_CPU_RESERVATION:-0.1}
          memory: ${VLLM_MEMORY_RESERVATION:-4G}
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    shm_size: 4g
    healthcheck:
      test: [CMD, curl, -f, 'http://localhost:8000/health']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

volumes:
  vllm_models:
