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

Rust #205

Merged
merged 67 commits into from
Aug 6, 2022
Merged

Rust #205

merged 67 commits into from
Aug 6, 2022

Conversation

qwerty2501
Copy link
Contributor

内容

Conflict具合を確認するためのPRです

関連 Issue

refs #128

その他

qwerty2501 and others added 30 commits May 15, 2022 10:04
* いったんC++関係のコードを削除

* とりあえずcargo initializeと関数定義だけ

* APIを既存のものに合わせて定義しなおした

* cargo projectをworkspace化

* テストCI追加

* last_error_messageの定義が抜けていたので修正

* internal関数に定義を分けた

* anyhowやめた

* 元あったヘッダーファイルに合わせて出力されるように定義を変更した

* result 変換方法を変更

* 従来どおりの出力をするように修正

- バイナリ名を従来通りcoreに変更
- ヘッダを従来どおりcore.hに変更
- workaroundでworkspaceのルートディレクトリを取得しその配下のtargetにヘッダを出力するようにした

* ERROR_MESSAGEをonce cell化

* Succeed渡したときでもメッセージを返すように修正

#126 (comment)

* VoicevoxResultCodeのエラーメッセージとErrorのベースとなる文字列を同一にするようにした

* output_binary_sizeの型をCのintに変更

* output_binary_sizeの型をc_intに変更

* 不要な文言を削除

* 今後workspace内にcrateが増えるとサブディレクトリがいっぱいできるのでrootディレクトリにディレクトリが増えすぎないようにcratesサブディレクトリ内に移動させた

* 無駄な空行を削除

* 不要な空白行を削除

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>

* 現状かならずCIテストが失敗するようになっているのでbuild.ymlを削除

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
* 簡単なテストコードとtestingライブラリの導入

参考になりそうな簡単なテストコードと独断ですがtestingライブラリを導入しました

* pull_request時にtestが実行されるようにした
* Statusを仮実装した

* get_supported_devices を仮実装した

* エラーの名前とsourceの修正

* initialize関数を仮実装した

* get_supported_devicesが動作するかどうか確認するためのテストを追加

* lint errorを修正した

* version up onnxruntime-rs to 0.0.17

* TODOコメント追加

* Update crates/voicevox_core/Cargo.toml

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
現在Cargo.lockファイルはgit管理対象外になっているが、cargoにはCargo.lockファイルをgit管理対象に入れるべき場合とそうでない場合がある。
Cargo.lockファイルをgit管理対象に入れないべき場合はcargo.ioなどでソースファイルごとライブラリとして公開し、ユーザー側でビルドする場合
git管理対象に入れる場合は配布形態がバイナリ等ソースコードに依存しない形で配布する場合
本リポジトリはcdylib形式でdllバイナリとして配布することを目的としているのでgit管理対象に入れるべきケースになる

詳しくは公式ドキュメントを参照のこと
https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

refs #128
* load_metasを実装した

* Statusのnew関数テストを追加した

* load_metasのテストを追加した

* なぜか.が入っていたため削除

* assertでresultの内容を表示するようにした

* output err string

* エラーを詳細に表示するように修正

* cache keyを設定した

* onnxruntime versionup

* Windows2019向けのlibclang install

* onnxruntime version up

* キャッシュ制御を環境変数で行うことをやめた
* onnxruntime-rs をアップデートした

* 消してしまっていたSessionのlifetimeを復活させた
* load_modelの際にInvalid dimensionsが発生する
* エラー対策したonnxruntime にアップデートした
* add supported_devices implementation

* cargo fmt

* remove extra use

* get supported_devices string only at initialization

* implement test for supported_devices c api

* change global variable name
internal.rsに load_modelを実装した

statusの方にのみ実装されていたのでinternal.rsに実装した
* is_model_loadedを実装した

* is_model_loadedに渡す数値をspeaker_idではなくmodel_indexにした
* internalを構造体化して薄いラッパーにした

testコードを書きやすくするため、internalのコードを一部を除いて構造体のメンバ関数とした

refs #128 (comment)

* lint errorを修正した
* fix load_model

* add tests of load_model and is_model_loaded

* add test case

* implement tests without fixture

* show result if error occured in test load_model_works

* change return value of get_model_index_and_speaker_id to optional

