diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..374c4774 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +.git +.gitignore +.github + +__pycache__/ +*.pyc +*.pyo +*.pyd + +.pytest_cache/ +.mypy_cache/ +.ruff_cache/ +.venv/ +.ipynb_checkpoints/ + +build/ +dist/ +*.egg-info/ +.eggs/ + +checkpoints/ +outputs/ +*.pt +*.pth +*.ckpt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..65d93562 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM python:3.12-slim + +ARG TORCH_VERSION=2.7.0 +ARG TORCH_INDEX_URL=https://download.pytorch.org/whl/cu126 +ARG SAM3_EXTRAS="" + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_NO_CACHE_DIR=1 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + git \ + libgl1 \ + libglib2.0-0 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Install torch early to leverage Docker layer caching. +RUN python -m pip install --upgrade pip \ + && pip install torch==${TORCH_VERSION} torchvision torchaudio --index-url ${TORCH_INDEX_URL} + +COPY . /app + +RUN if [ -n "${SAM3_EXTRAS}" ]; then \ + pip install -e ".[${SAM3_EXTRAS}]"; \ + else \ + pip install -e .; \ + fi + +CMD ["bash"] diff --git a/README.md b/README.md index 669242df..ff09390f 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,33 @@ pip install -e ".[notebooks]" pip install -e ".[train,dev]" ``` +### Docker (GPU) + +Build the image (defaults to CUDA 12.6 wheels): + +```bash +docker build -t sam3:latest . +``` + +Run with GPU access: + +```bash +docker run --gpus all -it --rm \ + -v "$(pwd)":/app \ + -v "$HOME/.cache/huggingface":/root/.cache/huggingface \ + sam3:latest +``` + +Optional build args: + +```bash +# CPU-only wheels +docker build --build-arg TORCH_INDEX_URL=https://download.pytorch.org/whl/cpu -t sam3:cpu . + +# Install extras (comma-separated) +docker build --build-arg SAM3_EXTRAS=train,dev -t sam3:train . +``` + ## Getting Started ⚠️ Before using SAM 3, please request access to the checkpoints on the SAM 3 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b89468ae --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +services: + sam3: + build: + context: . + args: + TORCH_VERSION: "2.7.0" + TORCH_INDEX_URL: "https://download.pytorch.org/whl/cu126" + SAM3_EXTRAS: "" + image: sam3:latest + working_dir: /app + volumes: + - .:/app + - ${HOME}/.cache/huggingface:/root/.cache/huggingface + environment: + HF_HOME: /root/.cache/huggingface + gpus: all + stdin_open: true + tty: true + command: bash