I reduced it as much as I could, but I’ll try to do more. I think visualization of graph and buffers for its vertices can help to understand what is going on. Can I visualize it using tensorboard? Any link will be very helpfull.

In your case I agree that this should not happend with a single call to  backward() .

Notice one more thing. Let’s conssider the folowwing changes:
        # gradient_penalty.backward()  # comment this line and error disappears
        loss_D_real.backward()
        loss_D_fake.backward()

The error dissapears, but we have run backward twice! Tensors loss_D_real and loss_D_fake are obtained by the same model netD. So, to understand the problem we need to verify what is going on during backward pass. I need more documentation.