Did you define a custom backward() function? (Note that defining your own backward function is not required in most cases because autograd takes care of it). If you didn’t then this is most likely a pytorch bug.