CTranslate2 icon indicating copy to clipboard operation
CTranslate2 copied to clipboard

[Feature Request] Expose Profiler to Python

Open yehudaorel opened this issue 7 months ago • 1 comments

Problem

We am working on analyzing the performance of different layers of a workload and comparing the performance with different backends.

The current issue is that we are running whisper via python and were not able to use the built in profiler

I came across this comment which surprised me it still has not been implemented.

Solution

As a workaround, I exposed the profiler to python with some small code modifications and it seemed to function smoothly on my linux env.

see changes here: https://github.com/OpenNMT/CTranslate2/compare/master...yehudaorel:CTranslate2:python_profiler

I am aware I hard coded threads and device but this can easily be fixed.

Usage:

import ctranslate2

ctranslate2.init_profiler()
 # Translate/Transcribe
ctranslate2.dump_profiler()

I understand this is a very niche request but would be extremely beneficial to have integrated and properly documented. Let me know if you would like me to refine the implementation and open a PR for the fix. Either way I thought to leave this hear in case someone else would like to use it in the future.

yehudaorel avatar Jul 04 '24 00:07 yehudaorel