Skip to content

Commit

Permalink
install libtorch
Browse files Browse the repository at this point in the history
  • Loading branch information
aoirint committed Sep 12, 2021
1 parent 79a9ae7 commit de20f62
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ jobs:
include:
- os: ubuntu-latest
tag: latest
target: runtime-env
base_runtime_image: ubuntu:focal
- os: ubuntu-latest
tag: cpu-latest
target: runtime-env
base_runtime_image: ubuntu:focal
- os: ubuntu-latest
tag: cpu-ubuntu20.04
target: runtime-env
base_runtime_image: ubuntu:focal
- os: ubuntu-latest
tag: nvidia-latest
target: runtime-nvidia-env
base_runtime_image: nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04
- os: ubuntu-latest
tag: nvidia-ubuntu20.04
target: runtime-nvidia-env
base_runtime_image: nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04

steps:
Expand Down Expand Up @@ -63,6 +68,7 @@ jobs:
file: ./Dockerfile
build-args: |
BASE_RUNTIME_IMAGE=${{ matrix.base_runtime_image }}
target: ${{ matrix.target }}
push: true
tags: ${{ env.IMAGE_NAME }}:${{ matrix.tag }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down
46 changes: 42 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ARG BASE_RUNTIME_IMAGE=ubuntu:focal

# Download VOICEVOX Core shared object
FROM ubuntu:focal AS download-core-env
ARG DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -30,6 +31,36 @@ RUN <<EOF
EOF


# Download LibTorch
FROM ubuntu:focal AS download-libtorch-env
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /work

RUN <<EOF
apt-get update
apt-get install -y \
wget \
unzip
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF

ARG LIBTORCH_URL=https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip
RUN <<EOF
wget -nv --show-progress -c -O "./libtorch.zip" "${LIBTORCH_URL}"
unzip "./libtorch.zip"
mv ./libtorch /opt/libtorch
rm ./libtorch.zip
EOF

RUN <<EOF
echo "/opt/libtorch/lib" > /etc/ld.so.conf.d/libtorch.conf
ldconfig
EOF


# Runtime
FROM ${BASE_RUNTIME_IMAGE} AS runtime-env
ARG DEBIAN_FRONTEND=noninteractive

Expand All @@ -56,17 +87,20 @@ RUN <<EOF
pip3 install -r /tmp/requirements-dev.txt
EOF

# Copy VOICEVOX Core shared object
COPY --from=download-core-env /etc/ld.so.conf.d/voicevox_core.conf /etc/ld.so.conf.d/voicevox_core.conf
COPY --from=download-core-env /opt/voicevox_core /opt/voicevox_core

# Copy LibTorch
COPY --from=download-libtorch-env /etc/ld.so.conf.d/libtorch.conf /etc/ld.so.conf.d/libtorch.conf
COPY --from=download-libtorch-env /opt/libtorch /opt/libtorch
RUN <<EOF
ldconfig
EOF

# TODO: install libtorch

ARG VOICEVOX_CORE_EXAMPLE_VERSION=0.5.2
RUN <<EOF
git clone -b "${VOICEVOX_CORE_EXAMPLE_VERSION}" https://github.com/Hiroshiba/voicevox_core.git /opt/voicevox_core_example
git clone -b "${VOICEVOX_CORE_EXAMPLE_VERSION}" --depth 1 https://github.com/Hiroshiba/voicevox_core.git /opt/voicevox_core_example
cd /opt/voicevox_core_example
cp ./core.h ./example/python/
cd example/python
Expand All @@ -81,4 +115,8 @@ RUN <<EOF
python3 -c "import pyopenjtalk; pyopenjtalk._lazy_init()"
EOF

CMD [ "python3", "./run.py", "--voicevox_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]
CMD [ "python3", "./run.py", "--voicevox_dir", "/opt/voicevox_core/", "--voicelib_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]

# enable use_gpu
FROM runtime-env AS runtime-nvidia-env
CMD [ "python3", "./run.py", "--use_gpu", "--voicevox_dir", "/opt/voicevox_core/", "--voicelib_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ CMD=
build-linux-docker-nvidia:
docker buildx build . \
-t aoirint/voicevox_engine:nvidia-ubuntu20.04 \
--target runtime-nvidia-env \
--progress plain \
--build-arg BASE_RUNTIME_IMAGE=nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04

run-linux-docker-nvidia:
Expand Down

0 comments on commit de20f62

Please sign in to comment.