    def inference(self):
        """Inference via batches"""
        for i, batch in tqdm(enumerate(self.test_dataloader)):
            if self.cfg.preprocess.use_frame_pitch:
                audio_pred = _vocoder_forward_funcs[self.cfg.model.generator](
                    self.cfg,
                    self.model,
                    batch["mel"].transpose(-1, -2),
                    f0s=batch["frame_pitch"].float(),
                    device=next(self.model.parameters()).device,
                )
            else:
                audio_pred = _vocoder_forward_funcs[self.cfg.model.generator](
                    self.cfg,
                    self.model,
                    batch["mel"].transpose(-1, -2),
                    device=next(self.model.parameters()).device,
                )
            audio_ls = audio_pred.chunk(self.test_batch_size)
            audio_gt_ls = batch["audio"].cpu().chunk(self.test_batch_size)
            length_ls = batch["target_len"].cpu().chunk(self.test_batch_size)
            j = 0
            for it, it_gt, l in zip(audio_ls, audio_gt_ls, length_ls):
                l = l.item()
                it = it.squeeze(0).squeeze(0)[: l * self.cfg.preprocess.hop_size]
                it_gt = it_gt.squeeze(0)[: l * self.cfg.preprocess.hop_size]
                uid = self.test_dataset.metadata[i * self.test_batch_size + j]["Uid"]
                save_audio(
                    os.path.join(self.args.output_dir, "pred", "{}.wav").format(uid),
                    it,
                    self.cfg.preprocess.sample_rate,
                )
                save_audio(
                    os.path.join(self.args.output_dir, "gt", "{}.wav").format(uid),
                    it_gt,
                    self.cfg.preprocess.sample_rate,
                )
                j += 1

        if os.path.exists(os.path.join(self.cfg.preprocess.processed_dir, "tmp")):
            shutil.rmtree(os.path.join(self.cfg.preprocess.processed_dir, "tmp"))
Inference via batches
models/vocoders/vocoder_inference.py