As I said, I think in this code u r returning a Python float object, and that doesn’t have a .backward() method.
I’m unclear about what the tensor_mul, vec_minus are, but the operations u apply to the outputs should all the Pytorch operations, involving some numpy operations would probably break the graph(I’m not sure).
If u return a FloatTensor like u described. The tensor would be a “Leaf variable”(I’m not sure what exactly it should be called), and these kind of variable does not have gradients because u created them out of a float, which holds no gradients information.