File size: 3,036 Bytes
5be0f71
 
 
 
 
b62c0da
5be0f71
 
 
 
 
 
 
 
 
 
 
 
 
b62c0da
 
 
 
 
 
5be0f71
 
 
 
b62c0da
 
5be0f71
b62c0da
 
5be0f71
 
 
 
 
b62c0da
 
5be0f71
 
b62c0da
 
5be0f71
 
 
 
 
b62c0da
47fbe3b
5be0f71
09f2b32
5be0f71
47fbe3b
 
bb1e6d3
 
5be0f71
 
 
 
 
 
 
 
273da4b
5be0f71
 
b62c0da
5be0f71
 
 
b62c0da
 
 
 
5be0f71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Config for 10M Modern TTS Model (Optimal Transport Flow Matching + Vocos)
Strictly tuned to ~10 Million Parameters.
"""

import math
from dataclasses import dataclass, field
from typing import Optional


@dataclass
class AudioConfig:
    sample_rate: int = 24000
    n_fft: int = 1024
    hop_length: int = 256
    win_length: int = 1024
    n_mels: int = 100
    f_min: float = 0.0
    f_max: float = 12000.0
    # Locked Vocos 24kHz normalization parameters (matches vocos.feature_extractors.MelSpectrogramFeatures)
    # Vocos uses torchaudio defaults: norm=None, mel_scale="htk", safe_log clip_val=1e-7
    mel_norm: Optional[str] = None
    mel_scale: str = "htk"
    mel_min_clip: float = 1e-7
    mel_pad_value: float = field(default_factory=lambda: math.log(1e-7))


@dataclass
class ModelConfig:
    # Hybrid Unicode Char (ASCII + Devanagari) + UTF-8 Byte Fallback Tokenizer
    vocab_size: int = 512
    pad_token_id: int = 0

    # Text Encoder (Transformer + RoPE) ~ 2.76M parameters
    text_dim: int = 256
    text_layers: int = 4
    text_heads: int = 4
    text_ffn_dim: int = 768
    dropout: float = 0.1

    # Duration Predictor ~ 0.40M parameters
    duration_hidden_dim: int = 256
    duration_kernel_size: int = 3

    # OT-CFM Flow Matching Vector Field Backbone ~ 4.98M parameters
    mel_dim: int = 100
    cfm_hidden_dim: int = 256
    cfm_num_blocks: int = 8
    cfm_kernel_size: int = 7
    time_embed_dim: int = 128

    # ODE Sampling & Classifier-Free Guidance (CFG) Settings
    sigma_min: float = 1e-4
    default_ode_steps: int = 48  # 48 midpoint steps for crisp studio audio
    ode_method: str = "midpoint"  # "euler" or "midpoint"
    p_uncond: float = 0.15  # 15% condition dropout during training for CFG
    default_cfg_scale: float = 1.5  # 1.0 = no CFG, 1.2-1.5 = crisp & natural
    default_temperature: float = 0.667  # Matcha-TTS standard: <1.0 removes background hiss/noise
    sway_sampling_coef: float = -1.0  # F5-TTS Sway Sampling (-1.0 = cleaner prosody, 0.0 = uniform)


@dataclass
class TrainingConfig:
    learning_rate: float = 2e-4
    weight_decay: float = 1e-2
    warmup_steps: int = 1000
    batch_size: int = 16
    num_workers: int = 4
    max_epochs: int = 200
    grad_clip_norm: float = 1.0  # Anti-Beep / Anti-Explosion guard

    # Loss weights
    cfm_loss_weight: float = 1.0
    dur_loss_weight: float = 0.5
    prior_loss_weight: float = 0.25

    # Validation, Logging & Checkpointing
    val_split: float = 0.05
    log_interval: int = 25
    eval_interval: int = 500
    save_interval: int = 2000
    output_dir: str = "checkpoints"


@dataclass
class HFConfig:
    hf_repo_id: str = "ViuAI/TTS-10M-Modern"
    hf_dataset_id: str = "ViuAI/ViuAI_TTS_Dataset"
    private: bool = False


@dataclass
class TTS10MConfig:
    audio: AudioConfig = field(default_factory=AudioConfig)
    model: ModelConfig = field(default_factory=ModelConfig)
    training: TrainingConfig = field(default_factory=TrainingConfig)
    hf: HFConfig = field(default_factory=HFConfig)