Why passing in tensor instead of Variable when backward?

Hi, I just realized Variable.grad field is also a Variable, it thus seems more natural to pass gradients as a Variable when doing backward (currently it must be a tensor). Any reason for such an interface?

1 Like

.grad has been changed to a Variable only a day or two before the release, because we didn’t want the user code to break when we add support for multiple backward. Still, we’ve left this as-is, because most people don’t care about differentiating the backward graph, and they would pass non-volatile Variables, and that would slow down the backward.

I don’t think you can pass in a Variable there right now, but you certainly will be able to in the future.

I see… Thanks for your explanation @apaszke :slight_smile: