Skip to content

Commit

Permalink
Dockerfile (Linux): CPUイメージでLibTorch CPU版を使用 (#101)
Browse files Browse the repository at this point in the history
* Dockerfile: use cpu LibTorch for cpu image

* Dockerfile: workaround to modify libcore link for cpu

* Dockerfile: use bash shell in download-libcore stage to use [[ command

* fix if expression for sh

* fix workaround working

* Dockerfile: add INFERENCE_DEVICE build arg
  • Loading branch information
aoirint authored Sep 16, 2021
1 parent b8c1c78 commit 89fddfe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,36 @@ jobs:
target: runtime-env
base_image: ubuntu:focal
base_runtime_image: ubuntu:focal
inference_device: cpu
libtorch_url: https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip
- os: ubuntu-latest
tag: cpu
target: runtime-env
base_image: ubuntu:focal
base_runtime_image: ubuntu:focal
inference_device: cpu
libtorch_url: https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip
- os: ubuntu-latest
tag: cpu-ubuntu20.04
target: runtime-env
base_image: ubuntu:focal
base_runtime_image: ubuntu:focal
inference_device: cpu
libtorch_url: https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip
- os: ubuntu-latest
tag: nvidia
target: runtime-nvidia-env
base_image: ubuntu:focal
base_runtime_image: nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04
inference_device: nvidia
libtorch_url: https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip
- os: ubuntu-latest
tag: nvidia-ubuntu20.04
target: runtime-nvidia-env
base_image: ubuntu:focal
base_runtime_image: nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04
inference_device: nvidia
libtorch_url: https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -76,6 +86,8 @@ jobs:
build-args: |
BASE_IMAGE=${{ matrix.base_image }}
BASE_RUNTIME_IMAGE=${{ matrix.base_runtime_image }}
INFERENCE_DEVICE=${{ matrix.inference_device }}
LIBTORCH_URL=${{ matrix.libtorch_url }}
target: ${{ matrix.target }}
push: true
tags: |
Expand Down
27 changes: 26 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ RUN <<EOF
ldconfig
EOF

# Temporary workaround: modify libcore link for cpu
# Remove CUDA/LibTorchGPU dependencies from libcore
ARG INFERENCE_DEVICE=cpu
RUN <<EOF
if [ "${INFERENCE_DEVICE}" = "cpu" ]; then
apt-get update
apt-get install -y \
patchelf
apt-get clean
rm -rf /var/lib/apt/lists/*
fi
EOF

RUN <<EOF
if [ "${INFERENCE_DEVICE}" = "cpu" ]; then
cd /opt/voicevox_core/

patchelf --remove-needed libtorch_cuda.so libcore.so
patchelf --remove-needed libtorch_cuda_cpp.so libcore.so
patchelf --remove-needed libtorch_cuda_cu.so libcore.so
patchelf --remove-needed libnvToolsExt.so.1 libcore.so
patchelf --remove-needed libcudart.so.11.0 libcore.so
fi
EOF


# Download LibTorch
FROM ${BASE_IMAGE} AS download-libtorch-env
Expand All @@ -48,7 +73,7 @@ RUN <<EOF
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
ARG LIBTORCH_URL=https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip
RUN <<EOF
wget -nv --show-progress -c -O "./libtorch.zip" "${LIBTORCH_URL}"
unzip "./libtorch.zip"
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ build-linux-docker-ubuntu:
-t hiroshiba/voicevox_engine:cpu-ubuntu20.04-latest \
--target runtime-env \
--progress plain \
--build-arg BASE_RUNTIME_IMAGE=ubuntu:focal
--build-arg BASE_RUNTIME_IMAGE=ubuntu:focal \
--build-arg LIBTORCH_URL=https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip \
--build-arg INFERENCE_DEVICE=cpu

.PHONY: run-linux-docker-ubuntu
run-linux-docker-ubuntu:
Expand All @@ -20,7 +22,9 @@ build-linux-docker-nvidia:
-t hiroshiba/voicevox_engine:nvidia-ubuntu20.04-latest \
--target runtime-nvidia-env \
--progress plain \
--build-arg BASE_RUNTIME_IMAGE=nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04
--build-arg BASE_RUNTIME_IMAGE=nvidia/cuda:11.4.1-cudnn8-runtime-ubuntu20.04 \
--build-arg LIBTORCH_URL=https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip \
--build-arg INFERENCE_DEVICE=nvidia

.PHONY: run-linux-docker-nvidia
run-linux-docker-nvidia:
Expand Down

0 comments on commit 89fddfe

Please sign in to comment.