Download tests/test_v15.py from ViuAI/Murli-V1.5-Code: direct link, hf CLI and curl.
- Browser
- Download file 2.98 kB
-
https://huggingface.co/ViuAI/Murli-V1.5-Code/resolve/main/tests/test_v15.py
- Command line
-
hf download hf://ViuAI/Murli-V1.5-Code/tests/test_v15.py
-
curl -L -o test_v15.py https://huggingface.co/ViuAI/Murli-V1.5-Code/resolve/main/tests/test_v15.py
2.98 kB
| """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() | |