run benchmark on multi-thread#121
Conversation
| _print_stats("Pitch NED ", [r.pitch_ned for r in results]) | ||
|
|
||
|
|
||
| class Sample: |
There was a problem hiding this comment.
Thanks so much for introducing these! I'm actually a big fan of classes over tuples myself. I should really watch more carefully what the AI agents spits out.
There was a problem hiding this comment.
I (and my colleagues) are heavily using AI as well (like spend 100USD per month). Yes, AI can produce huge code in a short time, making it impossible to review every line. We havn't think about a good way to review it yet. My colleague propose to use a different AI model to review, honestly I don't think so, and this sounds ironic
There was a problem hiding this comment.
Reviewing code and ensuring that it is actually matching the requirements really seems to be the difficult part now. Orchestrating multiple agents (e.g. planning, execution, review, ...) seems to be a trend right now. And I guess everything which improves the results before you even look at it is useful. But at least as of now the cost also seems to be significant.
|
Thanks, I haven't run it yet. Looks good, feel free to hit the merge button as soon as you are ready and I will likely give it a go soon then. |
Motivation
Benchmarks take a long time to run. Since it's an important way to evaluate model and find optimization opportunities, it is worthwhile to speed up this process.
I profiled the process and found that most of the time is spent on CPU-side. GPU-side (i.e. segment and transformer inference) accounts for < 50%. Modern CPUs typically have 4+ cores, so obviously it can speed up using multiple threads (cores).
Implementation
The existing code already divides the dataset into batches (i.e.
chunksin the code), with 10 samples per batch (i.e.batch_size=10). So we just use these batches in the multi-thread execution flow:pendingqueue.completedqueue, and get a new batch.completedqueue), and prints the progress information and writes the result to the database.Results
I measured the runtime on the Polish Scores dataset:
We do get some speedup! But please note that optimization is hardware-dependent. On a machine with a strong CPU but a weak GPU, GPU inference is more likely to become the bottleneck, in which case multi-thread may provide poor improvement.
I would welcome benchmark results from other hardware configurations and look forward to receiving feedback! Simply add
--workers 3will make it work, likepoetry run python -m validation.polish-scores --tool homr --workers 3Other Changes
Again I also made several code refactor. The existing code in
run_benchmark()makes extensive use of tuples, which makes the meaning of variables hard to understand. I replaced these with classes whose named fields clearly express their intent. Also addedset_successandset_failuremethods, making the control flow easier to follow.