nmhkahn / torchsummaryX

torchsummaryX: Improved visualization tool of torchsummary
302 stars 32 forks source link

negative MAdds appear, shall update datatype of np.int32 to int64 #23

Open canornot opened 2 years ago

canornot commented 2 years ago

For large networks, negative MAdds appear. It's because the caculated macs exceed the data range at line 53:

param.nelement() returns python int64 but np.prod(info["out"][2:])) returns numpy np.int32

multiplication of these two gives np.int32, with maximum value limitation of 2,147,483,647

Shall update line 53 into info["macs"] += param.nelement() * int(np.prod(info["out"][2:]))

so that maximum limitation of both mulitpliers, as well as results are 9,223,372,036,854,775,807