class Seq2Seq(nn.Module):
    def __init__(self,encoder, decoder, personas, hid_dim ,  device):
        super().__init__()
        self.encoder = encoder 
        self.decoder = decoder 
        self.device = device 
        self.fc = nn.Linear(hid_dim, personas+1)
    def forward(self, src,src_speaker,trg, trg_speaker, teacher_forcing_ratio  = 0.5):
        """
        ------------------------------------------------------
        End-to-end network for Seq2seq persona embedding creation 
        Variable    ----    Size    
        trg                 [batch size, sequence length]   
        src                 [batch size, sequence length]
        outputs             [sequence length, batch size, trg vocab size]
        hidden              [1, batch size, hid dim]
        input               [batch size]
        ------------------------------------------------------
        """
        batch_size = trg.shape[0]
        trg = trg.permute(1,0)
        max_len = trg.shape[0] 
        trg_vocab_size = self.decoder.output_dim 
        
        outputs = torch.zeros(max_len, batch_size, trg_vocab_size).to(self.device)
        
        context = self.encoder(src, src_speaker)
        
        # hidden = context
        # input = torch.LongTensor(np.ones(batch_size))
        
        # for t in range(1,max_len):
        #     input = Variable(input).cuda()
        #     hidden = Variable(hidden).cuda()
        #     context = Variable(context).cuda()
        #     output, hidden = self.decoder(input, hidden, context)
        #     outputs[t] = output
            
        #     teacher_force = random.random() < teacher_forcing_ratio
            
        #     top1 = output.argmax(1) 
            
        #     input = trg[t] if teacher_force else top1
        
        persona_out = self.fc(context).squeeze(0)
        
        return persona_out

I changed the seq2seq class so that it calls encoder but doesn’t call decoder, then the grad is present.
So i think the problem might be in decoder, or the way i am calling the decoder in seq2seq class.