Skip to content

Commit

Permalink
feat!: liberate VOICEVOX CORE (#825)
Browse files Browse the repository at this point in the history
1. manifest.jsonの"…_filename"部分を変更し、.binを認識できるようにする。
   .binの場合、 VOICEVOX/ort#8 で追加される
   `SessionBuilder::commit_from_vv_bin`を用いる。

    ```json
        "predict_duration": {
          "type": "onnx",
          "filename": "predict_duration.onnx"
        },
    ```

    ```json
        "predict_duration": {
          "type": "vv_bin",
          "filename": "pd.bin"
        },
    ```

2. `Onnxruntime::LIB_NAME`を`"onnxruntime"`から`"voicevox_onnxruntime"`
   にする。compatible_engineの場合だけ、`"voicevox_onnxruntime"`で失敗す
   ると`"onnxruntime"`にフォールバックするようにする(モック目的で使える
   ように)。

3. VOICEVOX/ort#8 でログのフィルタリングをやめる代わりに、C APIのログ
   フィルタの`ort=info`を`ort=warn`にする。

4. build_and_deploy_downloaderの`is_production`周りを吹き飛ばす。

5. #913 の続きとして、Rust APIの`package.license`を設定。

残る課題は以下の通り。

> README周り(たぶんcore.zip内のreadmeは削除で良さそう?)
> #825 (comment)
>
> downloader周り(一旦壊れることになる・・・?いやならなさそうな気がする!)
> #825 (comment)
>
> is_productionフラグを失くす?
> #825 (comment)

#825 (review)

Resolves: VOICEVOX/voicevox_project#24
Resolves: #388
Resolves: #722
  • Loading branch information
qryxip authored Jan 15, 2025
1 parent fda1e71 commit b94883f
Show file tree
Hide file tree
Showing 36 changed files with 382 additions and 304 deletions.
50 changes: 7 additions & 43 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:
type: boolean
required: false
default: false
# TODO: ライセンス表記およびモデル配布形体の方針が固まったら廃止
# <https://github.com/VOICEVOX/voicevox_core/pull/825#discussion_r1740115058>
is_production:
description: "製品版をビルドする"
type: boolean
Expand Down Expand Up @@ -158,30 +160,15 @@ jobs:
build_and_deploy:
needs: config
environment: ${{ inputs.is_production && 'production' || '' }} # 製品版のenvironment
environment: ${{ inputs.code_signing && 'production' || '' }} # コード署名用のenvironment
strategy:
matrix:
include: ${{ fromJson(needs.config.outputs.includes) }}
runs-on: ${{ matrix.os }}
env:
ASSET_NAME: voicevox_core-${{ matrix.artifact_name }}-${{ needs.config.outputs.version }}
steps:
- uses: actions/checkout@v4 # 製品版ではない場合
if: ${{ !inputs.is_production }}
- uses: actions/checkout@v4 # 製品版の場合
if: inputs.is_production
with:
fetch-depth: 0 # 全履歴取得
token: ${{ secrets.PRODUCTION_GITHUB_TOKEN }}
- name: Merge production branch
if: inputs.is_production
shell: bash
run: |
(
git remote add private ${{ secrets.PRODUCTION_REPOSITORY_URL }}
git fetch private refs/tags/${{ env.PRODUCTION_REPOSITORY_TAG }}
git -c user.name=dummy -c [email protected] merge FETCH_HEAD
) > /dev/null 2>&1
- uses: actions/checkout@v4
- name: Set up Python 3.10
if: matrix.python_whl
uses: actions/setup-python@v5
Expand Down Expand Up @@ -230,22 +217,14 @@ jobs:
fi
- name: cache target
uses: Swatinem/rust-cache@v2
if: ${{ !inputs.is_production }}
- name: build voicevox_core_c_api
shell: bash
run: |
case ${{ matrix.c_release_format }} in
plain-cdylib) linking=load-onnxruntime ;;
ios-xcframework) linking=link-onnxruntime ;;
esac
function build() {
cargo build -p voicevox_core_c_api -v --features "$linking" --target ${{ matrix.target }} --release
}
if ${{ !inputs.is_production }}; then
build
else
build > /dev/null 2>&1
fi
cargo build -p voicevox_core_c_api -v --features "$linking" --target ${{ matrix.target }} --release
env:
RUSTFLAGS: -C panic=abort
- name: build voicevox_core_python_api
Expand All @@ -256,26 +235,11 @@ jobs:
pip install --upgrade poetry
poetry config virtualenvs.create false
(cd crates/voicevox_core_python_api && poetry install --with dev)
function build() {
maturin build --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --target ${{ matrix.target }} --release
}
if ${{ !inputs.is_production }}; then
build
else
build > /dev/null 2>&1
fi
maturin build --manifest-path ./crates/voicevox_core_python_api/Cargo.toml --target ${{ matrix.target }} --release
echo "whl=$(find ./target/wheels -type f)" >> "$GITHUB_OUTPUT"
- name: build voicevox_core_java_api
if: contains(matrix.target, 'android')
run: |
function build() {
cargo build -p voicevox_core_java_api -v --target ${{ matrix.target }} --release
}
if ${{ !inputs.is_production }}; then
build
else
build > /dev/null 2>&1
fi
run: cargo build -p voicevox_core_java_api vv --target ${{ matrix.target }} --release
- name: Organize artifact
run: |
mkdir -p "artifact/${{ env.ASSET_NAME }}"
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/build_and_deploy_downloader.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ on:
type: boolean
required: false
default: false
is_production:
description: "製品版をビルドする"
type: boolean
required: false
default: false
release:
types:
- published
Expand All @@ -42,7 +37,7 @@ defaults:

