-
Notifications
You must be signed in to change notification settings - Fork 127
Description
内容
asyncなタスクに一般的に期待される機能の一つとして、キャンセル可能であるというのがあると思います。しかし現状の実装では、ONNX Runtimeの推論はasyncの文脈でキャンセルすることができません。何故ならスレッドは外から停止できないからです。ここでONNX RuntimeのRunOptions::SetTerminate
によって、推論のキャンセルを可能することを提案します。
terminate
というプロパティですが、次のように説明されています。
If a currently executing session needs to be force terminated, this can be called from another thread to force it to fail with an error.
(C API)
Set to True to terminate any currently executing calls that are using this RunOptions instance. The individual calls will exit gracefully and return an error status.
(Python API)
意味を掴みかねていたのですが、コードを見るとbool terminate
をconst bool&
で引き回してそれをチェックし続けていました。試してはいないのですが、あるRunOptions
で推論を開始したあと、そのRunOptions
のterminate
をtrue
にセットすると、"Exiting due to terminate flag being set to true."
というメッセージと共に推論が止まってくれるということだと予想しています。
APIとしては次のような形がよいのかなと思っています。
同期/非同期APIにおいて、Synthesizer
の各操作はclass SynthesisTask
を返すようにする。SynthesisTask
は.wait()
で続行、.cancel()
でキャンセルする。
- 同期/非同期APIにおいて、
Synthesizer
の各メソッドに推論キャンセルのためのオプションを一つ追加する。例えば#[repr(C)] struct VoicevoxInferenceCanceller
。
(追記) 直にbool
でもいけるかもしれない - 非同期APIにおいては、さらにasync文脈でのキャンセルでも推論をキャンセルするようにする。
Pros 良くなる点
- asyncなAPIとして完成に近づく
- 推論の中止ができる
Cons 悪くなる点
実現方法
VOICEVOXのバージョン
N/A
OSの種類/ディストリ/バージョン
- Windows
- macOS
- Linux
その他
TFLiteにもキャンセル機構があるようです。