In the below code; building the a1 tensor seems to “lose” the gradients - what would be the correct way to use l11 and l12 in further computations that would be included in the backward call?
x = torch.tensor([3.0,5.0], requires_grad=True)
w11 = torch.tensor([5.0,2.0], requires_grad=True)
w12 = torch.tensor([1.5,3.5], requires_grad=True)

w21 = torch.tensor([-0.5,2.0], requires_grad=True)

l11 = x@w11
l12 = x@w12
a1 = torch.tensor([l11, l12], requires_grad=True)
l21 = w21@a1

l21.backward()

print("x")
print(x.grad)
print("w11")
print(w11.grad)
print("w12")
print(w12.grad)
print("w21")
print(w21.grad)
print("a1")
print(a1.grad)
print("l21")
print(l21.grad)

Outputs:

x
None
w11
None
w12
None
w21
tensor([25., 22.])
a1
tensor([-0.5000,  2.0000])
l21
None