jobs:
deploy_and_deploy_downloader:
environment: ${{ inputs.is_production && 'production' || '' }} # コード署名用のenvironment
environment: ${{ inputs.code_signing && 'production' || '' }} # コード署名用のenvironment
strategy:
matrix:
include:
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,12 @@ jobs:
- run: cargo build -p test_util -v # build scriptにより/crates/test_util/data/の生成
- run: poetry run maturin build --locked
- run: poetry run maturin develop --locked
- name: 必要なDLLをコピーしてpytestを実行
run: |
cp -v ../../target/debug/onnxruntime.dll . || true
cp -v ../../target/debug/libonnxruntime.so.* . || true
cp -v ../../target/debug/libonnxruntime.*.dylib . || true
poetry run pytest
- name: pytestを実行
run: poetry run pytest
- name: Exampleを実行
run: |
for file in ../../example/python/run{,-asyncio}.py; do
poetry run python "$file" ../test_util/data/model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11
poetry run python "$file" ../test_util/data/model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11 --onnxruntime ../test_util/data/lib/*onnxruntime*
done
# https://github.com/VOICEVOX/voicevox_core/issues/873 が再発しないかの確認。
#
Expand All @@ -303,7 +298,7 @@ jobs:
#
# TODO: 10回の実行におよそ60秒ほどかかるため、状況の経過を見てやめる。
for _ in {1..10}; do
poetry run python ../../example/python/run-asyncio.py ../test_util/data/model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11 \
poetry run python ../../example/python/run-asyncio.py ../test_util/data/model/sample.vvm --dict-dir ../test_util/data/open_jtalk_dic_utf_8-1.11 --onnxruntime ../test_util/data/lib/*onnxruntime* \
2> >(tee ./stderr.txt >&2)
# shellcheck disable=SC2059
! grep -q StopIteration ./stderr.txt
Expand Down
4 changes: 2 additions & 2 deletions build_util/make_ios_xcframework.bash
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ for arch in "${arches[@]}"; do
install_name_tool -id "@rpath/voicevox_core.framework/voicevox_core" \
"Framework-${arch}/voicevox_core.framework/voicevox_core"

# 依存ライブラリonnxruntimeへの@rpathを変更
# onnxruntimeへの@rpathを、voicevox_onnxruntimeのXCFrameworkに変更
install_name_tool -change "@rpath/$dylib_string" \
"@rpath/onnxruntime.framework/onnxruntime" \
"@rpath/voicevox_onnxruntime.framework/voicevox_onnxruntime" \
"Framework-${arch}/voicevox_core.framework/voicevox_core"
done

Expand Down
3 changes: 2 additions & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
publish.workspace = true
rust-version.workspace = true
license.workspace = true

[package.metadata.docs.rs]
features = ["load-onnxruntime", "link-onnxruntime"]
Expand All @@ -25,7 +26,7 @@ camino.workspace = true
const_format.workspace = true
derive-getters.workspace = true
derive-new.workspace = true
derive_more = { workspace = true, features = ["add", "deref", "display", "from", "from_str"] }
derive_more = { workspace = true, features = ["add", "deref", "display", "from", "from_str", "index"] }
duplicate.workspace = true
easy-ext.workspace = true
educe.workspace = true
Expand Down
7 changes: 1 addition & 6 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ fn test_gpu(
/// use voicevox_core::{nonblocking::Onnxruntime, SupportedDevices};
///
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(if cfg!(windows) {
/// # // Windows\System32\onnxruntime.dllを回避
/// # test_util::ONNXRUNTIME_DYLIB_PATH
/// # } else {
/// # voicevox_core::blocking::Onnxruntime::LIB_VERSIONED_FILENAME
/// # })
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// #
/// let onnxruntime = Onnxruntime::get().unwrap();
Expand Down
12 changes: 4 additions & 8 deletions crates/voicevox_core/src/infer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pub(crate) mod domains;
mod model_file;
pub(crate) mod runtimes;
pub(crate) mod session_set;

use std::{borrow::Cow, collections::BTreeSet, fmt::Debug, ops::Index, sync::Arc};
use std::{borrow::Cow, collections::BTreeSet, fmt::Debug, sync::Arc};

use derive_new::new;
use duplicate::duplicate_item;
Expand All @@ -14,6 +13,7 @@ use thiserror::Error;
use crate::{
asyncs::{Async, BlockingThreadPool, SingleTasked},
devices::{DeviceSpec, GpuSpec},
voice_model::ModelBytes,
StyleType, SupportedDevices,
};

Expand Down Expand Up @@ -62,7 +62,7 @@ pub(crate) trait InferenceRuntime: 'static {
)]
fn new_session(
&self,
model: impl FnOnce() -> std::result::Result<Vec<u8>, DecryptModelError>,
model: &ModelBytes,
options: InferenceSessionOptions,
) -> anyhow::Result<(
Self::Session,
Expand All @@ -78,7 +78,7 @@ pub(crate) trait InferenceRuntime: 'static {
/// 共に扱われるべき推論操作の集合を示す。
pub(crate) trait InferenceDomain: Sized {
type Operation: InferenceOperation;
type Manifest: Index<Self::Operation, Output = Arc<str>>;
type Manifest;

/// 対応する`StyleType`。
///
Expand Down Expand Up @@ -265,7 +265,3 @@ pub(crate) enum ExtractError {
#[error(transparent)]
Shape(#[from] ShapeError),
}

#[derive(Error, Debug)]
#[error("不正なモデルファイルです")]
pub(crate) struct DecryptModelError;
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/infer/domains/experimental_talk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::BTreeSet, sync::LazyLock};
use enum_map::Enum;
use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignature};
use ndarray::{Array0, Array1, Array2};
use serde::Deserialize;

use crate::{manifest::ExperimentalTalkManifest, StyleType};

Expand All @@ -23,7 +24,8 @@ impl InferenceDomain for ExperimentalTalkDomain {
}
}

#[derive(Clone, Copy, Enum, InferenceOperation)]
#[derive(Clone, Copy, Deserialize, Enum, InferenceOperation)]
#[serde(rename_all = "snake_case")]
#[inference_operation(
type Domain = ExperimentalTalkDomain;
)]
Expand Down
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/infer/domains/frame_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::BTreeSet, sync::LazyLock};
use enum_map::Enum;
use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignature};
use ndarray::{Array1, Array2};
use serde::Deserialize;

use crate::{manifest::FrameDecodeManifest, StyleType};

Expand All @@ -23,7 +24,8 @@ impl InferenceDomain for FrameDecodeDomain {
}
}

#[derive(Clone, Copy, Enum, InferenceOperation)]
#[derive(Clone, Copy, Deserialize, Enum, InferenceOperation)]
#[serde(rename_all = "snake_case")]
#[inference_operation(
type Domain = FrameDecodeDomain;
)]
Expand Down
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/infer/domains/singing_teacher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::BTreeSet, sync::LazyLock};
use enum_map::Enum;
use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignature};
use ndarray::{Array1, Array2};
use serde::Deserialize;

use crate::{manifest::SingingTeacherManifest, StyleType};

Expand All @@ -23,7 +24,8 @@ impl InferenceDomain for SingingTeacherDomain {
}
}

#[derive(Clone, Copy, Enum, InferenceOperation)]
#[derive(Clone, Copy, Deserialize, Enum, InferenceOperation)]
#[serde(rename_all = "snake_case")]
#[inference_operation(
type Domain = SingingTeacherDomain;
)]
Expand Down
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/infer/domains/talk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::BTreeSet, sync::LazyLock};
use enum_map::Enum;
use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignature};
use ndarray::{Array0, Array1, Array2};
use serde::Deserialize;

use crate::{manifest::TalkManifest, StyleType};

Expand All @@ -23,7 +24,8 @@ impl InferenceDomain for TalkDomain {
}
}

#[derive(Clone, Copy, Enum, InferenceOperation)]
#[derive(Clone, Copy, Deserialize, Enum, InferenceOperation)]
#[serde(rename_all = "snake_case")]
#[inference_operation(
type Domain = TalkDomain;
)]
Expand Down
5 changes: 0 additions & 5 deletions crates/voicevox_core/src/infer/model_file.rs

This file was deleted.

Loading

0 comments on commit b94883f

Please sign in to comment.