I guess, both should give the same output; as both will give the list of layers in the network.
But, I’m not able to try your approach which I think might be because of version mismatch.
I currently have 0.4.0 pytorch version.