Skip to content

About

A set of useful tools for ModelZoo benchmark

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

How to Use

ExecTimer

Basic Usage

Suppose you have a code snippet to profile

function_a()

function_b()

function_c()

You can use this class to get the statistical time cost of each of the fucntions with minimum code change

from modelzoo_tools import ExecTimer

iters = 100

timer = ExecTimer("example.csv", iters)

for _ in range(iters):

    with timer.record_event("func_a"):
        function_a()
    
    with timer.record_event("func_b&func_c"):
        function_b()
        function_c()

timer.analyze_data()

Then, the maximum, minimum and average time cost of the records events will be output at terminals At the same time, they will be write to the .csv file as well, whose name is specified when you instantiate the class.

[INFO] Event Name            Total Cost(ms)        Max Cost(ms)          Min Cost(ms)          Avg Cost(ms)        
[INFO] func_a                365.62                200.50                165.11                182.81              
[INFO] func_b&func_c         588.45                584.59                3.86                  294.22              
[INFO] total_time            954.06                785.08                168.97                477.03     

Complex Usage

If you want to get cost time for different part with different repeative iters, you need to create multiple instantiations of ExecTimer

Suppose we have the following code to profile, and we need to do func_a() once but func_b() + func_c() for 10 times, in addition, we want to get the total excution time as well.

function_a()

function_b()

function_c()

We can do like this:

from modelzoo_tools import ExecTimer

total_timer = ExecTimer("example.csv", 1)
timer_func_a = ExecTimer("example.csv", 1)
timer_func_bc = ExecTimer("example.csv", 10)


with total_timer.record_event("e2e_time"):

    with timer.record_event("func_a"):
        function_a()

    for _ in range(10):
        with timer.record_event("func_b&func_c"):
            function_b()
            function_c()

total_timer.analyze_data()
timer_func_a.analyze_data()
timer_func_bc.analyze_data()

you will get the output like:

[INFO] Event Name     Iters       Total Cost(ms)        Max Cost(ms)          Min Cost(ms)          Avg Cost(ms)        
[INFO] e2e_time       1           1111.62               1111.62               1111.62               1111.62                      
[INFO] sum_time       1           1111.62               1111.62               1111.62               1111.62                      

[INFO] Event Name     Iters       Total Cost(ms)        Max Cost(ms)          Min Cost(ms)          Avg Cost(ms)        
[INFO] func_a         1           588.45                588.45                588.45                588.45            
[INFO] sum_time       1           588.45                588.45                588.45                588.45            


[INFO] Event Name     Iters       Total Cost(ms)        Max Cost(ms)          Min Cost(ms)          Avg Cost(ms)        
[INFO] func_b&func_c  10          3222.89               432.69                299.12                322.29            
[INFO] sum_time       10          3222.89               432.69                299.12                322.29            

Profiler

profiler.py is a python script to automatically profile your python code with rocprofv3, then generate, collect and make them a archive.

How to use:

python profiler.py -f "full_path_of_your_python_script" -o "output_file_name" --args "arg1=val1" --args "arg2=val2" ....

Suppose you have a python script "test.py" in path "/home/", in common case you run it like:

python /root/test.py --niters=10

Now, in order to get the profiling data, you need to run like this:

python profiler.py -f /root/test.py -o result_abc --args niters=10

After that, you will find all generated files with profiling result in path "modelzoo_tools/archives/2026-01-xx-xx-xx-xx/", and they will be make into a zip named "result_abc.zip" under the same path.

About

A set of useful tools for ModelZoo benchmark

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages