VOICEVOX / voicevox_core

無料で使える中品質なテキスト読み上げソフトウェア、VOICEVOXのコア
https://voicevox.hiroshiba.jp/
MIT License
844 stars 114 forks source link

onnxruntime-rsからortに乗り換える #725

Closed qryxip closed 3 months ago

qryxip commented 7 months ago

内容

関連 Issue

Resolves #718, resolves #307.

その他

qryxip commented 4 months ago

このPRですが、次のPRにブロックされている状態の認識です。

qryxip commented 3 months ago

正しいバージョンのCUDAを入れずににCUDA版のセッションを開始しようとしたときの様子。 ortってこういうとこにも変化が入っているんですね。

Before (エラー):

[INFO] __main__: Loading `../../model/sample.vvm`
Exception: Failed to create session options: Error calling ONNX Runtime C function: /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1103 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_cuda.so with error: libcublasLt.so.11: cannot open shared object file: No such file or directory

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./run.py", line 98, in <module>
    main()
  File "./run.py", line 41, in main
    synthesizer.load_voice_model(model)
voicevox_core.InvalidModelDataError: `../../model/sample.vvm`の読み込みに失敗しました: モデルデータを読むことができませんでした

After (CPU版にフォールバックして継続):

[WARNING] ort.execution_providers: An error occurred when attempting to register `CUDAExecutionProvider`: /home/runner/work/onnxruntime-builder/onnxruntime-builder/onnxruntime/core/session/provider_bridge_ort.cc:1209 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_cuda.so with error: libcublasLt.so.11: cannot open shared object file: No such file or directory

[WARNING] ort.execution_providers: No execution providers registered successfully. Falling back to CPU.
tarepan commented 3 months ago

正しいバージョンのCUDAを入れずににCUDA版のセッションを開始

こちら https://github.com/VOICEVOX/voicevox_engine/issues/709#issuecomment-1983153709 で議論されていた CUDA バージョン不一致に関して、実際に不一致が起きた場合に ort 版では CPU フォールバックになる、ということですね。
ユーザーがフォールバックに気づかず「GPU 版を使っているはずなのに遅い」という感想が出てきそうな予感もします。

qryxip commented 3 months ago

まあコア的にもAccelerationMode::Autoがあるわけですし良くはないですね。ドキュメント見たらこうあったので、EnvironmentBuilder::with_execution_provider SessionBuilder::with_execution_providerじゃなくてExecutionProvider::registerを使う方がよさそう。

To receive these registration errors, instead use ExecutionProvider::register to register an execution provider:

use ort::{CUDAExecutionProvider, ExecutionProvider, Session};

fn main() -> anyhow::Result<()> {
    let builder = Session::builder()?;

    let cuda = CUDAExecutionProvider::default();
    if cuda.register(&builder).is_err() {
        eprintln!("Failed to register CUDA!");
        std::process::exit(1);
    }

    let session = builder.commit_from_file("model.onnx")?;

    Ok(())
}

Fallback behavior - Execution providers - ort

qryxip commented 3 months ago

コアAPI的には、AccelerationMode::Autoのときに限ってフォールバック挙動(libonnxruntimeが対応してたらAccelerationMode::Gpuと同様にDML/CUDA版の開始を試み、駄目だったらエラーではなくCPU版)にしてもいいかもしれませんね。

qryxip commented 3 months ago

これでエラー挙動になるはず。 7e74743 (#725)

sevenc-nanashi commented 3 months ago

コアAPI的には、AccelerationMode::Autoのときに限ってフォールバック挙動(libonnxruntimeが対応してたらAccelerationMode::Gpuと同様にDML/CUDA版の開始を試み、駄目だったらエラーではなくCPU版)にしてもいいかもしれませんね。

Autoという単語からするとこれがかなり自然で良いと思います。

qryxip commented 3 months ago

784

qryxip commented 3 months ago

@tuna2134 (#693) @takejohn (#758)

共有です。