Hi Yifan_Xu,
Backward for a vector tensor certainly does not work without the input gradient.
One reason the above code may be working is that the size_average argument has been deprecated in the current version of pytorch, in favour of the reduction argument, which has a default value of ‘mean’. Hence, the above code may unintentionally calculated gradient on a scalar tensor.
Hope this helps.