you can call .detach() on some variables to ensure G.grad is not touched when E_loss.backward() is called.
See the GAN example for instance:

  
      github.com
  
  
    pytorch/examples/blob/master/dcgan/main.py#L231-L240 14

noise.resize_(batch_size, nz, 1, 1).normal_(0, 1)
noisev = Variable(noise)
fake = netG(noisev)
labelv = Variable(label.fill_(fake_label))
output = netD(fake.detach())
errD_fake = criterion(output, labelv)
errD_fake.backward()
D_G_z1 = output.data.mean()
errD = errD_real + errD_fake
optimizerD.step()