Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreのctypes実装を追加&古いコアを利用できるようにする #254

Merged
merged 50 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ed13057
古いコアを使えるように
takana-v Dec 23, 2021
ba96a1b
pysen
takana-v Dec 23, 2021
9bee5d5
全てcore_wrapperを使うよう変更
takana-v Dec 27, 2021
491bfa1
onnx版対応
takana-v Dec 28, 2021
1efce0e
fix typo
takana-v Dec 28, 2021
4fb1013
読み込み順修正
takana-v Dec 29, 2021
45e51aa
ビルド周りの修正
takana-v Jan 3, 2022
4a3f4bd
fix dll path
takana-v Jan 3, 2022
79315b8
fix cancellable engine
takana-v Jan 3, 2022
64b01fb
fix format
takana-v Jan 5, 2022
c851ed6
ビルド周り修正
takana-v Jan 5, 2022
d2a16eb
重複処理を関数化
takana-v Jan 5, 2022
43781a5
パスを厳密に指定
takana-v Jan 5, 2022
af3d7bc
Merge branch 'master' into use-ctypes
takana-v Jan 8, 2022
07912e1
libtorchの読み込み修正
takana-v Jan 9, 2022
d5cd571
expanduserの処理を追加
takana-v Jan 9, 2022
f34c321
Merge branch 'master' into use-ctypes
takana-v Jan 9, 2022
0e0fa53
作業ディレクトリを変更
takana-v Jan 9, 2022
afaea8d
fix format
takana-v Jan 9, 2022
41210d7
expanduser処理の場所を修正
takana-v Jan 9, 2022
f6d195d
mockが起動するように変更
takana-v Jan 9, 2022
8e84134
MacでのLibtorch対応を削除
takana-v Jan 9, 2022
af9b368
Revert "作業ディレクトリを変更"
takana-v Jan 9, 2022
ab12264
fix format
takana-v Jan 9, 2022
32e07c2
依存関係インストールの重複を削除
takana-v Jan 14, 2022
4f44aa1
Merge branch 'master' into use-ctypes
takana-v Jan 14, 2022
96da624
build.ymlを修正
takana-v Jan 15, 2022
614ccff
VOICEVOX_CORE_SOURCE_VERSIONを削除
takana-v Jan 15, 2022
c62c6ea
複数バージョン対応
takana-v Jan 15, 2022
bd2545e
ImportErrorを修正
takana-v Jan 15, 2022
cdc411e
ミスを修正
takana-v Jan 15, 2022
ba24d7b
Merge branch 'master' into use-ctypes
takana-v Jan 15, 2022
d4acf7e
コンフリクト解消時にデグレってたので修正
takana-v Jan 15, 2022
530d3f6
まだデグレってたので修正
takana-v Jan 15, 2022
5ea60f4
コメントを追加
takana-v Jan 17, 2022
5ed4047
変数ミスを修正
takana-v Jan 17, 2022
48761d9
変数名を分かりやすく変更
takana-v Jan 17, 2022
ddf999b
引数名のdirをdirsに変更
takana-v Jan 21, 2022
a0e8022
引数名をmodel_libからruntimeに変更
takana-v Jan 21, 2022
d2d21b6
(本体側)引数名を変更
takana-v Jan 21, 2022
0ff4f56
Merge branch 'master' into use-ctypes
takana-v Jan 21, 2022
a31a80f
speaker_infoに引数を追加
takana-v Jan 24, 2022
020ab62
cancellableを使用しようとした際に例外を投げるようにする
takana-v Jan 24, 2022
0424e0a
不要なcopyを削除
takana-v Jan 24, 2022
562df6d
関数名を変更
takana-v Jan 24, 2022
a0a4d30
アサーションを追加
takana-v Jan 24, 2022
c696ce4
型ヒント修正&pysen
takana-v Jan 24, 2022
9558f56
Dictの引数ミス修正
takana-v Jan 24, 2022
b67d6f4
型ヒントの修正漏れを追記
takana-v Jan 24, 2022
ceb11b8
cancellableを起動不可にする
takana-v Jan 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/voicevox_engine
PYTHON_VERSION: '3.8.10'
VOICEVOX_CORE_VERSION: '0.10.preview.3'
VOICEVOX_CORE_SOURCE_VERSION: '0.10.preview.3'
VOICEVOX_ENGINE_VERSION: |- # releaseのときはタグが、それ以外はlatestがバージョン名に
${{ github.event.release.tag_name != '' && github.event.release.tag_name || 'latest' }}

