def save(self, epoch, path):
    ' Snapshot models '
    (the_dir, _) = os.path.split(path)
    os.makedirs(the_dir, exist_ok=True)
    states = {}

    def create_state(name, model, optimizer):
        states[name] = {'epoch': (epoch + 1), 'state_dict': model.state_dict(), 'optimizer': optimizer.state_dict()}
    all_tuple = [('encoder', self.encoder, self.encoder_optimizer), ('decoder', self.decoder, self.decoder_optimizer), ('critic', self.critic, self.critic_optimizer)]
    for param in all_tuple:
        create_state(*param)
    torch.save(states, path)
Snapshot models
def save(self, epoch, path):
    '  '
    (the_dir, _) = os.path.split(path)
    os.makedirs(the_dir, exist_ok=True)
    states = {}

    def create_state(name, model, optimizer):
        states[name] = {'epoch': (epoch + 1), 'state_dict': model.state_dict(), 'optimizer': optimizer.state_dict()}
    all_tuple = [('encoder', self.encoder, self.encoder_optimizer), ('decoder', self.decoder, self.decoder_optimizer), ('critic', self.critic, self.critic_optimizer)]
    for param in all_tuple:
        create_state(*param)
    torch.save(states, path)