zhijian-liu / torchprofile

A general and accurate MACs / FLOPs profiler for PyTorch models
https://pypi.org/project/torchprofile/
MIT License
571 stars 39 forks source link

Is there a way to get not only the MACs count, but also the model's output? #9

Closed ji-xin closed 3 years ago

ji-xin commented 3 years ago

As in macs = profile_macs(model, inputs) - is there a way to also obtain the model's output given inputs, without running the forward pass again?

zhijian-liu commented 3 years ago

It's indeed possible. The second return from https://github.com/zhijian-liu/torchprofile/blob/master/torchprofile/utils/trace.py#L17 is actually the output of the inference. However, I'm not sure about the motivation behind this. It's always fairly easy to re-run the forward pass.

ji-xin commented 3 years ago

Thanks for the reply! It's purely for efficiency, just so I don't need to run the forward pass twice. By the way, do you know how fast a forward pass with profile_mac is compared with a usual one?