From c542e118f7576f999ec79eb075eb9d53dced554a Mon Sep 17 00:00:00 2001 From: luslucifer Date: Fri, 19 Dec 2025 19:58:13 -0500 Subject: [PATCH 1/2] docker added --- .dockerignore | 25 +++++++++++++++++++++++++ Dockerfile | 34 ++++++++++++++++++++++++++++++++++ README.md | 27 +++++++++++++++++++++++++++ docker-compose.yml | 22 ++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml 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..822b1c3c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +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 + device_requests: + - driver: nvidia + count: all + capabilities: [gpu] + stdin_open: true + tty: true + command: bash From a8e5a9ad89988f2a3c8c5b299f7c1a38063d5e9d Mon Sep 17 00:00:00 2001 From: luslucifer Date: Fri, 19 Dec 2025 19:59:15 -0500 Subject: [PATCH 2/2] docker added --- docker-compose.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 822b1c3c..b89468ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,10 +13,7 @@ services: - ${HOME}/.cache/huggingface:/root/.cache/huggingface environment: HF_HOME: /root/.cache/huggingface - device_requests: - - driver: nvidia - count: all - capabilities: [gpu] + gpus: all stdin_open: true tty: true command: bash