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

change: liberate VOICEVOX CORE #825

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 user.email=dummy@dummy.dummy 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 -vv --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 -vv --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 -vv --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 -vv # 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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ zip = "0.6.3"

[workspace.dependencies.voicevox-ort]
git = "https://github.com/VOICEVOX/ort.git"
rev = "8627833456a69e7841ae2a29fd184752df8de8d9"
rev = "3ecf05d66e2e04435fde3c8200e5208ce2707eb7"

[workspace.dependencies.open_jtalk]
git = "https://github.com/VOICEVOX/open_jtalk-rs.git"
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
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
8 changes: 2 additions & 6 deletions crates/voicevox_core/src/infer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub(crate) mod domains;
mod model_file;
pub(crate) mod runtimes;
pub(crate) mod session_set;

Expand All @@ -13,6 +12,7 @@ use thiserror::Error;

use crate::{
devices::{DeviceSpec, GpuSpec},
voice_model::ModelBytes,
StyleType, SupportedDevices,
};

Expand All @@ -37,7 +37,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 Down Expand Up @@ -212,7 +212,3 @@ pub(crate) enum ExtractError {
#[error(transparent)]
Shape(#[from] ShapeError),
}

#[derive(Error, Debug)]
#[error("不正なモデルファイルです")]
pub(crate) struct DecryptModelError;
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 @@ -271,12 +274,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 @@ -299,7 +300,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 @@ -460,12 +461,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 @@ -495,7 +494,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
29 changes: 26 additions & 3 deletions crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,41 @@ pub(crate) type ManifestDomains = (Option<TalkManifest>,);
#[index_for_fields(TalkOperation)]
pub(crate) struct TalkManifest {
#[index_for_fields(TalkOperation::PredictDuration)]
pub(crate) predict_duration_filename: Arc<str>,
pub(crate) predict_duration: ModelFile,

#[index_for_fields(TalkOperation::PredictIntonation)]
pub(crate) predict_intonation_filename: Arc<str>,
pub(crate) predict_intonation: ModelFile,

#[index_for_fields(TalkOperation::Decode)]
pub(crate) decode_filename: Arc<str>,
pub(crate) decode: ModelFile,

#[serde(default)]
pub(crate) style_id_to_inner_voice_id: StyleIdToInnerVoiceId,
}

#[derive(Deserialize, Clone)]
pub(crate) struct ModelFile {
pub(crate) r#type: ModelFileType,
pub(crate) filename: Arc<str>,
}

#[cfg(test)]
impl Default for ModelFile {
fn default() -> Self {
Self {
r#type: ModelFileType::Onnx,
filename: "".into(),
}
}
}

#[derive(Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ModelFileType {
Onnx,
VvBin,
}

#[serde_as]
#[derive(Default, Clone, Deref, Deserialize)]
#[deref(forward)]
Expand Down
Loading
Loading