Solved by ptrblck in post #2 
              
              
                In your code snippet you are overwriting the leaf tensor A with a new tensor also called A and thus you should also get a warning when you try to access its .grad attribute: 
UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be popula…