From 47cc38bb35a73bf8b9b1fc47912309c3894a0e5c Mon Sep 17 00:00:00 2001 From: sueszli Date: Mon, 16 Sep 2024 15:43:07 +0200 Subject: [PATCH] dockerize project --- Dockerfile.cpu | 18 ++++++++++++++++++ Dockerfile.gpu | 17 +++++++++++++++++ docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ docker.sh | 12 ++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 Dockerfile.cpu create mode 100644 Dockerfile.gpu create mode 100644 docker-compose.yml create mode 100755 docker.sh diff --git a/Dockerfile.cpu b/Dockerfile.cpu new file mode 100644 index 00000000000..01679397b8e --- /dev/null +++ b/Dockerfile.cpu @@ -0,0 +1,18 @@ +FROM --platform=linux/amd64 ubuntu:20.04 + +RUN apt-get update && apt-get install -y libjpeg-dev libpng-dev build-essential git python3 python3-pip + +RUN pip3 install --upgrade pip +RUN pip3 install torch +RUN pip3 install aiofiles aiohttp auditwheel av defusedxml docutils gdown h5py ipython lmdb matplotlib numpy pandas Pillow pycocotools pytest pytorch_sphinx_theme Requests scipy setuptools Sphinx sphinx_gallery tabulate torch torchdata tqdm + +ENV FORCE_CUDA="0" +ENV TORCH_CUDA_ARCH_LIST="" +ENV USE_CUDA="0" + +COPY . /workspace +WORKDIR /workspace +RUN chmod +x /workspace/setup.py +RUN python3 /workspace/setup.py develop + +CMD ["tail", "-f", "/dev/null"] diff --git a/Dockerfile.gpu b/Dockerfile.gpu new file mode 100644 index 00000000000..8054cedf776 --- /dev/null +++ b/Dockerfile.gpu @@ -0,0 +1,17 @@ +FROM pytorch/pytorch:1.7.0-cuda11.0-cudnn8-devel + +RUN apt-get update && apt-get install -y libjpeg-dev libpng-dev build-essential git + +RUN pip3 install --upgrade pip +RUN pip3 install aiofiles aiohttp auditwheel av defusedxml docutils gdown h5py ipython lmdb matplotlib numpy pandas Pillow pycocotools pytest pytorch_sphinx_theme Requests scipy setuptools Sphinx sphinx_gallery tabulate torchdata tqdm + +ENV FORCE_CUDA="1" +ENV TORCH_CUDA_ARCH_LIST="3.5 5.2 6.0 6.1 7.0+PTX" +ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all" + +COPY . /workspace +WORKDIR /workspace +RUN chmod +x /workspace/setup.py +RUN python3 /workspace/setup.py develop + +CMD ["tail", "-f", "/dev/null"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000000..ec9b6617752 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +# for mac arm chips see: +# - https://docs.docker.com/desktop/troubleshoot/known-issues/ + +# for nvidia gpus see: +# - https://github.com/NVIDIA/nvidia-container-toolkit +# - https://docs.docker.com/compose/gpu-support/ + +# compiling pip dependencies: +# +# $ pipreqs . --mode no-pin --encoding utf-8 +# $ mv requirements.txt requirements.in +# $ pip-compile requirements.in -o requirements.txt -vvv + +# usage: cpu +# +# $ docker-compose build +# $ docker-compose up + +# usage: gpu +# +# $ BUILD_TYPE=gpu docker-compose build +# $ BUILD_TYPE=gpu docker-compose up + +services: + main: + container_name: main + volumes: + - type: bind + source: . + target: /workspace + working_dir: /workspace + build: + context: . + dockerfile: Dockerfile.${DOCKER_FILE_SUFFIX:-cpu} + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [gpu] + environment: + - NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all} + - NVIDIA_DRIVER_CAPABILITIES=${NVIDIA_DRIVER_CAPABILITIES:-compute,utility} diff --git a/docker.sh b/docker.sh new file mode 100755 index 00000000000..4d274890576 --- /dev/null +++ b/docker.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if command -v nvidia-smi &> /dev/null && nvidia-smi &> /dev/null +then + echo "NVIDIA GPU detected" + export DOCKER_FILE_SUFFIX=gpu +else + echo "No NVIDIA GPU detected" + export DOCKER_FILE_SUFFIX=cpu +fi + +docker-compose up --build