I don’t know much about the paper you mentioned, but the error is caused because you tried to backpropagate the created graph (generated_images = net(noise))  more than once through the inner for loop. General usage is, put your forward (generated_images = net(noise)) inside the inner for loop, such as,
for epoch in range(epochs):
    for input_images, _ in iter(train_loader):
        noise = torch.randn((noise_batch_size, latent_size))
        generated_images = net(noise)
        input_images = input_images.to(device)
        optimizer.zero_grad()
        loss = mmd(input_images.squeeze(), generated_images.squeeze())
        loss.backward()
        optimizer.step()