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

feat!: liberate VOICEVOX CORE #825

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c6e0935
change: liberate VOICEVOX CORE
qryxip Aug 26, 2024
6e1cafb
ortをアップデート
qryxip Aug 31, 2024
a5f009c
`bin` → `vv-bin`
qryxip Aug 31, 2024
92fb4c9
ortをアップデート
qryxip Aug 31, 2024
38687d5
ortをアップデート
qryxip Sep 2, 2024
ff70980
`"type": "vv-bin"` → `"type": "vv_bin"`
qryxip Sep 2, 2024
b87afd8
`inputs.is_production`を残す
qryxip Sep 2, 2024
80345e5
嘘コメントをリバート
qryxip Sep 4, 2024
148fa5d
`install_name_tool`でのrpath変更をvoicevox_onnxruntime.framework宛てに
qryxip Sep 4, 2024
688c03f
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 5, 2024
89ea1f9
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 6, 2024
accb03f
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 12, 2024
026ff6f
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 19, 2024
c5db7b8
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 19, 2024
d5bce52
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 19, 2024
0b63929
Merge branch 'main' into change-liberate-voicevox-core
qryxip Sep 26, 2024
b1175b2
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 3, 2024
bb0c57f
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 4, 2024
012ac5a
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 8, 2024
5cf7fcb
Fix a test
qryxip Oct 8, 2024
929fec2
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 13, 2024
10a6111
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 13, 2024
c61141c
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 13, 2024
7780c34
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 14, 2024
17fedd5
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 21, 2024
2579467
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 23, 2024
5187f9e
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 25, 2024
f9e3cde
Merge branch 'main' into change-liberate-voicevox-core
qryxip Oct 29, 2024
09ffd63
Merge branch 'main' into change-liberate-voicevox-core
qryxip Nov 2, 2024
21e3e79
Merge branch 'main' into change-liberate-voicevox-core
qryxip Nov 27, 2024
3fa5a64
Merge branch 'main' into change-liberate-voicevox-core
qryxip Nov 29, 2024
ea4885e
Merge branch 'main' into change-liberate-voicevox-core
qryxip Dec 10, 2024
c5617c8
Merge branch 'main' into change-liberate-voicevox-core
qryxip Dec 12, 2024
9fde4e7
Merge branch 'main' into change-liberate-voicevox-core
qryxip Dec 12, 2024
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
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.8
if: matrix.python_whl
uses: actions/setup-python@v5
Expand Down Expand Up @@ -228,22 +215,14 @@ jobs:
if ${{ matrix.python_whl }}; then cargo set-version "$VERSION" -p voicevox_core_python_api; 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 @@ -254,26 +233,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
11 changes: 3 additions & 8 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
build-and-test-java-api:
strategy:
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
2 changes: 1 addition & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 @@ -251,7 +251,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/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.

