You’re right, we indeed have to use Variables to use autograd.

So this copy of code doesnot work, as torch.dot doesn’t support autograd, it returns a float…

You can use torch.dot with autograd, it returns a Variable with a single element.
import torch as th

v1 = th.autograd.Variable(th.randn(10), requires_grad=True)
v2 = th.autograd.Variable(th.randn(10), requires_grad=True)

res = th.dot(v1, v2)

res.backward()

print(res)

# prints
# Variable containing:
# 1.1473
# [torch.FloatTensor of size 1]