MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / run_batch

Function run_batch

scripts/batch_eval_llama_cpp.py:109–173  ·  view source on GitHub ↗
(
    pipeline: LlamaCppPipeline,
    cases: list[tuple[str, str, Path, str]],
    result_dir: Path,
    max_cases: int = 0,
    skip_existing: bool = True,
)

Source from the content-addressed store, hash-verified

107
108
109def run_batch(
110 pipeline: LlamaCppPipeline,
111 cases: list[tuple[str, str, Path, str]],
112 result_dir: Path,
113 max_cases: int = 0,
114 skip_existing: bool = True,
115) -> list[CaseResult]:
116 results: list[CaseResult] = []
117 total = len(cases) if max_cases <= 0 else min(max_cases, len(cases))
118 cases = cases[:total]
119
120 log.info("Running %d evaluation cases, output -> %s", total, result_dir)
121
122 pbar = tqdm(cases, desc="Evaluation", unit="case", total=total, dynamic_ncols=True)
123 for i, (task, case_id, prompt_wav, text) in enumerate(pbar):
124 pbar.set_postfix_str(f"{task}/{case_id}")
125 out_dir = result_dir / task / case_id
126 out_wav = out_dir / "pred.wav"
127
128 if skip_existing and out_wav.exists():
129 log.info("[%d/%d] %s/%s — skipped (exists)", i + 1, total, task, case_id)
130 results.append(CaseResult(task=task, case_id=case_id, success=True))
131 continue
132
133 log.info("[%d/%d] %s/%s — %s", i + 1, total, task, case_id, text[:60])
134 t0 = time.time()
135
136 try:
137 lang = TASK_LANGUAGE.get(task)
138 ref_audio = str(prompt_wav) if prompt_wav.exists() else None
139
140 waveform = pipeline.generate(
141 text=text, reference_audio=ref_audio, language=lang,
142 )
143 elapsed = time.time() - t0
144
145 if waveform.size == 0:
146 results.append(CaseResult(
147 task=task, case_id=case_id, success=False,
148 generation_time=elapsed, error="empty waveform",
149 ))
150 continue
151
152 out_dir.mkdir(parents=True, exist_ok=True)
153 sf.write(str(out_wav), waveform, SAMPLE_RATE)
154 audio_dur = len(waveform) / SAMPLE_RATE
155
156 results.append(CaseResult(
157 task=task, case_id=case_id, success=True,
158 audio_duration=audio_dur, generation_time=elapsed,
159 ))
160 log.info(
161 " -> %.2fs audio in %.2fs (RTF=%.2f)",
162 audio_dur, elapsed, elapsed / max(audio_dur, 1e-6),
163 )
164
165 except Exception as e:
166 elapsed = time.time() - t0

Callers 1

mainFunction · 0.85

Calls 3

CaseResultClass · 0.85
getMethod · 0.45
generateMethod · 0.45

Tested by

no test coverage detected