Skip to content

Conversation

@PhilippNaused
Copy link
Contributor

@PhilippNaused PhilippNaused commented Jun 25, 2025

Add a simple benchmark project.
It tests the performance of the tokenizer, text pre-processing and inference.
You can run it by calling:
dotnet run --project Benchmark -c Release

Example output:

| Method         |         Mean |       Error |      StdDev |
|----------------|-------------:|------------:|------------:|
| PreprocessText |     202.9 μs |     1.13 μs |     1.05 μs |
| Phonemize      | 148,545.9 μs | 2,866.41 μs | 2,541.00 μs |
| Tokenize       | 147,700.7 μs | 2,047.23 μs | 1,814.82 μs |
| Method | Model   |       Mean |    Error |   StdDev |
|--------|---------|-----------:|---------:|---------:|
| CPU    | float32 |   462.5 ms |  9.19 ms | 16.33 ms |
| CUDA   | float32 |   134.8 ms |  3.20 ms |  9.43 ms |
| CPU    | float16 |   432.3 ms |  8.63 ms | 15.99 ms |
| CUDA   | float16 |   214.0 ms |  3.36 ms |  3.14 ms |
| CPU    | int8    | 1,887.4 ms | 37.52 ms | 86.21 ms |
| CUDA   | int8    | 2,106.5 ms | 41.13 ms | 57.66 ms |

@PhilippNaused
Copy link
Contributor Author

@Lyrcaxis Could you review this when you have the time?

@Lyrcaxis
Copy link
Owner

Lyrcaxis commented Aug 6, 2025

@PhilippNaused Hey, thanks for the PR! I've reviewed this for some time now -- code looks good.

I've been thinking on whether we want a benchmark project in the repo -- what value it would add, any pitfalls, etc.
Thoughts so far:

Pros: I guess it could get curious people somewhat more involved to making edits and comparing performance (?)
Cons: It might not be very relevant past the GPU vs CPU benchmarks. Not until batching is officially supported, at least.

So I thought I'd give it some time since it's not an engine feature, but sorry, it's indeed been a while 😅 (month+)

Are you looking forward to using the Benchmark project for more stuff/automations/metrics/docs / expand on it?
In that case it can get merged asap. Anyway let me know your thoughts.

Lyrcaxis
Lyrcaxis previously approved these changes Aug 6, 2025
Copy link
Owner

@Lyrcaxis Lyrcaxis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Few comments and minor styling tweaks here and there.

Let's talk about the potential of this benchmark project for a bit first before merging though.

Comment on lines +24 to +29
var options2 = new Microsoft.ML.OnnxRuntime.SessionOptions();
options2.AppendExecutionProvider_CUDA(); // Use CUDA for GPU inference.
models[(model, true)] = new KokoroModel(KokoroTTS.ModelNamesMap[model], options2);
Copy link
Owner

@Lyrcaxis Lyrcaxis Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require the benchmarker to tweak a non-highest-level file if they don't use CUDA.
Preferrably this would be an option configurable from the highest-level Program.cs or the CLI args.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best option would be to split the benchmark into two classes. One for comparing the models on CPU and one for CPU vs GPU.
e.g.,

public class Inference {
...
}

public class InferenceCPUvsCUDA : Inference {
...
}

Then you can select which one you like from the CLI using BenchmarkDotNet built-in benchmark selector.

I'm just not too happy with the name InferenceCPUvsCUDA...

Comment on lines +1 to +3
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of implicit Program/Main but could make sense here if it's a one-liner.
I think it shouldn't be a one-liner though and could have more options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean you would prefer this?

BenchmarkDotNet.Running.BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

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.

2 participants