pacnet icon indicating copy to clipboard operation
pacnet copied to clipboard

About "Native Implemention"

Open JUGGHM opened this issue 4 years ago • 6 comments

Hi Suhang! Thanks for your sharing the code! I just wonder why there is a native implemention to control the computational flow. Is there any theoretical or performance differences between the native implemantion and non-native implemention?

JUGGHM avatar Aug 18 '20 09:08 JUGGHM

The native implementation is using only standard pytorch layers/operations, while the other one uses the Function interface at places. The latter can have some memory advantage for larger input sizes.

suhangpro avatar Aug 19 '20 17:08 suhangpro

Hey Hang, thanks for the comment! Additionally I am wondering if you have any statistics on how big the performance gap is between native and functional implementations, especially in case of large input sizes, or any differences in backprop speed, because I did some basic benchmarking and did not find significant difference there. Thanks!

Jerrypiglet avatar Dec 04 '20 06:12 Jerrypiglet

There shouldn't be any noticeable differences in speed. The non-native implementation has advantages in terms of peak memory usage, but I have no statistics regarding the gap. The native version was there mostly for debugging purposes, and the non-native version should be the preferred option now.

suhangpro avatar Dec 04 '20 07:12 suhangpro

Ah i see. Thanks! The native version would also be useful for prototyping because it is easier to build upon.

Jerrypiglet avatar Dec 04 '20 07:12 Jerrypiglet

Hey Hang, after a second thought, the original version is actually correct to me. kernel will be used when you compute grad_input, and input will be used when you compute grad_kernel. See the highlights below. image

In your updated version I suppose you will see errors in https://github.com/NVlabs/pacnet/blob/master/pac.py#L352 that input is None when ctx.needs_input_grad[0] == False and ctx.needs_input_grad[0] == True. Am I right?

Jerrypiglet avatar Dec 04 '20 17:12 Jerrypiglet

@Jerrypiglet That's right. I wasn't careful enough on this. The change is now reverted.

suhangpro avatar Dec 04 '20 18:12 suhangpro