notmax123 commited on
Commit
0ce63bb
Β·
verified Β·
1 Parent(s): 86cb1c6

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +156 -3
README.md CHANGED
@@ -1,3 +1,156 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - text-to-speech
5
+ - speech-synthesis
6
+ - autoencoder
7
+ - flow-matching
8
+ - audio
9
+ ---
10
+
11
+ # BlueCodec β€” Speech Autoencoder
12
+
13
+ This repository contains the pretrained **Speech Autoencoder (AE)** from the Light-BlueTTS system β€” Stage 1 of a three-stage TTS pipeline.
14
+
15
+ The AE encodes 44.1 kHz audio into a 24-dim continuous latent space at ~86 Hz, and decodes back to waveform via a causal dilated decoder.
16
+
17
+ **Total inference model size:** ~71M parameters (AE decoder ~25M, TTL ~45M, DP ~0.5M)
18
+
19
+ ---
20
+
21
+ ## Checkpoint
22
+
23
+ | File | Contents |
24
+ |---|---|
25
+ | `ae_latest.safetensors` | Encoder + Decoder weights (202 tensors, ~204 MB) |
26
+
27
+ Keys are prefixed with `encoder.*` and `decoder.*`.
28
+
29
+ ---
30
+
31
+ ## Architecture
32
+
33
+ Encodes via a concatenated log-linear (1025-ch) + log-mel (228-ch) spectrogram (FFT 2048, hop 512) into a 24-dim latent at ~86 Hz.
34
+
35
+ | Component | Details |
36
+ |---|---|
37
+ | Input | 1253-channel spectrogram (1025 log-linear + 228 log-mel) |
38
+ | Encoder (~25.6M) | Conv1d stem (1253β†’512) + 10 ConvNeXt blocks (intermediate 2048) + proj (512β†’24) |
39
+ | Decoder (~25.3M) | CausalConv1d stem (24β†’512) + 10 causal dilated ConvNeXt blocks + VocoderHead |
40
+ | Decoder dilations | `[1, 2, 4, 1, 2, 4, 1, 1, 1, 1]` |
41
+ | Discriminators (train only) | MPD (periods 2,3,5,7,11) + MRD (FFTs 512/1024/2048) |
42
+
43
+ **Generator loss (training):**
44
+ ```
45
+ L_G = 45 * L_recon + 1 * L_adv + 0.1 * L_fm
46
+ ```
47
+ Reconstruction uses multi-resolution mel L1 on 3 scales: (FFT 1024, 64 mels), (FFT 2048, 128 mels), (FFT 4096, 128 mels).
48
+
49
+ ---
50
+
51
+ ## Full Pipeline β€” Light-BlueTTS
52
+
53
+ Training is split into three independent stages run in order:
54
+
55
+ 1. **Speech Autoencoder** ← *this repo* β€” encodes audio into a 24-dim continuous latent space
56
+ 2. **Text-to-Latent (TTL)** β€” flow-matching model that maps text + reference speech to latents
57
+ 3. **Duration Predictor (DP)** β€” utterance-level duration estimator
58
+
59
+ ### Text-to-Latent Module
60
+
61
+ Operates on *compressed* latents: the 24-dim latent is reshaped to 144-dim at ~14 Hz (compression factor K_c = 6).
62
+
63
+ | Component | Details |
64
+ |---|---|
65
+ | Reference Encoder (~4.8M) | Conv1d (144β†’256) + 6 ConvNeXt blocks (k=5) + 2 cross-attn layers β†’ 50 style tokens |
66
+ | Text Encoder (~6.9M) | Char embedding (256-dim) + 6 ConvNeXt blocks + 4 self-attn blocks (RoPE) + 2 style cross-attn layers |
67
+ | Vector Field Estimator (~33M) | proj_in (144β†’512) + 4Γ— superblock + 4 final ConvNeXt blocks + proj_out (512β†’144) |
68
+ | VF superblock | 4Γ— dilated ConvNeXt (d=1,2,4,8) + time injection + 2Γ— ConvNeXt + text cross-attn + style cross-attn |
69
+
70
+ **Flow-matching objective (L1, masked):**
71
+ ```
72
+ L_TTL = E [ || m Β· (v(z_t, z_ref, c, t) - (z₁ - (1 - Οƒ_min)Β·zβ‚€)) ||₁ ]
73
+ ```
74
+ Οƒ_min = 1e-8, p_uncond = 0.05. Inference: Euler method, NFE=32, CFG=3.
75
+
76
+ ### Duration Predictor (~0.5M)
77
+
78
+ Utterance-level (not phoneme-level).
79
+
80
+ | Component | Details |
81
+ |---|---|
82
+ | DP Reference Encoder | Linear (144β†’64) + 4 ConvNeXt blocks + 2 cross-attn β†’ 64-dim embedding |
83
+ | DP Text Encoder | Char embedding (64-dim) + 6 ConvNeXt blocks + 2 self-attn + utterance token β†’ 64-dim |
84
+ | Estimator | Linear(192β†’128) + PReLU + Linear(128β†’1) β†’ scalar log-duration |
85
+
86
+ ---
87
+
88
+ ## Training the Autoencoder
89
+
90
+ Multi-GPU training via PyTorch DDP on 4Γ— GPUs.
91
+
92
+ ```bash
93
+ torchrun --nproc_per_node=4 src/train_autoencoder.py \
94
+ --arch_config configs/tts.json
95
+ ```
96
+
97
+ **Key hyperparameters:**
98
+
99
+ | Parameter | Value |
100
+ |---|---|
101
+ | Optimizer | AdamW (β₁=0.8, Ξ²β‚‚=0.99, wd=0.01) |
102
+ | Learning rate | 2e-4 with cosine annealing to 1e-6 |
103
+ | Batch size | 128 |
104
+ | Crop length | 0.19 s (~8,379 samples at 44.1 kHz) |
105
+ | Total iterations | 1,500,000 |
106
+ | Hardware (paper) | 2Γ— RTX 3090 |
107
+
108
+ Resume from checkpoint:
109
+ ```bash
110
+ torchrun --nproc_per_node=4 src/train_autoencoder.py \
111
+ --resume checkpoints/ae/ae_latest.pt
112
+ ```
113
+
114
+ Training dataset: ~5.9M files / ~10,000 hours of audio.
115
+
116
+ ---
117
+
118
+ ## Reducing Model Size
119
+
120
+ All dimensions are controlled by `configs/tts.json`. Key levers for the AE:
121
+
122
+ | Change | Param reduction |
123
+ |---|---|
124
+ | `encoder.idim`: 1253 β†’ 228 (mel-only input) | βˆ’3.7M |
125
+ | `encoder.hdim`: 512 β†’ 256 | βˆ’10M |
126
+ | `encoder.intermediate_dim`: 2048 β†’ 1024 | βˆ’10.5M |
127
+ | Reduce `encoder.num_layers` / `decoder.num_layers` 10 β†’ 6 | βˆ’8.4M each |
128
+
129
+ > Reducing `idim` to 228 also requires updating `LinearMelSpectrogram` to output mel-only (set `n_mels=228` and remove log-linear concatenation in `models/utils.py`).
130
+
131
+ ---
132
+
133
+ ## Repository Structure
134
+
135
+ ```
136
+ training/
137
+ β”œβ”€β”€ src/
138
+ β”‚ β”œβ”€β”€ train_autoencoder.py # Stage 1: AE training (multi-GPU DDP)
139
+ β”‚ β”œβ”€β”€ train_text_to_latent.py # Stage 2: TTL flow-matching training
140
+ β”‚ └── train_duration_predictor.py # Stage 3: Duration predictor training
141
+ β”œβ”€β”€ models/
142
+ β”‚ β”œβ”€β”€ autoencoder/
143
+ β”‚ β”‚ β”œβ”€β”€ latent_encoder.py # LatentEncoder (mel β†’ 24-dim latent)
144
+ β”‚ β”‚ β”œβ”€β”€ latent_decoder.py # LatentDecoder1D (latent β†’ waveform)
145
+ οΏ½οΏ½οΏ½ β”‚ β”œβ”€β”€ discriminators.py # MPD + MRD for GAN training
146
+ β”‚ β”‚ └── modules.py # Shared: ConvNeXtBlock, CausalConvNeXtBlock, etc.
147
+ β”‚ └── text2latent/
148
+ β”‚ β”œβ”€β”€ text_encoder.py # TextEncoder with ConvNeXt + self-attn + style cross-attn
149
+ β”‚ β”œβ”€β”€ reference_encoder.py # ReferenceEncoder (audio β†’ style tokens)
150
+ β”‚ β”œβ”€β”€ vf_estimator.py # VectorFieldEstimator (flow-matching backbone)
151
+ β”‚ β”œβ”€β”€ duration_predictor.py # TTSDurationModel (full DP model)
152
+ β”‚ └── dp_network.py # DPNetwork (backward-compatible wrapper)
153
+ β”œβ”€β”€ compute_latent_stats.py # Compute latent mean/std (run before Stage 2/3)
154
+ └── configs/
155
+ └── tts.json # Single config file for all stages
156
+ ```