Thanks for all of your support!



 InnovArul:

It may be unrelated. I think you could remove requires_grad=True , as you need not have this unless you really need gradient with respect to data.


It is related. requires_grad is set to True because improved WGAN training needs (simply said) the derivative of the discriminator output with respect to the data in the loss function. For test purposes I removed this gradient term from the loss function and tried running my code with both requires_grad=True and requires_grad=False. Only the first one raised the error.
My model looks like this:
import torch.nn as nn
import torch


class MFCCCritic(nn.Module):
    """Generic Wasserstein GAN critic for generating artificial MFCC. Includes one skip
    connection for MFCC input.
    """

    def __init__(self, model_before, model_after):
        super(MFCCCritic,self).__init__()

        self.model_before = model_before
        self.model_after = model_after

    def forward(self, x):
        input = torch.cat([x['phoneme'], x['mfcc']], 1)
        h = torch.cat([self.model_before(input), x['mfcc']], 1)
        out = self.model_after(h)
        return out


model_before and model_after are only nn.Linear, nn.LayerNorm, and nn.LeakyReLU modules connected by nn.Sequential.