Hi @harishkool,
Here the graph built by autograd will represent only " y = mat . inpt".
That’s because mat = Variable(torch.Tensor([1,cosval,cosval])) is a leaf node (think that mat creation torch.Tensor([1,cosval,cosval] is not a differentiable operation).
Also Variable is deprecated and you should use Tensor instead.
If you replace them by Tensor and use torch.cat to create mat:
mat = torch.cat((torch.Tensor([1]), cosval, cosval))

it should do.
You will also need to call retain_grad on Tensors you want to access the gradient after the backward pass. So you should end up with something like:
import torch

theta = torch.randn(1, requires_grad=True)*3.1414
theta.retain_grad()

cosval = torch.cos(theta)
cosval.retain_grad()

mat = torch.cat((torch.Tensor([1]), cosval, cosval))
mat.retain_grad()

inpt = torch.Tensor([3,3,3])
y = torch.dot(mat,inpt)
y.backward(torch.ones(3))