Thank you. Your solution solved my problem. But I am just wondering how come torch.Tensor([1,cosval,cosval]) is not differentiable and torch.cat((torch.Tensor([1]),cosval,cosval)) is differentiable?. Is it because torch.Tensor() is a leaf node where as torch.cat() is a torch op and makes it as a part of the graph?