游雁
2024-06-07 0ba1bdd476c2079f1220904d5f2a217d78bdb64a
auto frontend
1个文件已修改
26 ■■■■■ 已修改文件
funasr/datasets/openai_datasets/datasets.py 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/datasets/openai_datasets/datasets.py
@@ -180,6 +180,10 @@
        return output
    def collator(self, samples: list = None):
        for idx in range(self.retry):
            badcase_flag = False
        outputs = {}
        for sample in samples:
            if sample is None:
@@ -202,29 +206,17 @@
                )
        if self.batch_type != "example":
            for i in range(10):
                outputs = self._filter_badcase(outputs, i=i)
        return outputs
    def _filter_badcase(self, outputs, i=0):
        b, t = outputs["input_ids"].shape
        if b * t > self.batch_size * 2:
            beg = torch.randint(0, 2, ()).item()
            if b < 2:
                beg = 0
            logging.info(
                f"Warning, b * t: {b * t} > {self.batch_size}, b: {b}, t: {t}, drop half data {i}th, beg:{beg}"
                        f"Warning, b * t: {b * t} > {self.batch_size}, b: {b}, t: {t}, drop half data {idx}th, beg:{beg}"
            )
            for key, data_list in outputs.items():
                outputs[key] = outputs[key][beg : beg + b : 2]
            #
            # speech_lengths_max = outputs["speech_lengths"].max().item()
            # outputs["speech"] = outputs["speech"][:, :speech_lengths_max, :]
            # text_lengths_max = outputs["text_lengths"].max().item()
            # outputs["text"] = outputs["text"][:, :text_lengths_max]
            # target_mask_lengths_max = outputs["target_mask_lengths"].max().item()
            # outputs["target_mask"] = outputs["target_mask"][:, :target_mask_lengths_max]
                    samples = samples[beg : beg + b : 2]
                    continue
            break
        return outputs