Expand Down Expand Up @@ -109,7 +108,6 @@ jobs:
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
VOICEVOX_ENGINE_VERSION=${{ env.VOICEVOX_ENGINE_VERSION }}
VOICEVOX_CORE_VERSION=${{ env.VOICEVOX_CORE_VERSION }}
VOICEVOX_CORE_SOURCE_VERSION=${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
VOICEVOX_CORE_LIBRARY_NAME=${{ matrix.voicevox_core_library_name }}
ONNXRUNTIME_URL=${{ matrix.onnxruntime_url }}
target: ${{ matrix.target }}
Expand Down
99 changes: 6 additions & 93 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:
PYTHON_VERSION: '3.8.10'
VOICEVOX_RESOURCE_VERSION: '0.10.preview.2'
VOICEVOX_CORE_VERSION: '0.10.preview.3'
VOICEVOX_CORE_SOURCE_VERSION: '0.10.preview.3'
VOICEVOX_ENGINE_VERSION: |- # releaseのときはタグが、それ以外はlatestがバージョン名に
${{ github.event.release.tag_name != '' && github.event.release.tag_name || 'latest' }}

Expand Down Expand Up @@ -144,44 +143,6 @@ jobs:
ditto -x -k --sequesterRsrc --rsrc download/core.zip download/
rm download/core.zip

# Install VOICEVOX Core Python package
- name: Prepare VOICEVOX Core source cache
uses: actions/cache@v2
id: voicevox-core-source-cache
with:
key: ${{ matrix.os }}-voicevox-core-source-${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
path: download/voicevox_core_source

- name: Checkout VOICEVOX Core source
if: steps.voicevox-core-source-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: VOICEVOX/voicevox_core
ref: ${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
path: download/voicevox_core_source

- name: Install VOICEVOX Core Python package
shell: bash
run: |
set -eux

mkdir -p download/voicevox_core_source/core/lib

# Copy VOICEVOX Core dylib to core/lib
cp download/core/${{ matrix.voicevox_core_library_name }} download/voicevox_core_source/core/lib/libcore.dylib

cd download/voicevox_core_source
cp core/src/core.h core/lib/
cd -

# Copy ONNX Runtime dylib
cp download/onnxruntime/lib/libonnxruntime.*.dylib download/voicevox_core_source/core/lib/

# Install VOICEVOX Core Python package with libcore.dylib & libonnxruntime.*.dylib
cd download/voicevox_core_source
NUMPY_INCLUDE=`python -c "import numpy; print(numpy.get_include())"`
CPATH="$NUMPY_INCLUDE:${CPATH:-}" pip install .

- name: Download PyOpenJTalk dictionary
shell: bash
run: |
Expand Down Expand Up @@ -228,7 +189,8 @@ jobs:
--include-data-file=../user.dic=./ \
--include-data-file=../download/core/*.bin=./ \
--include-data-file=../download/core/metas.json=./ \
--include-data-file=../download/onnxruntime/lib/libonnxruntime.*.dylib=./ \
--include-data-file=../download/core/${{ matrix.voicevox_core_library_name }}=./ \
--include-data-file=../download/onnxruntime/lib/libonnxruntime.dylib=./ \
aoirint marked this conversation as resolved.
Show resolved Hide resolved
--include-data-file=${{ env.pythonLocation }}/lib/python*/site-packages/scipy/.dylibs/*.dylib=./scipy/.dylibs/ \
--include-data-file=${{ env.pythonLocation }}/lib/python*/site-packages/_soundfile_data/*=./_soundfile_data/ \
--include-data-dir=../speaker_info=./speaker_info \
Expand Down Expand Up @@ -352,7 +314,6 @@ jobs:
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
VOICEVOX_ENGINE_VERSION=${{ env.VOICEVOX_ENGINE_VERSION }}
VOICEVOX_CORE_VERSION=${{ env.VOICEVOX_CORE_VERSION }}
VOICEVOX_CORE_SOURCE_VERSION=${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
VOICEVOX_CORE_LIBRARY_NAME=${{ matrix.voicevox_core_library_name }}
ONNXRUNTIME_URL=${{ matrix.onnxruntime_url }}
target: ${{ matrix.target }}
Expand Down Expand Up @@ -650,49 +611,6 @@ jobs:
unzip download/core.zip -d download/
rm download/core.zip

# Install VOICEVOX Core Python package
- name: Prepare VOICEVOX Core source cache
uses: actions/cache@v2
id: voicevox-core-source-cache
with:
key: ${{ matrix.os }}-voicevox-core-source-${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
path: download/voicevox_core_source

- name: Checkout VOICEVOX Core source
if: steps.voicevox-core-source-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: VOICEVOX/voicevox_core
ref: ${{ env.VOICEVOX_CORE_SOURCE_VERSION }}
path: download/voicevox_core_source

- name: Install VOICEVOX Core Python package
shell: bash
run: |
set -eux

# Generate VOICEVOX Core LIB from DLL
cp download/core/${{ matrix.voicevox_core_dll_name }} download/voicevox_core_source/example/python/core.dll

cd download/voicevox_core_source/example/python
./makelib.bat core
cd -

# Copy VOICEVOX Core DLL & LIB to core/lib
cd download/voicevox_core_source
mkdir -p core/lib
mv example/python/core.dll core/lib/
mv example/python/core.lib core/lib/
cp core/src/core.h core/lib/
cd -

# Copy ONNX Runtime DLLs
cp download/onnxruntime/lib/*.dll download/voicevox_core_source/core/lib/

# Install VOICEVOX Core Python package with core.dll & onnxruntime*.dll
cd download/voicevox_core_source
pip install .

- name: Generate licenses.json
shell: bash
run: python generate_licenses.py > licenses.json
Expand Down Expand Up @@ -720,7 +638,7 @@ jobs:

# Replace version
sed -i "s/__version__ = \"latest\"/__version__ = \"${{ env.VOICEVOX_ENGINE_VERSION }}\"/" voicevox_engine/__init__.py

python -m nuitka \
--standalone \
--assume-yes-for-downloads \
Expand All @@ -737,6 +655,8 @@ jobs:
--include-data-file="presets.yaml=./" \
--include-data-file=download/core/*.bin=./ \
--include-data-file="download/core/metas.json=./" \
--include-data-file="download/onnxruntime/lib/onnxruntime.dll=./" \
--include-data-file="download/core/${{ matrix.voicevox_core_dll_name }}=./" \
--include-data-dir="speaker_info=./speaker_info" \
--msvc=14.2 \
--follow-imports \
Expand All @@ -758,13 +678,6 @@ jobs:
run: |
set -eux

# Workaround: Move core.dll to run.dist/core/lib/
# Nuitka copies core.dll to run.dist/core.dll
# but core Python module will load core.dll from run.dist/core/lib/core.dll.
mkdir -p run.dist/core/lib
mv run.dist/core.dll run.dist/core/lib/
mv run.dist/onnxruntime.dll run.dist/core/lib/

# Build artifact directory
mkdir -p artifact
ln -sf "$(pwd)/run.dist"/* artifact/
Expand All @@ -773,7 +686,7 @@ jobs:

if [ -f "download/onnxruntime/lib/onnxruntime_providers_cuda.dll" ]; then
# ONNX Runtime providers (Nuitka does not copy dynamic loaded libraries)
ln -sf "$(pwd)/download/onnxruntime/lib"/onnxruntime_*.dll artifact/core/lib/
ln -sf "$(pwd)/download/onnxruntime/lib"/onnxruntime_*.dll artifact/

# CUDA
ln -sf "$(pwd)/download/cuda/bin"/cublas64_*.dll artifact/
Expand Down
49 changes: 5 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ RUN <<EOF
mkdir /opt/voicevox_core
mv "./core/${VOICEVOX_CORE_LIBRARY_NAME}" /opt/voicevox_core/

if [ "${VOICEVOX_CORE_LIBRARY_NAME}" != "libcore.so" ]; then
# Create relative symbolic link
cd /opt/voicevox_core
ln -sf "${VOICEVOX_CORE_LIBRARY_NAME}" libcore.so
cd -
fi

# Move Voice Library to /opt/voicevox_core/
mv ./core/*.bin ./core/core.h ./core/metas.json /opt/voicevox_core/
mv ./core/*.bin ./core/metas.json /opt/voicevox_core/

# Move documents to /opt/voicevox_core/
mv ./core/README.txt ./core/VERSION /opt/voicevox_core/
Expand Down Expand Up @@ -202,40 +195,6 @@ COPY --from=download-core-env /opt/voicevox_core /opt/voicevox_core
# COPY --from=download-onnxruntime-env /etc/ld.so.conf.d/onnxruntime.conf /etc/ld.so.conf.d/onnxruntime.conf
COPY --from=download-onnxruntime-env /opt/onnxruntime /opt/onnxruntime

# Install VOICEVOX Core Python module
ARG VOICEVOX_CORE_SOURCE_VERSION=0.10.preview.3
RUN <<EOF
set -eux

git clone -b "${VOICEVOX_CORE_SOURCE_VERSION}" --depth 1 https://github.com/VOICEVOX/voicevox_core.git /tmp/voicevox_core_source

# Copy shared libraries to repo to be packed in core package
# ONNX Runtime: included
# CUDA/cuDNN: not included

mkdir -p /tmp/voicevox_core_source/core/lib
cp /opt/voicevox_core/libcore.so /tmp/voicevox_core_source/core/lib/

# Copy versioned shared library only (setup.py will copy package data as real file on install)
cd /opt/onnxruntime/lib
find . -name 'libonnxruntime.so.*' -or -name 'libonnxruntime_*.so' | xargs -I% cp -v % /tmp/voicevox_core_source/core/lib/
cd -

# Duplicate core.h in repo
cp /tmp/voicevox_core_source/core/src/core.h /tmp/voicevox_core_source/core/lib/

# Install voicevox_core Python module
# Files will be generated at build time, so chown for general user
chown -R user:user /tmp/voicevox_core_source

cd /tmp/voicevox_core_source

gosu user /opt/python/bin/pip3 install .

# remove cloned repository before layer end to reduce image size
rm -rf /tmp/voicevox_core_source
EOF

# Add local files
ADD ./voicevox_engine /opt/voicevox_engine/voicevox_engine
ADD ./docs /opt/voicevox_engine/docs
Expand Down Expand Up @@ -291,11 +250,11 @@ exec "\$@"
EOF

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--voicelib_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]
CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--voicelib_dir", "/opt/voicevox_core/", "--runtime_dir", "/opt/onnxruntime/lib", "--host", "0.0.0.0" ]

# Enable use_gpu
FROM runtime-env AS runtime-nvidia-env
CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--use_gpu", "--voicelib_dir", "/opt/voicevox_core/", "--host", "0.0.0.0" ]
CMD [ "gosu", "user", "/opt/python/bin/python3", "./run.py", "--use_gpu", "--voicelib_dir", "/opt/voicevox_core/", "--runtime_dir", "/opt/onnxruntime/lib", "--host", "0.0.0.0" ]
aoirint marked this conversation as resolved.
Show resolved Hide resolved

# Binary build environment (common to CPU, GPU)
FROM runtime-env AS build-env
Expand Down Expand Up @@ -369,6 +328,8 @@ RUN <<EOF
--include-data-file=/opt/voicevox_engine/user.dic=./ \
--include-data-file=/opt/voicevox_core/*.bin=./ \
--include-data-file=/opt/voicevox_core/metas.json=./ \
--include-data-file=/opt/voicevox_core/*.so=./ \
--include-data-file=/opt/onnxruntime/lib/libonnxruntime.so=./ \
--include-data-dir=/opt/voicevox_engine/speaker_info=./speaker_info \
--follow-imports \
--no-prefer-source-code \
Expand Down
Loading