What is leaf node

def main():
    #order2 - MmBackward
    A = torch.tensor([1.,2,3,4,5,6],requires_grad=True).reshape(2,3)
    B = torch.tensor([1.,2,
                      3,4,
                      5,6],requires_grad=True).reshape(3,2)

    b = torch.tensor([1.,2,3,4],requires_grad=True).reshape(2,2)

    #A.retain_grad()
    #B.retain_grad()
    #b.retain_grad()

    z_ = A@B
    z = z_ +b
    z[0][0].backward()

    print('A.grad ',A.grad)#None
    print('B.grad ',B.grad)#None 
    print('z_.grad ',z_.grad)#none
    print('z.grad ',z.grad)#none

why A and B are both None?? Aren’t they the leaf node?? If not, What is a leaf node?
pytorch version = 1.2

2 Likes

Have a look at this post for more information.

PS: I enjoy the friendly discussion style in this forum and would like to keep it this way, thus editing your topic name.

1 Like