I resolved it. I learned the model output only should be transformed by some differentiable function (grad_fn) , such as exp, log, etc, in order to compute some loss value. Perhaps it was my lack of fundamentals of DL and Pytorch skills. Thank again.