C++実装と挙動が異なるが、SPEAKER_ID_MAPのキーに含まれないspeaker_idを引数
として渡すと結果は未定義動作であるため、許容する

* validate model_index in Status::load_model

* add fields variable to InvalidSpeakerId and InvalidModelIndex error

* oracle of clippy
assert_eq!で比較できるところは比較するようにした
* add yukarin_s_forward implementation

* use replace method

* use std::slice::from_raw_parts_mut

* change argument type of Internal::yukarin_s_forward

* fix to use proper speaker_id

* use assert_eq
…含む) (#158)

* add yukarin_s_forward implementation

* use replace method

* use std::slice::from_raw_parts_mut

* change argument type of Internal::yukarin_s_forward

* fix to use proper speaker_id

* use assert_eq

* add yukarin_sa_forward implementation

* add decode_forward implementation

* Update crates/voicevox_core/src/internal.rs

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>

* add tensor of speaker_id in yukarin_sa_forward

* remove allow unused_variables attribute

* update onnxruntime-rs version to 0.0.24, and implement decode_forward

* change return value of *-forward

* change the way to convert from OrtOwnedTensor to Vec

* add tests of yukarin_sa_forward and decode_forward

* trivial change

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
cargo auditを追加

[cargo-audit](https://crates.io/crates/cargo-audit) をCI上で実行することにより脆弱性のあるライブラリがないか確認できるようにする
* 音が途切れてしまうのを避けるworkaround処理を追加した

* padding_phonemeを一まとまりにするように修正した

* paddingのsize変数名をpadding_sizeに統一した
* WIP: kana parser

* add: parse_kana/create_kana

* add: error handling, tests

* fix: removed unused #[derive()]

* fix: cargo clippy

* modify: modified directory layout

* fmt: cargo fmt

* fixx: mistake

* modify: module layout

* fix: reflect reviews

* fix: use hashMap instead of BTreeMap

* change: use rstest for mod tests

* Update crates/voicevox_core/src/engine/kana_parser.rs

fix: use rstest

Co-authored-by: Gray Suitcase <41382894+PickledChair@users.noreply.github.com>

* update: use #[derive(new, Getter)]

Co-authored-by: qwerty2501 <939468+qwerty2501@users.noreply.github.com>

* fix: use rstest

Co-authored-by: Gray Suitcase <41382894+PickledChair@users.noreply.github.com>

* fix: use rstest

Co-authored-by: Gray Suitcase <41382894+PickledChair@users.noreply.github.com>

* fix: use new() and getters

* fmt: clippy

* update: define setters for requiring attrs

Co-authored-by: Gray Suitcase <41382894+PickledChair@users.noreply.github.com>
Co-authored-by: qwerty2501 <939468+qwerty2501@users.noreply.github.com>
* OpenJtalkを実装した

refs #128

* open_jtalk-rs更新

* Update crates/voicevox_core/src/engine/open_jtalk.rs

mecab2njdが抜けていたので追加

Co-authored-by: Gray Suitcase <41382894+PickledChair@users.noreply.github.com>

Co-authored-by: Gray Suitcase <41382894+PickledChair@users.noreply.github.com>
* call decode_forward for allocating gpu memory

* イントネーションの推論をCPUで行うようにする
mecab_dict_index関数をwrapperに追加したことによる対応です
* internalからunsafeを取り除いてc_export側でのみunsafeを使うようにした

unsafeなコードを使う領域を減らして安全なコードな領域を増やすためinternalで使用していたunsafeなコードをc_exportがわに閉じ込めた

* fixed lint error

* fixed ci test error
実装を複数人で分けて行う場合、SynthesisEngineの定義がないと実装が競合したり実装を進めにくくなってしまうのであらかじめ仮実装するようにした
* added clippy check when no tests

* CIエラーを修正した
* prepare onnxruntime.dll for test on windows-2022

* add comment
unsafeなコードを原則禁止にした

unsafe_codeをdenyにすることにより、うっかりunsafeコードを書くのを防ぐことが目的
例外としてc関数向けの実装である c_export moduleと、static領域に配置する必要があるStatus structについてはunsafeを使うことを許可している

refs #128
update open_jtalk 0.1.7
qwerty2501 and others added 2 commits July 24, 2022 14:35
* RPATHの設定をした

* build.rs で設定できるようになったので不要な処理を削除
* デフォルト引数はC言語では使えないのでC++のみに有効になるように変更した (#122)

本当はデフォルト引数を消したかったが、使ってる人がいる可能性があるためC++で使ってる場合はそのままにするように修正した

* initializeで全モデルを読み込まなくても良いようにした (#124)

* load_model関数を切り出す

* load_modelとis_model_loadedを足した

* 使われてないエラーメッセージを消去

* Update core/src/core.cpp

Co-authored-by: qwerty2501 <939468+qwerty2501@users.noreply.github.com>

* Update core/src/core.cpp

Co-authored-by: qwerty2501 <939468+qwerty2501@users.noreply.github.com>

* Update core/src/core.cpp

Co-authored-by: qwerty2501 <939468+qwerty2501@users.noreply.github.com>

* pythonのラッパーの型を変更

* load_all_models追加

* return true

Co-authored-by: qwerty2501 <939468+qwerty2501@users.noreply.github.com>

* workflow_dispatchでもビルド開始可能に (#127)

* ビルド時にREADMEファイルを追加する (#131)

* append unit testing framework (#121)

* Catch2をプロジェクト導入して参考となる1ケースを追加した

* リリース用ビルドにはテストビルドは不要のため無効化する変数を追加した

* テストコードの短縮化を行った

* READMEにテスト実行方法を追加

* テストをビルドするかどうかのフラグをデフォルトOFFにした

* テストをビルドするかどうかのフラグを変更したことによりREADMEを修正

* MSVCに対して足りないオプションを追加

- utf8文字列でコンパイルするように指定
- C++20を明示的に指定
- __cplusplusの値を利用中のC++のバージョンに合わせるように指定(ないとC++98相当になるとか)

* Configがリリースの場合のみに最適化オプションを指定するように修正

* オプションの指定を短くまとめた

* coreの標準ライブラリもバージョンアップした

* compile optionsの修正

* Catch2にもCXX_STANDARD 20を追加

* Windows環境でビルドできるように設定を修正

#121 (comment)

* format 効いてしまっていたところを修正

* static castやnullopt比較をやめ、value関数などを使うようにする (#118)

* use value and has value

* remove has_value

* coreのビルド時にバージョン情報がちゃんと
入るようにする

* hotfix イントネーションの推論をCPUで行うように (#146)

* python example for 0.12, update FFI (#138)

* .gitignore open_jtalk_dic in example (#148)

* .gitignore open_jtalk_dic in example

* modify: example/python/.gitignore

* C++サンプルコードへのリンクを追加 (#142)

* C++サンプルコードへのリンクを追加

* #readme

* Update README.md

* コード署名できるようにする (#164)

* コード署名

* build_util

* artifact/

* a

* remove

* inputのbooleanは文字列として渡ってくるので判定を修正 (#166)

* inputのbooleanは文字列として渡ってくるので判定を修正

* 修正もれ

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
Co-authored-by: Yuto Ashida <y-chan@y-chan.dev>
Co-authored-by: Yosshi999 <Yosshi999@users.noreply.github.com>
Co-authored-by: nebocco <73807432+nebocco@users.noreply.github.com>
@qwerty2501
Copy link
Contributor Author

あれまだconflictするな

@qwerty2501
Copy link
Contributor Author

@PickledChair #204 もしかしてこれsquash mergeしちゃいました?

@PickledChair
Copy link
Member

@PickledChair #204 もしかしてこれsquash mergeしちゃいました?

ああ、確かに……! ミスですね、すみません……

@qwerty2501
Copy link
Contributor Author

qwerty2501 commented Jul 24, 2022

うーんこれはいったん #204 のmergeをreset( revertではなく) して、rust branchにforce pushしたあと#204 のブランチを再度mergeするのがいいですかね・・・?

@PickledChair
Copy link
Member

うーんこれはいったん #204 のmergeをreset( revertではなく) して、rust branchにforce pushしたあと#204 のブランチを再度mergeするのがいいですかね・・・?

それが良いかもしれません。 @Hiroshiba さんに頼むことになると思いますが……

@qwerty2501
Copy link
Contributor Author

いやrevertでもいけるかな?ちょっとやってみます

@PickledChair
Copy link
Member

@qwerty2501 申し訳ないです。よろしくお願いします。

@qwerty2501
Copy link
Contributor Author

いけそうだったんでつくりました #206

Hiroshiba and others added 3 commits July 24, 2022 23:34
mainブランチとのconflict解消がうまく行ってなかったのでリトライ
* pythonのexampleを新しい形に変更した

refs #128

* typo修正

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>

* 不要な手順を削除した

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
* rustのAPIに追従するように変更

* README.md修正

* GetOpenJTalkDictの戻り値をUTF-8に変更。
wide_to_multi_capi関数が不要になったので削除。

Co-authored-by: shigobu <shigobu@shigobu.com>
Co-authored-by: kasamatsu <kasamatsu@kasa.com>
@qwerty2501 qwerty2501 marked this pull request as ready for review July 28, 2022 17:53
@qwerty2501
Copy link
Contributor Author

そろそろmergeできそうですかね?

@Hiroshiba
Copy link
Member

マージできそう!
と思ったのですが、issue側のリスト見るとDirectML 対応が残っていそうでした。
(リストアップありがたい・・・!!!)

@qwerty2501
Copy link
Contributor Author

DirectMLに対応しなくてはならない場合、onnxruntime-rsのダウンロード処理をかなり書き換えないといけなさそうなんですが、どれをダウンロードすればいいかよくわかってないです

@qwerty2501
Copy link
Contributor Author

いや、DirectMLについては一時的にREADMEでコメントアウトしてたのでまだ対応しないのかなと思ってたんですが今やりますか?
結構かかりそうなんですけど...

@PickledChair
Copy link
Member

PickledChair commented Jul 29, 2022

DirectMLに対応しなくてはならない場合、onnxruntime-rsのダウンロード処理をかなり書き換えないといけなさそうなんですが、どれをダウンロードすればいいかよくわかってないです

確かに、他の配布物と条件が違う点が多いので、DirectML 版 onnxrtuntime だけダウンロード処理の実装を例外的にしなければならない感じがありますね……。パッと思いつくだけで以下のような差異がありそうでした:

runtimes
├── win-arm
│   └── native
│       ├── onnxruntime.dll
│       └── onnxruntime.lib
├── win-arm64
│   └── native
│       ├── onnxruntime.dll
│       └── onnxruntime.lib
├── win-x64
│   └── native
│       ├── onnxruntime.dll
│       └── onnxruntime.lib
└── win-x86
    └── native
        ├── onnxruntime.dll
        └── onnxruntime.lib
  • 動作に必要な DirectML 関連の dll は含まれていない: 別途自前で用意しなければならない。C++ 版のビルド手順では以下で行われている:

# download directml
- name: Download DirectML
if: steps.directml-cache.outputs.cache-hit != 'true' && endswith(matrix.artifact_name, '-directml')
shell: bash
run: |
curl -L "${{matrix.directml_url}}" -o download/directml.zip
mkdir -p download/directml
# strip-components
TEMPDIR=$(mktemp -d)
unzip download/directml.zip -d "${TEMPDIR}"
mv "${TEMPDIR}"/* download/directml/.
rm -rf "${TEMPDIR}"
rm download/directml.zip
ls download/directml

@Hiroshiba
Copy link
Member

Hiroshiba commented Jul 29, 2022

まず、DirectML版は特にAMD GPUユーザーから支持を受けているので、なくなるのはなるべく避けたい感じです。
今やるべきかですが、0.13系のリリースまでに機能実装されていれば問題無さそうではあります。
また、mainにマージして、DirectMLが使える過去版から0.13をリリースすることもできなくはないはずです。
(運用コストと何かミスするリスクがちょい上がります)

@qwerty2501
Copy link
Contributor Author

とりあえずdownloadの修正できないかやってみます

@qwerty2501
Copy link
Contributor Author

qwerty2501 commented Jul 29, 2022

PR出しました
VOICEVOX/onnxruntime-rs#1
思ってたほど大きな変更がなかったかなと

qwerty2501 and others added 3 commits August 3, 2022 02:41
* directml用release buildを作成

* onnxruntimeを0.0.29にバージョンアップ

* CIテストをfeatures指定で動作するようにしてテストが通るようにした

* lint時にはdownlaodを行わないようにした
* [Rust] README追記、エラーが起きる話者IDを大きく

* 修正漏れ
@Hiroshiba Hiroshiba merged commit 129b2d2 into main Aug 6, 2022
@Hiroshiba Hiroshiba deleted the rust branch April 29, 2023 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants