Solved by tom in post #2 
              
              
                The problem is that you only compute self.b once - in the __init__. Then on the first backward, it’ll work. But the next time around, the edge in the computation graph connecting self.b to self.a will be gone.
The most obvious way to get this to work is to move the line self.b = torch.log(self.a) …