Hi,
@CedricLy 's suggestion is the correct way of doing it.
Note that torch.tensor(another_tensor) works like tensor.clone().detach() which causes the trouble you have mentioned.
Also, you are printing a1.grad which gives you a tensor instead of None because it should not be a leaf tensor but because of the torch.tensor(tensor, requires_grad=True), it creates a leaf tensor.
About the second issue, l11 and l12 are scalars but they should be at least 1D tensors which you achieve it by using tensor.unsqueeze(dim).
But as a general tip, if you use any functions other than methods provided by PyTorch, you are breaking the computational graph. So, always try to use PyTorch semantics as it also help you to find bugs later on.
And, following tutorials can help you a lot as they are very well written (and of course documentations).
Bests