So the error message describes very literally the situation it found: There is a leaf (i.e. no grad_fn) for a tensor but it doesn’t have an accumulator (to add things it gets to .grad). Unfortunately, you cannot get a representation of the accumulator in Python directly (interestingly, you can get it in the graph through grad_fn.next_functions, but I don’t know that you could directly).
This is strange because the things that make leaf tensors (requires_grad_, factory functions with requires_grad=True) should all reliably set up the accumulator as needed, so it looks like something is not setting up the grad_fn properly.
This essentially means that something in the autograd-set-up has been messed up when the tensor in question was created. I must admit it fascinates me, because while I did have it happen to me when I manually did stuff with the autograd graph in C++, I have not seen this happen from Python, but my guess is that the most likely way to trigger this is doing very funny stuff inside an autograd.Function.
If you have something that reproduces it with code that you’re willing to share, I would be most grateful.
Best regards
Thomas