SOTA Open Source TTS
Add dropout options to optimize overfitting
Lengyue39f6902119a8
diff --git a/fish_speech/configs/text2semantic_finetune.yaml b/fish_speech/configs/text2semantic_finetune.yamlindex 1cc3848..9d0be78 100644--- a/fish_speech/configs/text2semantic_finetune.yaml+++ b/fish_speech/configs/text2semantic_finetune.yaml@@ -59,6 +59,7 @@ model:norm_eps: 1e-5num_codebooks: 4 # single codebookcodebook_size: 168 # codebook size 160 + 2 special tokens+ dropout: 0.1 # For small dataset, dropout helps to prevent overfittingoptimizer:_target_: torch.optim.AdamWdiff --git a/fish_speech/configs/text2semantic_finetune_lora.yaml b/fish_speech/configs/text2semantic_finetune_lora.yamlindex b4e7b6e..000441e 100644--- a/fish_speech/configs/text2semantic_finetune_lora.yaml+++ b/fish_speech/configs/text2semantic_finetune_lora.yaml@@ -59,6 +59,7 @@ model:norm_eps: 1e-5num_codebooks: 4 # single codebookcodebook_size: 168 # codebook size 160 + 2 special tokens+ dropout: 0.1 # For small dataset, dropout helps to prevent overfittinglora_config:_target_: fish_speech.models.text2semantic.lit_module.LoraConfigdiff --git a/fish_speech/models/text2semantic/llama.py b/fish_speech/models/text2semantic/llama.pyindex 0b27e6f..08b0f9c 100644--- a/fish_speech/models/text2semantic/llama.py+++ b/fish_speech/models/text2semantic/llama.py@@ -31,6 +31,7 @@ class ModelArgs:rope_base: float = 10000norm_eps: float = 1e-5max_seq_len: int = 2048+ dropout: float = 0.0# Additional decoding headscodebook_size: int = 160@@ -260,6 +261,7 @@ class Attention(nn.Module):self.wo = nn.Linear(config.dim, config.dim, bias=False)self.kv_cache = None+ self.dropout = config.dropoutself.n_head = config.n_headself.head_dim = config.head_dimself.n_local_heads = config.n_local_heads@@ -301,7 +303,13 @@ class Attention(nn.Module):k = k.repeat_interleave(self.n_head // self.n_local_heads, dim=1)v = v.repeat_interleave(self.n_head // self.n_local_heads, dim=1)- y = F.scaled_dot_product_attention(q, k, v, attn_mask=mask, dropout_p=0.0)+ y = F.scaled_dot_product_attention(+ q,+ k,+ v,+ attn_mask=mask,+ dropout_p=self.dropout if self.training else 0.0,+ )y = y.transpose(1, 2).contiguous().view(bsz, seqlen, self.dim)else:@@ -311,7 +319,7 @@ class Attention(nn.Module):# We don't need to transpose q, k, v here because flash_attn_varlen_funcattn_output = self._flash_attention_forward(- q, k, v, mask, seqlen, dropout=0.0+ q, k, v, mask, seqlen, dropout=self.dropout if self.training else 0.0)y = attn_output.reshape(bsz, seqlen, self.dim).contiguous()