Counting operations

Is there a recommended way to count the number of operations a network performs during inference?

2 Likes

we could build a script / utility for this. The best method would be to count operations of traces.

There are now scripts that can take a network output and visualize the network. Stuff like https://gist.github.com/apaszke/f93a377244be9bfcb96d3547b9bc424d
https://github.com/e-lab/pytorch-toolbox/tree/master/model_graph

Taking them and modifying them to loop over ops and doing a total count of ops (based on the autograd Function name + size of inputs) is probably the best way of going about this.

One such utility script written for lua-torch has the “ops per Function” in this file: https://github.com/e-lab/Torch7-profiling/blob/master/src/profiler.lua

3 Likes

Thanks for the advice. I’ll look at those scripts.

There is a new version here: https://github.com/e-lab/pytorch-toolbox/tree/master/profiler

2 Likes