Jointly training two deep neural networks

Hello, I have two deep neural networks, one for speech enhancement to remove noise from the speech signals and the other network is for intent classification. I am trying to train them jointly i.e. the output of the first network is passed directly to the second network as follows:

def _train_epoch(self, epoch=100):

    for i, (mixture, clean, name) in enumerate(self.train_data_loader):
        mixture =, dtype=torch.float)
        clean =, dtype=torch.float)
        enhanced = self.model(mixture).to(self.device)
        loss = self.loss_function(clean, enhanced)
        for i, d in enumerate(train_set_generator):
            enhanced, l = d
            y = model_back(enhanced.float().to(device2))
            loss_back = loss_func_back(y[0], l[0].to(device2))
            print("Iteration %d in epoch%d--> loss = %f" % (i, epoch, loss_back.item()), end='\r')
            if i % 100 == 0:
              correct = []
              for j, ev in enumerate(valid_set_generator):
                enhanced, label = ev
                y_eval = model_back(enhanced.float().to(device2))
                pred = torch.argmax(y_eval[0].detach().cpu(), dim=1)
                intent_pred = pred
                correct.append((intent_pred == label[0]).float())
                if j > 100:
              acc = np.mean(np.hstack(correct))
              intent_acc = acc
              iter_acc = '\n iteration %d epoch %d -->' %(i, epoch)
              print(iter_acc, acc, best_accuracy)
              if intent_acc > best_accuracy:
                improved_accuracy = 'Current accuracy {}, {}'.format(intent_acc, best_accuracy)
      , 'bestmodel.pkl')

Where the loss of the first DNN is the MSE loss and the loss of the second DNN is the Cross entropy loss. The problem is that after many iterations in the first epoch the second DNN starts to iterate on the first loop again not goes to the second loop. Any help will be appreciated.