From 89dde2d46835711578fac5ea874590c6d2dd5dc6 Mon Sep 17 00:00:00 2001 From: Jon Wiggins Date: Mon, 20 Jun 2022 16:20:07 -0600 Subject: [PATCH] Add CUDA docker version --- README.md | 10 ++++++++++ docker-compose.cuda.yml | 12 ++++++++++++ docker/Dockerfile.cuda | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 docker-compose.cuda.yml create mode 100644 docker/Dockerfile.cuda diff --git a/README.md b/README.md index 8e211a9..706cb24 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,16 @@ docker-compose up -d --build > Feel free to change the [`docker-compose.yml`](https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml) file to adapt it to your deployment needs, or use an extra `docker-compose.prod.yml` file for your deployment configuration. +### CUDA + +You can use hardware acceleration to speed up translations on a GPU machine with CUDA 11.2 and [nvidia-docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) installed. + +Run this version with: + +```bash +docker-compose -f docker-compose.cuda.yml up -d --build +``` + ## Arguments | Argument | Description | Default | Env. name | diff --git a/docker-compose.cuda.yml b/docker-compose.cuda.yml new file mode 100644 index 0000000..5f8beaa --- /dev/null +++ b/docker-compose.cuda.yml @@ -0,0 +1,12 @@ +version: "3" + +services: + libretranslate-cuda: + container_name: libretranslate-cuda + build: + context: . + dockerfile: docker/Dockerfile.cuda + restart: unless-stopped + ports: + - 5000:5000 + command: --gpus all diff --git a/docker/Dockerfile.cuda b/docker/Dockerfile.cuda new file mode 100644 index 0000000..a07662e --- /dev/null +++ b/docker/Dockerfile.cuda @@ -0,0 +1,37 @@ +FROM nvidia/cuda:11.2.2-devel-ubuntu20.04 + +ENV ARGOS_DEVICE_TYPE cuda +ARG with_models=true +ARG models= + +WORKDIR /app + +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update -qq \ + && apt-get -qqq install --no-install-recommends -y libicu-dev libaspell-dev libcairo2 libcairo2-dev pkg-config gcc g++ python3.8-dev python3-pip libpython3.8-dev\ + && apt-get clean \ + && rm -rf /var/lib/apt + +RUN pip3 install --upgrade pip + +COPY . . + +RUN ln -s /usr/bin/python3 /usr/bin/python + +RUN if [ "$with_models" = "true" ]; then \ + # install only the dependencies first + pip3 install -e .; \ + # initialize the language models + if [ ! -z "$models" ]; then \ + ./install_models.py --load_only_lang_codes "$models"; \ + else \ + ./install_models.py; \ + fi \ + fi + +# Install package from source code +RUN pip3 install . \ + && pip3 cache purge +ENV LD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/lib64 +EXPOSE 5000 +ENTRYPOINT [ "libretranslate", "--host", "0.0.0.0" ]