37 changes: 18 additions & 19 deletions crates/voicevox_core/src/infer/runtimes/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ use ort::{
use crate::{
devices::{DeviceSpec, GpuSpec, SupportedDevices},
error::ErrorRepr,
voice_model::ModelBytes,
};

use super::super::{
DecryptModelError, InferenceRuntime, InferenceSessionOptions, InputScalarKind,
OutputScalarKind, OutputTensor, ParamInfo, PushInputTensor,
InferenceRuntime, InferenceSessionOptions, InputScalarKind, OutputScalarKind, OutputTensor,
ParamInfo, PushInputTensor,
};

impl InferenceRuntime for self::blocking::Onnxruntime {
Expand Down Expand Up @@ -72,7 +73,7 @@ impl InferenceRuntime for self::blocking::Onnxruntime {

fn new_session(
&self,
model: impl FnOnce() -> std::result::Result<Vec<u8>, DecryptModelError>,
model: &ModelBytes,
options: InferenceSessionOptions,
) -> anyhow::Result<(
Self::Session,
Expand All @@ -96,8 +97,10 @@ impl InferenceRuntime for self::blocking::Onnxruntime {
}
};

let model = model()?;
let sess = builder.commit_from_memory(&{ model })?;
let sess = match model {
ModelBytes::Onnx(onnx) => builder.commit_from_memory(onnx),
ModelBytes::VvBin(bin) => builder.commit_from_vv_bin(bin),
}?;

let input_param_infos = sess
.inputs
Expand Down Expand Up @@ -285,12 +288,10 @@ pub(crate) mod blocking {
/// # use voicevox_core as another_lib;
/// #
/// # fn main() -> anyhow::Result<()> {
/// # if cfg!(windows) {
/// # // Windows\System32\onnxruntime.dllを回避
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// # }
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// #
/// let ort1 = voicevox_core::blocking::Onnxruntime::load_once().exec()?;
/// let ort2 = another_lib::nonblocking::Onnxruntime::get().expect("`ort1`と同一のはず");
/// assert_eq!(ptr_addr(ort1), ptr_addr(ort2));
Expand All @@ -313,7 +314,7 @@ pub(crate) mod blocking {
/// ONNX Runtimeのライブラリ名。
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub const LIB_NAME: &'static str = "onnxruntime";
pub const LIB_NAME: &'static str = "voicevox_onnxruntime";

/// 推奨されるONNX Runtimeのバージョン。
#[cfg(feature = "load-onnxruntime")]
Expand Down Expand Up @@ -474,12 +475,10 @@ pub(crate) mod nonblocking {
/// #
/// # #[pollster::main]
/// # async fn main() -> anyhow::Result<()> {
/// # if cfg!(windows) {
/// # // Windows\System32\onnxruntime.dllを回避
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// # }
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// #
/// let ort1 = voicevox_core::nonblocking::Onnxruntime::load_once()
/// .exec()
/// .await?;
Expand Down Expand Up @@ -509,7 +508,7 @@ pub(crate) mod nonblocking {
#[cfg(feature = "load-onnxruntime")]
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
// ブロッキング版と等しいことはテストで担保
pub const LIB_NAME: &'static str = "onnxruntime";
pub const LIB_NAME: &'static str = "voicevox_onnxruntime";

/// 推奨されるONNX Runtimeのバージョン。
#[cfg(feature = "load-onnxruntime")]
Expand Down
8 changes: 4 additions & 4 deletions crates/voicevox_core/src/infer/session_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use anyhow::bail;
use enum_map::{Enum as _, EnumMap};
use itertools::Itertools as _;

use crate::error::ErrorRepr;
use crate::{error::ErrorRepr, voice_model::ModelBytes};

use super::{
model_file, InferenceDomain, InferenceInputSignature, InferenceOperation, InferenceRuntime,
InferenceDomain, InferenceInputSignature, InferenceOperation, InferenceRuntime,
InferenceSessionOptions, InferenceSignature, ParamInfo,
};

Expand All @@ -18,7 +18,7 @@ pub(crate) struct InferenceSessionSet<R: InferenceRuntime, D: InferenceDomain>(
impl<R: InferenceRuntime, D: InferenceDomain> InferenceSessionSet<R, D> {
pub(crate) fn new(
rt: &R,
model_bytes: &EnumMap<D::Operation, Vec<u8>>,
model_bytes: &EnumMap<D::Operation, ModelBytes>,
options: &EnumMap<D::Operation, InferenceSessionOptions>,
) -> anyhow::Result<Self> {
let mut sessions = model_bytes
Expand All @@ -28,7 +28,7 @@ impl<R: InferenceRuntime, D: InferenceDomain> InferenceSessionSet<R, D> {
<D::Operation as InferenceOperation>::PARAM_INFOS[op];

let (sess, actual_input_param_infos, actual_output_param_infos) =
rt.new_session(|| model_file::decrypt(model_bytes), options[op])?;
rt.new_session(model_bytes, options[op])?;

check_param_infos(expected_input_param_infos, &actual_input_param_infos)?;
check_param_infos(expected_output_param_infos, &actual_output_param_infos)?;
Expand Down
Loading
Loading