File size: 2,976 Bytes
44e7b48 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | """Unit, training step, and Android ONNX export tests for Murli V1.5."""
import os
import sys
import tempfile
import unittest
import torch
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from config import MurliV15Config
from data.text_cleaner import BilingualTextTokenizer
from export_onnx import export_acoustic_onnx
from models.tts_engine import MurliV15Engine
class TestMurliV15(unittest.TestCase):
def test_param_count_and_hindi_g2p_v1_fixes(self):
cfg = MurliV15Config()
engine = MurliV15Engine(cfg)
n_params = sum(p.numel() for p in engine.parameters())
print(f"\n[Murli V1.5] Total acoustic params: {n_params / 1e6:.2f}M")
self.assertGreater(n_params, 15_000_000)
self.assertLess(n_params, 26_000_000)
tok = BilingualTextTokenizer(use_g2p_en=False)
# Exact V1 failure words from LESSONS_LEARNED_V1.md
for word in ["बढ़ई", "लकड़ी", "राघव", "मुरली", "रखे", "अपनी", "मेहनत", "सम्मान"]:
ids = tok.text_to_ids(word, language="hi")
self.assertGreater(ids.numel(), 2, f"Empty encoding for {word}")
def test_train_step_and_synthesize(self):
cfg = MurliV15Config()
engine = MurliV15Engine(cfg)
bsz, t_text, t_mel = 2, 16, 80
token_ids = torch.randint(1, 50, (bsz, t_text))
text_mask = torch.ones((bsz, t_text), dtype=torch.bool)
mel_target = torch.randn((bsz, cfg.model.mel_dim, t_mel))
mel_mask = torch.ones((bsz, t_mel), dtype=torch.bool)
f0_target = torch.randn((bsz, t_mel))
energy_target = torch.randn((bsz, t_mel))
emotion_ids = torch.tensor([0, 1], dtype=torch.long)
out = engine(
token_ids=token_ids,
text_mask=text_mask,
mel_target=mel_target,
mel_mask=mel_mask,
f0_target=f0_target,
energy_target=energy_target,
emotion_ids=emotion_ids,
)
self.assertTrue(torch.isfinite(out["loss"]))
out["loss"].backward()
mel_gen = engine.synthesize(token_ids[:1], emotion_id=1, steps=4)
self.assertEqual(mel_gen.shape[0], 1)
self.assertEqual(mel_gen.shape[1], cfg.model.mel_dim)
self.assertGreater(mel_gen.shape[2], 0)
def test_android_onnx_export_and_parity(self):
cfg = MurliV15Config()
engine = MurliV15Engine(cfg)
with tempfile.TemporaryDirectory() as tmpdir:
fe_path, cfm_path = export_acoustic_onnx(engine, tmpdir, opset=17)
self.assertTrue(os.path.exists(fe_path))
self.assertTrue(os.path.exists(cfm_path))
print(
f"[ONNX Sizes] frontend={os.path.getsize(fe_path) / (1024 * 1024):.2f} MiB, "
f"cfm_step={os.path.getsize(cfm_path) / (1024 * 1024):.2f} MiB"
)
if __name__ == "__main__":
unittest.main()
|