Open TimCJanke opened 8 months ago
Thanks for your report!
Hello, this issue has been fixed. But the result may be different from thop's. Onnx-tool also considers sigmoid and tanh activation MACs into count.
You can view the change in this commit dd895b056f1eded06cf8fede9176dba0516cd37f
Describe the bug MACs calculation is broken for recurrent layers, i.e., if there are T time steps, MACs are off by a factor of T. Code below reproduces the bug for GRU and LSTM layers, it works correctly for looping over a linear layer (although MAC numbers are not perfectly identical). For LSTM and GRU layers, thop (correctly) calculates MACs that are 100x higher for the torch model compared to the onnx model using onnx-tool.
This is the result of running code below:
Layer Type: linear
torch thop profiler results: Params: 4160 MACs: 409600
onnx-tool profiler results: Params: 4160 MACs: 416000
Layer Type: lstm
Layer Type: gru
To Reproduce The code below creates a torch model with a single recurrent layer and measures MACs for torch model using thop and for exported onnx models using onnx-tool. torch == 1.13.1 onnx-tool == 0.8.5