From edcf85555f851586e7ba832eb36d49e708ebf206 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 15 Mar 2023 20:30:03 +0100 Subject: [PATCH 01/17] Dockerfile: Use virtual environment python3-pip can now be removed, and running pip instead of pip3 is sufficient. This also avoids the installation of python3-setuptools and python3-wheel (requirements of python3-pip). Signed-off-by: Stefan Weil --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b23842ee..a6008feb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV DEBIAN_FRONTEND noninteractive ENV PYTHONIOENCODING utf8 ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 -ENV PIP=pip3 +ENV PIP=pip WORKDIR /build-ocrd COPY ocrd ./ocrd @@ -23,7 +23,6 @@ RUN apt-get update && apt-get -y install software-properties-common \ && apt-get update && apt-get -y install \ ca-certificates \ python3-dev \ - python3-pip \ python3-venv \ gcc \ make \ @@ -33,7 +32,8 @@ RUN apt-get update && apt-get -y install software-properties-common \ sudo \ git \ && make deps-ubuntu \ - && pip3 install --upgrade pip setuptools \ + && python3 -m venv /usr/local \ + && pip install --upgrade pip setuptools \ && make install \ && apt-get remove -y gcc \ && apt-get autoremove -y \ From 5c003fa3dca79b2c0de1e65da47d4bac5c8870eb Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 1 Apr 2023 11:10:37 +0200 Subject: [PATCH 02/17] give up workaround for shapely-CUDA issue --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 72a9bb765..4d43130d5 100644 --- a/Makefile +++ b/Makefile @@ -72,8 +72,6 @@ install: @# speedup for end-of-life builds if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) install --prefer-binary opencv-python-headless numpy; fi for mod in $(BUILD_ORDER);do (cd $$mod ; $(PIP_INSTALL) .);done - @# workaround for shapely#1598 - $(PIP) install --no-binary shapely --force-reinstall shapely # Install with pip install -e install-dev: uninstall From 2250550d85b626da18ca8050f0ed8997eba6a8fd Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 1 Apr 2023 11:12:00 +0200 Subject: [PATCH 03/17] rehash after pip upgrade --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 6b23842ee..f425bb82b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ RUN apt-get update && apt-get -y install software-properties-common \ git \ && make deps-ubuntu \ && pip3 install --upgrade pip setuptools \ + && hash -r \ && make install \ && apt-get remove -y gcc \ && apt-get autoremove -y \ From 00a0f6f6f72817239f6f6214e72c9a79e1d29478 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 1 Apr 2023 11:12:36 +0200 Subject: [PATCH 04/17] keep gcc, no autoremove --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f425bb82b..720c4d3b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,8 +36,6 @@ RUN apt-get update && apt-get -y install software-properties-common \ && pip3 install --upgrade pip setuptools \ && hash -r \ && make install \ - && apt-get remove -y gcc \ - && apt-get autoremove -y \ && $FIXUP \ && rm -rf /build-ocrd From 410783f4767882d3b73574dfe6866f788360ada3 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 1 Apr 2023 11:13:37 +0200 Subject: [PATCH 05/17] docker-cuda: change base image, no multi-CUDA runtimes --- Dockerfile | 4 ++++ Makefile | 35 ++++++----------------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 720c4d3b6..52f8eb4a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,4 +41,8 @@ RUN apt-get update && apt-get -y install software-properties-common \ WORKDIR /data +# remove any entry points from base image +RUN rm -fr /opt/nvidia +ENTRYPOINT [] + CMD ["/usr/local/bin/ocrd", "--help"] diff --git a/Makefile b/Makefile index 4d43130d5..b907993be 100644 --- a/Makefile +++ b/Makefile @@ -214,38 +214,15 @@ pyclean: # Build docker image docker docker-cuda: - docker build -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) . + docker build --progress=plain -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) . # Build docker GPU / CUDA image -docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04 +# (we need *devel* for compilation via nvcc etc. of our dependencies inside the build, +# no good *cudnn* because it will not be used by pip installs, +# and cudnn-devel does not contain nvcc etc.) +# cf. https://github.com/NVIDIA/nvidia-docker/wiki/CUDA#description +docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.3.1-devel-ubuntu20.04 docker-cuda: DOCKER_TAG = ocrd/core-cuda -docker-cuda: DOCKER_ARGS += --build-arg FIXUP="make cuda-ubuntu cuda-ldconfig" - -# -# CUDA -# - -.PHONY: cuda-ubuntu cuda-ldconfig - -# Install native CUDA toolkit in different versions -cuda-ubuntu: cuda-ldconfig - apt-get -y install --no-install-recommends cuda-runtime-11-0 cuda-runtime-11-1 cuda-runtime-11-3 cuda-runtime-11-7 cuda-runtime-12-1 - -cuda-ldconfig: /etc/ld.so.conf.d/cuda.conf - ldconfig - -/etc/ld.so.conf.d/cuda.conf: - @echo > $@ - @echo /usr/local/cuda-11.0/lib64 >> $@ - @echo /usr/local/cuda-11.0/targets/x86_64-linux/lib >> $@ - @echo /usr/local/cuda-11.1/lib64 >> $@ - @echo /usr/local/cuda-11.1/targets/x86_64-linux/lib >> $@ - @echo /usr/local/cuda-11.3/lib64 >> $@ - @echo /usr/local/cuda-11.3/targets/x86_64-linux/lib >> $@ - @echo /usr/local/cuda-11.7/lib64 >> $@ - @echo /usr/local/cuda-11.7/targets/x86_64-linux/lib >> $@ - @echo /usr/local/cuda-12.1/lib64 >> $@ - @echo /usr/local/cuda-12.1/targets/x86_64-linux/lib >> $@ # Build wheels and source dist and twine upload them pypi: uninstall install From de86e0fc380c7786222f92f38b971824bb84af00 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Wed, 12 Apr 2023 17:24:26 +0200 Subject: [PATCH 06/17] reinstate workaround for shapely, but more robust --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index b907993be..ecaa44e4f 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,8 @@ install: @# speedup for end-of-life builds if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) install --prefer-binary opencv-python-headless numpy; fi for mod in $(BUILD_ORDER);do (cd $$mod ; $(PIP_INSTALL) .);done + @# workaround for shapely#1598 + $(PIP) config set global.no-binary shapely # Install with pip install -e install-dev: uninstall @@ -223,6 +225,7 @@ docker docker-cuda: # cf. https://github.com/NVIDIA/nvidia-docker/wiki/CUDA#description docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.3.1-devel-ubuntu20.04 docker-cuda: DOCKER_TAG = ocrd/core-cuda +docker-cuda: DOCKER_ARGS += --build-arg FIXUP="apt-get install libcudnn8" # Build wheels and source dist and twine upload them pypi: uninstall install From c1178f9076cbbcc8b45ce487bc39eb8739b82ed7 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 15 Apr 2023 23:11:56 +0200 Subject: [PATCH 07/17] core-cuda: use CUDA 11.8, install cuDNN via pip and make available system-wide via ld.so.conf --- Dockerfile | 2 +- Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 52f8eb4a2..b8b98c15b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN apt-get update && apt-get -y install software-properties-common \ && pip3 install --upgrade pip setuptools \ && hash -r \ && make install \ - && $FIXUP \ + && eval $FIXUP \ && rm -rf /build-ocrd WORKDIR /data diff --git a/Makefile b/Makefile index ecaa44e4f..28f43fca7 100644 --- a/Makefile +++ b/Makefile @@ -223,9 +223,9 @@ docker docker-cuda: # no good *cudnn* because it will not be used by pip installs, # and cudnn-devel does not contain nvcc etc.) # cf. https://github.com/NVIDIA/nvidia-docker/wiki/CUDA#description -docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.3.1-devel-ubuntu20.04 +docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.8.0-devel-ubuntu20.04 docker-cuda: DOCKER_TAG = ocrd/core-cuda -docker-cuda: DOCKER_ARGS += --build-arg FIXUP="apt-get install libcudnn8" +docker-cuda: DOCKER_ARGS += --build-arg FIXUP="pip3 install nvidia-pyindex && pip3 install nvidia-cudnn-cu11==8.6.0.163 && echo /usr/local/lib/python3.8/dist-packages/nvidia/cudnn/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && echo /usr/local/lib/python3.8/dist-packages/nvidia/cublas/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && ldconfig" # Build wheels and source dist and twine upload them pypi: uninstall install From d3d54bff959d0f812b651049bcb433eaeee3f333 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 21 Apr 2023 01:38:07 +0200 Subject: [PATCH 08/17] core-cuda: install more CUDA libs via pip and ld.so.conf, simplify Dockerfile for that --- Dockerfile | 20 ++++++++++++++++++++ Makefile | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b8b98c15b..5c2954bd8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ ARG BASE_IMAGE FROM $BASE_IMAGE +ARG BASE_IMAGE ARG FIXUP=echo MAINTAINER OCR-D ENV DEBIAN_FRONTEND noninteractive @@ -38,6 +39,25 @@ RUN apt-get update && apt-get -y install software-properties-common \ && make install \ && eval $FIXUP \ && rm -rf /build-ocrd +RUN if echo $BASE_IMAGE | fgrep -q cuda; then \ + pip3 install nvidia-pyindex && \ + pip3 install nvidia-cudnn-cu11==8.6.0.163 && \ + pip3 install nvidia-cublas-cu11 && \ + pip3 install nvidia-cusparse-cu11 && \ + pip3 install nvidia-cusolver-cu11 && \ + pip3 install nvidia-curand-cu11 && \ + pip3 install nvidia-cufft-cu11 && \ + pip3 install nvidia-cuda-runtime-cu11 && \ + pip3 install nvidia-cuda-nvrtc-cu11 && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cudnn/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cublas/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cusparse/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cusolver/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/curand/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cufft/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cuda_runtime/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + echo /usr/local/lib/python3.8/dist-packages/nvidia/cuda_nvrtc/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ + ldconfig; fi WORKDIR /data diff --git a/Makefile b/Makefile index 28f43fca7..91807cb02 100644 --- a/Makefile +++ b/Makefile @@ -225,7 +225,6 @@ docker docker-cuda: # cf. https://github.com/NVIDIA/nvidia-docker/wiki/CUDA#description docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.8.0-devel-ubuntu20.04 docker-cuda: DOCKER_TAG = ocrd/core-cuda -docker-cuda: DOCKER_ARGS += --build-arg FIXUP="pip3 install nvidia-pyindex && pip3 install nvidia-cudnn-cu11==8.6.0.163 && echo /usr/local/lib/python3.8/dist-packages/nvidia/cudnn/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && echo /usr/local/lib/python3.8/dist-packages/nvidia/cublas/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && ldconfig" # Build wheels and source dist and twine upload them pypi: uninstall install From 357e72984e80d84b6bcfd0bfa85c9e78f9b08c7e Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 21 Apr 2023 01:39:23 +0200 Subject: [PATCH 09/17] make install on py36: prefer binary OpenCV/Numpy via pip config instead of preinstall --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 91807cb02..bdf79eeee 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ deps-test: install: $(PIP) install -U pip wheel setuptools fastentrypoints @# speedup for end-of-life builds - if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) install --prefer-binary opencv-python-headless numpy; fi + if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) config set global.prefer-binary "opencv-python-headless numpy"; fi for mod in $(BUILD_ORDER);do (cd $$mod ; $(PIP_INSTALL) .);done @# workaround for shapely#1598 $(PIP) config set global.no-binary shapely From 2640b711c98ca5ae21ad9a3af463602ed26da116 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 21 Apr 2023 17:22:54 +0200 Subject: [PATCH 10/17] make install on py36: fix prefer-binary syntax --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bdf79eeee..8f7431a9f 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ deps-test: install: $(PIP) install -U pip wheel setuptools fastentrypoints @# speedup for end-of-life builds - if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) config set global.prefer-binary "opencv-python-headless numpy"; fi + if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) config set global.prefer-binary "opencv-python-headless=1 numpy=1"; fi for mod in $(BUILD_ORDER);do (cd $$mod ; $(PIP_INSTALL) .);done @# workaround for shapely#1598 $(PIP) config set global.no-binary shapely @@ -215,7 +215,7 @@ pyclean: .PHONY: docker docker-cuda # Build docker image -docker docker-cuda: +docker docker-cuda: docker build --progress=plain -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) . # Build docker GPU / CUDA image From b3618a98b770da287be55bf23d006787362e7782 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 21 Apr 2023 19:09:58 +0200 Subject: [PATCH 11/17] make install on py36: revert to prefer-binary via install --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8f7431a9f..35914b626 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,8 @@ deps-test: install: $(PIP) install -U pip wheel setuptools fastentrypoints @# speedup for end-of-life builds - if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) config set global.prefer-binary "opencv-python-headless=1 numpy=1"; fi + @# we cannot use pip config here due to pip#11988 + if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) install --prefer-binary opencv-python-headless numpy; fi for mod in $(BUILD_ORDER);do (cd $$mod ; $(PIP_INSTALL) .);done @# workaround for shapely#1598 $(PIP) config set global.no-binary shapely From a6cf5ff2ff62a421b0f764f3a00388edead14e6c Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Thu, 27 Apr 2023 15:11:08 +0200 Subject: [PATCH 12/17] core-cuda: use same CUDA libs as needed for Torch anyway --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 069cb0e0a..506bfa014 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,13 +43,13 @@ RUN apt-get update && apt-get -y install software-properties-common \ RUN if echo $BASE_IMAGE | fgrep -q cuda; then \ pip3 install nvidia-pyindex && \ pip3 install nvidia-cudnn-cu11==8.6.0.163 && \ - pip3 install nvidia-cublas-cu11 && \ - pip3 install nvidia-cusparse-cu11 && \ - pip3 install nvidia-cusolver-cu11 && \ - pip3 install nvidia-curand-cu11 && \ - pip3 install nvidia-cufft-cu11 && \ - pip3 install nvidia-cuda-runtime-cu11 && \ - pip3 install nvidia-cuda-nvrtc-cu11 && \ + pip3 install nvidia-cublas-cu117 && \ + pip3 install nvidia-cusparse-cu117 && \ + pip3 install nvidia-cusolver-cu117 && \ + pip3 install nvidia-curand-cu117 && \ + pip3 install nvidia-cufft-cu117 && \ + pip3 install nvidia-cuda-runtime-cu117 && \ + pip3 install nvidia-cuda-nvrtc-cu117 && \ echo /usr/local/lib/python3.8/site-packages/nvidia/cudnn/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ echo /usr/local/lib/python3.8/site-packages/nvidia/cublas/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ echo /usr/local/lib/python3.8/site-packages/nvidia/cusparse/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ From f5e212afbfd0c7043d8da91af196782b05dc407d Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Thu, 1 Jun 2023 20:14:07 +0200 Subject: [PATCH 13/17] =?UTF-8?q?docker-cuda:=20rewrite=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - extra Dockerfile.cuda instead of guessing from base image name - re-use non-CUDA ocrd/core instead of nvidia/cuda base image - install CUDA toolkit and libraries via (micro)mamba instead of nvidia-pyindex CUDA libraries made available system-wide - get cuDNN and CUDA libs from conda-forge and nvidia channels --- Dockerfile | 24 ------------------------ Dockerfile.cuda | 38 ++++++++++++++++++++++++++++++++++++++ Makefile | 33 ++++++++++++++------------------- 3 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 Dockerfile.cuda diff --git a/Dockerfile b/Dockerfile index 506bfa014..04df1e356 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ ARG BASE_IMAGE FROM $BASE_IMAGE -ARG BASE_IMAGE ARG FIXUP=echo MAINTAINER OCR-D ENV DEBIAN_FRONTEND noninteractive @@ -40,30 +39,7 @@ RUN apt-get update && apt-get -y install software-properties-common \ && make install \ && eval $FIXUP \ && rm -rf /build-ocrd -RUN if echo $BASE_IMAGE | fgrep -q cuda; then \ - pip3 install nvidia-pyindex && \ - pip3 install nvidia-cudnn-cu11==8.6.0.163 && \ - pip3 install nvidia-cublas-cu117 && \ - pip3 install nvidia-cusparse-cu117 && \ - pip3 install nvidia-cusolver-cu117 && \ - pip3 install nvidia-curand-cu117 && \ - pip3 install nvidia-cufft-cu117 && \ - pip3 install nvidia-cuda-runtime-cu117 && \ - pip3 install nvidia-cuda-nvrtc-cu117 && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cudnn/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cublas/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cusparse/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cusolver/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/curand/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cufft/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cuda_runtime/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - echo /usr/local/lib/python3.8/site-packages/nvidia/cuda_nvrtc/lib/ >> /etc/ld.so.conf.d/000_cuda.conf && \ - ldconfig; fi WORKDIR /data -# remove any entry points from base image -RUN rm -fr /opt/nvidia -ENTRYPOINT [] - CMD ["/usr/local/bin/ocrd", "--help"] diff --git a/Dockerfile.cuda b/Dockerfile.cuda new file mode 100644 index 000000000..a6c51a71f --- /dev/null +++ b/Dockerfile.cuda @@ -0,0 +1,38 @@ +ARG BASE_IMAGE +FROM $BASE_IMAGE + +ENV MAMBA_EXE=/usr/local/bin/conda +ENV MAMBA_ROOT_PREFIX=/conda +ENV PATH=$MAMBA_ROOT_PREFIX/bin:$PATH +ENV CONDA_PREFIX=$MAMBA_ROOT_PREFIX +ENV CONDA_SHLVL='1' + +WORKDIR $MAMBA_ROOT_PREFIX + +RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba +RUN mv bin/micromamba $MAMBA_EXE +RUN hash -r +RUN echo $CONDA_PREFIX/lib >> /etc/ld.so.conf.d/conda.conf +# get CUDA toolkit, including compiler and libraries with dev +# nvidia channels do not provide (recent) cudnn (needed for Torch, TF etc): +#RUN conda install -c nvidia/label/cuda-11.8.0 cuda && conda clean -a +# conda-forge has cudnn but no cudatoolkit-dev anymore +# so let's combine nvidia and conda-forge (will be same lib versions, no waste of space): +RUN conda install -c conda-forge \ + cudatoolkit=11.8.0 \ + cudnn=8.8.* && \ + conda clean -a && \ + find $CONDA_PREFIX -name "*_static.a" -delete +RUN conda install -c nvidia/label/cuda-11.8.0 \ + cuda-nvcc \ + cuda-cudart-dev \ + cuda-libraries-dev && \ + conda clean -a && \ + find $CONDA_PREFIX -name "*_static.a" -delete +# gputil/nvidia-smi would be nice, too – but that drags in Python as a conda dependency... +RUN ldconfig + +WORKDIR /data + +CMD ["/usr/local/bin/ocrd", "--help"] + diff --git a/Makefile b/Makefile index d87ccb8d9..ff28d1fc5 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,6 @@ help: @echo " docs-coverage Calculate docstring coverage" @echo " docker Build docker image" @echo " docker-cuda Build docker GPU / CUDA image" - @echo " cuda-ubuntu Install native CUDA toolkit in different versions" @echo " pypi Build wheels and source dist and twine upload them" @echo "" @echo " Variables" @@ -45,15 +44,6 @@ help: # END-EVAL -# Docker tag. Default: '$(DOCKER_TAG)'. -DOCKER_TAG = ocrd/core - -# Docker base image. Default: '$(DOCKER_BASE_IMAGE)'. -DOCKER_BASE_IMAGE = ubuntu:20.04 - -# Additional arguments to docker build. Default: '$(DOCKER_ARGS)' -DOCKER_ARGS = - # pip install command. Default: $(PIP_INSTALL) PIP_INSTALL = $(PIP) install @@ -215,17 +205,22 @@ pyclean: .PHONY: docker docker-cuda +# Additional arguments to docker build. Default: '$(DOCKER_ARGS)' +DOCKER_ARGS = + # Build docker image -docker docker-cuda: - docker build --progress=plain -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) . - -# Build docker GPU / CUDA image -# (we need *devel* for compilation via nvcc etc. of our dependencies inside the build, -# no good *cudnn* because it will not be used by pip installs, -# and cudnn-devel does not contain nvcc etc.) -# cf. https://github.com/NVIDIA/nvidia-docker/wiki/CUDA#description -docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.8.0-devel-ubuntu20.04 +docker: DOCKER_BASE_IMAGE = ubuntu:20.04 +docker: DOCKER_TAG = ocrd/core +docker: DOCKER_FILE = Dockerfile + +docker-cuda: DOCKER_BASE_IMAGE = ocrd/core docker-cuda: DOCKER_TAG = ocrd/core-cuda +docker-cuda: DOCKER_FILE = Dockerfile.cuda + +docker-cuda: docker + +docker docker-cuda: + docker build --progress=plain -f $(DOCKER_FILE) -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) . # Build wheels and source dist and twine upload them pypi: uninstall install From 85a5d16a3e37ae9ac33cd2193d62c4e32eaf4eb2 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 2 Jun 2023 02:36:50 +0200 Subject: [PATCH 14/17] =?UTF-8?q?docker-cuda:=20improve=20(reduce=20size)?= =?UTF-8?q?=20again=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - install CUDA libraries via nvidia-pyindex again (but not nvcc) - ensure they can be compiled/linked against system-wide (with nvcc) --- Dockerfile.cuda | 51 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/Dockerfile.cuda b/Dockerfile.cuda index a6c51a71f..c968ae9f4 100644 --- a/Dockerfile.cuda +++ b/Dockerfile.cuda @@ -12,26 +12,51 @@ WORKDIR $MAMBA_ROOT_PREFIX RUN curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba RUN mv bin/micromamba $MAMBA_EXE RUN hash -r +RUN mkdir -p $CONDA_PREFIX/lib $CONDA_PREFIX/include RUN echo $CONDA_PREFIX/lib >> /etc/ld.so.conf.d/conda.conf -# get CUDA toolkit, including compiler and libraries with dev -# nvidia channels do not provide (recent) cudnn (needed for Torch, TF etc): +# Get CUDA toolkit, including compiler and libraries with dev. +# The nvidia channels do not provide (recent) cudnn (needed for Torch, TF etc): #RUN conda install -c nvidia/label/cuda-11.8.0 cuda && conda clean -a -# conda-forge has cudnn but no cudatoolkit-dev anymore +# The conda-forge channel has cudnn but no cudatoolkit-dev anymore, # so let's combine nvidia and conda-forge (will be same lib versions, no waste of space): -RUN conda install -c conda-forge \ - cudatoolkit=11.8.0 \ - cudnn=8.8.* && \ - conda clean -a && \ - find $CONDA_PREFIX -name "*_static.a" -delete RUN conda install -c nvidia/label/cuda-11.8.0 \ - cuda-nvcc \ - cuda-cudart-dev \ - cuda-libraries-dev && \ - conda clean -a && \ - find $CONDA_PREFIX -name "*_static.a" -delete + cuda-nvcc \ + cuda-cccl \ + && conda clean -a \ + && find $CONDA_PREFIX -name "*_static.a" -delete + # cuda-cudart-dev \ + # cuda-libraries-dev \ +#RUN conda install -c conda-forge \ +# cudatoolkit=11.8.0 \ +# cudnn=8.8.* && \ +# conda clean -a && \ +# find $CONDA_PREFIX -name "*_static.a" -delete +# Since Torch will pull in the CUDA libraries (as Python pkgs) anyway, +# let's jump the shark and pull these via NGC index directly, +# but then share them with the rest of the system so native compilation/linking +# works, too: +RUN pip3 install nvidia-pyindex \ + && pip3 install nvidia-cudnn-cu11==8.6.0.163 \ + nvidia-cublas-cu11 \ + nvidia-cusparse-cu11 \ + nvidia-cusolver-cu11 \ + nvidia-curand-cu11 \ + nvidia-cufft-cu11 \ + nvidia-cuda-runtime-cu11 \ + nvidia-cuda-nvrtc-cu11 \ + && for pkg in cudnn cublas cusparse cusolver curand cufft cuda_runtime cuda_nvrtc; do \ + for lib in /usr/local/lib/python3.8/site-packages/nvidia/$pkg/lib/lib*.so.*; do \ + base=$(basename $lib); \ + ln -s $lib $CONDA_PREFIX/lib/$base.so; \ + ln -s $lib $CONDA_PREFIX/lib/${base%.so.*}.so; \ + done \ + && ln -s /usr/local/lib/python3.8/site-packages/nvidia/$pkg/include/* $CONDA_PREFIX/include/; \ + done \ + && ldconfig # gputil/nvidia-smi would be nice, too – but that drags in Python as a conda dependency... RUN ldconfig + WORKDIR /data CMD ["/usr/local/bin/ocrd", "--help"] From 47eff22f7a18928ff1bb56f734f63a3a033f6772 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 2 Jun 2023 03:58:58 +0200 Subject: [PATCH 15/17] remove out-dated processor resources --- ocrd/ocrd/resource_list.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/ocrd/ocrd/resource_list.yml b/ocrd/ocrd/resource_list.yml index fcedf8591..5a047daad 100644 --- a/ocrd/ocrd/resource_list.yml +++ b/ocrd/ocrd/resource_list.yml @@ -59,19 +59,3 @@ ocrd-sbb-binarize: type: archive path_in_archive: models size: 1654623597 -ocrd-sbb-textline-detector: - - url: https://qurator-data.de/sbb_textline_detector/models.tar.gz - description: default models provided by github.com/qurator-spk - name: default - type: archive - size: 1194551551 -ocrd-kraken-segment: - - url: https://github.com/mittagessen/kraken/raw/master/kraken/blla.mlmodel - description: Pretrained baseline segmentation model - name: blla.mlmodel - size: 5046835 -ocrd-kraken-recognize: - - url: https://zenodo.org/record/2577813/files/en_best.mlmodel?download=1 - name: en_best.mlmodel - description: This model has been trained on a large corpus of modern printed English text\naugmented with ~10000 lines of historical pages - size: 2930723 From 12e781c67812e7cda97659786d5b79ec2b3aa31a Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Fri, 2 Jun 2023 04:13:54 +0200 Subject: [PATCH 16/17] Revert "Merge remote-tracking branch 'hnesk/no-more-pkg_resources' into release-2.36.0" This reverts commit 9a54ef6ae95c84fcf9d0513afa732c4abc33e8eb, reversing changes made to a78d4c50e92b2acc8fcb0f18fdb23da366631b41. --- Makefile | 2 +- ocrd/ocrd/constants.py | 2 +- .../builtin/{ => dummy}/ocrd-tool.json | 0 .../ocrd/processor/builtin/dummy_processor.py | 4 +- ocrd/ocrd/workspace_bagger.py | 2 +- ocrd/setup.py | 1 - ocrd_models/ocrd_models/constants.py | 2 +- ocrd_utils/ocrd_utils/constants.py | 3 +- ocrd_utils/ocrd_utils/package_resources.py | 49 ------------------- ocrd_utils/requirements.txt | 2 - ocrd_validators/ocrd_validators/constants.py | 2 +- 11 files changed, 8 insertions(+), 61 deletions(-) rename ocrd/ocrd/processor/builtin/{ => dummy}/ocrd-tool.json (100%) delete mode 100644 ocrd_utils/ocrd_utils/package_resources.py diff --git a/Makefile b/Makefile index ff28d1fc5..7a66526d1 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ deps-test: # (Re)install the tool install: - $(PIP) install -U pip wheel setuptools fastentrypoints + $(PIP) install -U pip wheel setuptools @# speedup for end-of-life builds @# we cannot use pip config here due to pip#11988 if $(PYTHON) -V | fgrep -e 3.5 -e 3.6; then $(PIP) install --prefer-binary opencv-python-headless numpy; fi diff --git a/ocrd/ocrd/constants.py b/ocrd/ocrd/constants.py index 2e9c17c64..1d436a7fa 100644 --- a/ocrd/ocrd/constants.py +++ b/ocrd/ocrd/constants.py @@ -1,7 +1,7 @@ """ Constants for ocrd. """ -from ocrd_utils.package_resources import resource_filename +from pkg_resources import resource_filename __all__ = [ 'TMP_PREFIX', diff --git a/ocrd/ocrd/processor/builtin/ocrd-tool.json b/ocrd/ocrd/processor/builtin/dummy/ocrd-tool.json similarity index 100% rename from ocrd/ocrd/processor/builtin/ocrd-tool.json rename to ocrd/ocrd/processor/builtin/dummy/ocrd-tool.json diff --git a/ocrd/ocrd/processor/builtin/dummy_processor.py b/ocrd/ocrd/processor/builtin/dummy_processor.py index 0fb07fc6d..c0371e2d0 100644 --- a/ocrd/ocrd/processor/builtin/dummy_processor.py +++ b/ocrd/ocrd/processor/builtin/dummy_processor.py @@ -1,6 +1,6 @@ # pylint: disable=missing-module-docstring,invalid-name from os.path import join, basename -from ocrd_utils.package_resources import resource_string +from pkg_resources import resource_string import click @@ -17,7 +17,7 @@ ) from ocrd_modelfactory import page_from_file -OCRD_TOOL = parse_json_string_with_comments(resource_string(__name__, 'ocrd-tool.json').decode('utf8')) +OCRD_TOOL = parse_json_string_with_comments(resource_string(__name__, 'dummy/ocrd-tool.json').decode('utf8')) class DummyProcessor(Processor): """ diff --git a/ocrd/ocrd/workspace_bagger.py b/ocrd/ocrd/workspace_bagger.py index 97d452718..447f33d13 100644 --- a/ocrd/ocrd/workspace_bagger.py +++ b/ocrd/ocrd/workspace_bagger.py @@ -9,6 +9,7 @@ import sys from bagit import Bag, make_manifests, _load_tag_file, _make_tag_file, _make_tagmanifest_file # pylint: disable=no-name-in-module from distutils.dir_util import copy_tree +from pkg_resources import get_distribution from ocrd_utils import ( pushd_popd, @@ -22,7 +23,6 @@ from ocrd_validators.constants import BAGIT_TXT, TMP_BAGIT_PREFIX, OCRD_BAGIT_PROFILE_URL from ocrd_modelfactory import page_from_file from ocrd_models.ocrd_page import to_xml -from ocrd_utils.package_resources import get_distribution from .workspace import Workspace diff --git a/ocrd/setup.py b/ocrd/setup.py index be28ba0d6..654b36237 100644 --- a/ocrd/setup.py +++ b/ocrd/setup.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import fastentrypoints from setuptools import setup, find_packages from ocrd_utils import VERSION diff --git a/ocrd_models/ocrd_models/constants.py b/ocrd_models/ocrd_models/constants.py index b3fe89a4c..6c8b0e101 100644 --- a/ocrd_models/ocrd_models/constants.py +++ b/ocrd_models/ocrd_models/constants.py @@ -1,7 +1,7 @@ """ Constants for ocrd_models. """ -from ocrd_utils.package_resources import resource_string +from pkg_resources import resource_string import re __all__ = [ diff --git a/ocrd_utils/ocrd_utils/constants.py b/ocrd_utils/ocrd_utils/constants.py index cfe5b20e0..3b1449e30 100644 --- a/ocrd_utils/ocrd_utils/constants.py +++ b/ocrd_utils/ocrd_utils/constants.py @@ -1,12 +1,11 @@ """ Constants for ocrd_utils. """ +from pkg_resources import get_distribution from re import compile as regex_compile from os import environ from os.path import join, expanduser -from ocrd_utils.package_resources import get_distribution - __all__ = [ 'EXT_TO_MIME', 'LOG_FORMAT', diff --git a/ocrd_utils/ocrd_utils/package_resources.py b/ocrd_utils/ocrd_utils/package_resources.py deleted file mode 100644 index c142f0e11..000000000 --- a/ocrd_utils/ocrd_utils/package_resources.py +++ /dev/null @@ -1,49 +0,0 @@ -import atexit -from contextlib import ExitStack -from pathlib import Path - -try: - from importlib.resources import as_file, files -except ImportError: - from importlib_resources import as_file, files # type: ignore - -try: - from importlib.metadata import distribution as get_distribution -except ImportError: - from importlib_metadata import distribution as get_distribution - -# See https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename -_file_manager = ExitStack() -atexit.register(_file_manager.close) - - -def resource_filename(package: str, resource: str) -> Path: - """ - Reimplementation of the function with the same name from pkg_resources - - Using importlib for better performance - - package : str - The package from where to start looking for resource (often __name__) - resource : str - The resource to look up - """ - parent_package = package.rsplit('.',1)[0] - return _file_manager.enter_context(as_file(files(parent_package).joinpath(resource))) - - -def resource_string(package: str, resource: str) -> bytes: - """ - Reimplementation of the function with the same name from pkg_resources - - Using importlib for better performance - - package : str - The package from where to start looking for resource (often __name__) - resource : str - The resource to look up - """ - parent_package = package.rsplit('.',1)[0] - return files(parent_package).joinpath(resource).read_bytes() - -__all__ = ['resource_filename', 'resource_string', 'get_distribution'] diff --git a/ocrd_utils/requirements.txt b/ocrd_utils/requirements.txt index 12f36abec..b4dccec0a 100644 --- a/ocrd_utils/requirements.txt +++ b/ocrd_utils/requirements.txt @@ -3,6 +3,4 @@ Pillow >= 7.2.0 # tensorflow versions might require different versions numpy atomicwrites >= 1.3.0 -importlib_metadata;python_version<'3.8' -importlib_resources;python_version<'3.9' frozendict>=2.3.4 diff --git a/ocrd_validators/ocrd_validators/constants.py b/ocrd_validators/ocrd_validators/constants.py index b3834f7eb..fc1ff445a 100644 --- a/ocrd_validators/ocrd_validators/constants.py +++ b/ocrd_validators/ocrd_validators/constants.py @@ -2,7 +2,7 @@ Constants for ocrd_validators. """ import yaml -from ocrd_utils.package_resources import resource_string, resource_filename +from pkg_resources import resource_string, resource_filename __all__ = [ 'PROCESSING_SERVER_CONFIG_SCHEMA', From bac1a45b1393028cebf85371a4e0225de00936cb Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 3 Jun 2023 00:17:29 +0200 Subject: [PATCH 17/17] make help: improve description --- Dockerfile.cuda | 2 -- Makefile | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile.cuda b/Dockerfile.cuda index c968ae9f4..0e470a474 100644 --- a/Dockerfile.cuda +++ b/Dockerfile.cuda @@ -54,8 +54,6 @@ RUN pip3 install nvidia-pyindex \ done \ && ldconfig # gputil/nvidia-smi would be nice, too – but that drags in Python as a conda dependency... -RUN ldconfig - WORKDIR /data diff --git a/Makefile b/Makefile index 7a66526d1..f6537b69e 100644 --- a/Makefile +++ b/Makefile @@ -32,13 +32,13 @@ help: @echo " docs-clean Clean docs" @echo " docs-coverage Calculate docstring coverage" @echo " docker Build docker image" - @echo " docker-cuda Build docker GPU / CUDA image" + @echo " docker-cuda Build docker image for GPU / CUDA" @echo " pypi Build wheels and source dist and twine upload them" @echo "" @echo " Variables" @echo "" - @echo " DOCKER_TAG Docker tag. Default: '$(DOCKER_TAG)'." - @echo " DOCKER_BASE_IMAGE Docker base image. Default: '$(DOCKER_BASE_IMAGE)'." + @echo " DOCKER_TAG Docker target image tag. Default: '$(DOCKER_TAG)'." + @echo " DOCKER_BASE_IMAGE Docker source image tag. Default: '$(DOCKER_BASE_IMAGE)'." @echo " DOCKER_ARGS Additional arguments to docker build. Default: '$(DOCKER_ARGS)'" @echo " PIP_INSTALL pip install command. Default: $(PIP_INSTALL)"