File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1010
1111 <ItemGroup >
1212 <PackageReference Include =" BenchmarkDotNet" Version =" 0.15.2" />
13+ <PackageReference Include =" Microsoft.ML.OnnxRuntime.Gpu" Version =" 1.22.0" />
1314 </ItemGroup >
1415
1516 <ItemGroup >
Original file line number Diff line number Diff line change 1+ using BenchmarkDotNet . Attributes ;
2+
3+ using KokoroSharp ;
4+ using KokoroSharp . Core ;
5+
6+ namespace Benchmark ;
7+
8+ [ InProcess ]
9+ public class Inference {
10+ const string text = "This is a performance benchmark of Kokoro." ;
11+ static readonly Dictionary < ( KModel , bool UseCuda ) , KokoroModel > models = [ ] ;
12+ static int [ ] ? tokens ;
13+ static KokoroVoice ? voice ;
14+
15+ [ GlobalSetup ]
16+ public void Setup ( ) {
17+ tokens = KokoroSharp . Processing . Tokenizer . Tokenize ( text ) ;
18+ voice = KokoroVoiceManager . GetVoice ( "af_heart" ) ;
19+ foreach ( var model in Enum . GetValues < KModel > ( ) ) {
20+ if ( ! KokoroTTS . IsDownloaded ( model ) )
21+ KokoroTTS . LoadModel ( model ) . Dispose ( ) ; // downloads the model if not already present.
22+ var options = new Microsoft . ML . OnnxRuntime . SessionOptions ( ) ;
23+ models [ ( model , false ) ] = new KokoroModel ( KokoroTTS . ModelNamesMap [ model ] , options ) ;
24+ var options2 = new Microsoft . ML . OnnxRuntime . SessionOptions ( ) ;
25+ options2 . AppendExecutionProvider_CUDA ( ) ; // Use CUDA for GPU inference.
26+ models [ ( model , true ) ] = new KokoroModel ( KokoroTTS . ModelNamesMap [ model ] , options2 ) ;
27+ }
28+ }
29+
30+ [ ParamsAllValues ]
31+ public KModel Model { get ; set ; }
32+
33+ [ Benchmark ]
34+ public float [ ] CPU ( ) {
35+ return models [ ( Model , false ) ] . Infer ( tokens , voice ! . Features ) ;
36+ }
37+
38+ [ Benchmark ]
39+ public float [ ] CUDA ( ) {
40+ return models [ ( Model , true ) ] . Infer ( tokens , voice ! . Features ) ;
41+ }
42+ }
Original file line number Diff line number Diff line change 88public enum KModel { float32 , float16 , int8 }
99
1010public partial class KokoroTTS {
11- static IReadOnlyDictionary < KModel , string > ModelNamesMap { get ; } = new Dictionary < KModel , string > ( ) {
11+ internal static IReadOnlyDictionary < KModel , string > ModelNamesMap { get ; } = new Dictionary < KModel , string > ( ) {
1212 { float32 , "kokoro.onnx" } ,
1313 { float16 , "kokoro-quant.onnx" } ,
1414 { int8 , "kokoro-quant-convinteger.onnx" } ,
You can’t perform that action at this time.
0 commit comments