bghira commited on
Commit
b4824eb
·
verified ·
1 Parent(s): 7ad9ed5

Add RVQ encoder model card

Browse files
Files changed (1) hide show
  1. README.md +337 -0
README.md ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ datasets:
4
+ - bghira/minimax-music3-rvq-reverse-distillation
5
+ tags:
6
+ - audio
7
+ - music
8
+ - rvq
9
+ - reverse-distillation
10
+ - minimax-music-3
11
+ - mup
12
+ ---
13
+
14
+ # Open RVQ Encoder for MiniMax Music 3, 41M, v1 WIP
15
+
16
+ ## Status
17
+
18
+ - Work in progress.
19
+ - Checkpoints are uploaded during training.
20
+ - Not an official MiniMax model.
21
+ - Not the original MiniMax Music 3 RVQ encoder.
22
+ - No original encoder weights or source code were used.
23
+ - Real-audio generalization is not established.
24
+ - A packaged `from_pretrained` loader is not present yet.
25
+
26
+ ## Objective
27
+
28
+ Approximate the missing audio-to-RVQ path used by MiniMax Music 3.
29
+
30
+ Input path:
31
+
32
+ ```text
33
+ 44.1 kHz waveform
34
+ -> frozen DAV / Flow-VAE encoder
35
+ -> 128-channel DAV latents
36
+ -> this encoder
37
+ -> 8 RVQ distributions per 25 Hz frame
38
+ -> 1 semantic code + 7 acoustic codes
39
+ ```
40
+
41
+ Output vocabularies:
42
+
43
+ | Head | Role | Vocabulary |
44
+ |---:|---|---:|
45
+ | 0 | semantic | 16,384 |
46
+ | 1-7 | acoustic | 1,024 each |
47
+
48
+ The model predicts code distributions. Argmax produces a discrete code stream. The intended downstream test replays those codes through the MiniMax Music 3 LM, condition encoder, diffusion transformer, and DAV decoder.
49
+
50
+ ## Architecture
51
+
52
+ Exact trainable parameter count: **40,978,944**.
53
+
54
+ | Component | Configuration | Parameters |
55
+ |---|---|---:|
56
+ | DAV latent input stem | Conv1d, 128 -> 512, kernel 7 | 459,264 |
57
+ | Local residual stack | 3 blocks, dilations 1/3/9, GroupNorm, kernel-3 + kernel-1 convolutions | 3,151,872 |
58
+ | Position embedding | learned, 128 x 512 | 65,536 |
59
+ | Transformer | 8 pre-norm layers, width 512, 8 heads, FFN 2,048, GELU, dropout 0.1 | 25,219,072 |
60
+ | Final normalization | LayerNorm(512) | 1,024 |
61
+ | RVQ readouts | 8 independent `mup.MuReadout` heads | 12,082,176 |
62
+
63
+ Processing order:
64
+
65
+ 1. Apply the convolutional stem and residual stack at DAV latent rate.
66
+ 2. Average-pool exact DAV latent spans into 25 Hz semantic frames.
67
+ 3. Add learned positions.
68
+ 4. Apply eight bidirectional Transformer encoder layers.
69
+ 5. Apply final LayerNorm.
70
+ 6. Produce one logit tensor per RVQ codebook.
71
+
72
+ The pool matrix is supplied with each sample. It is not a fixed-ratio resampler. This preserves stitched-chunk alignment.
73
+
74
+ Context: 128 semantic frames = 5.12 seconds. There is no cross-window state.
75
+
76
+ ## Architecture Selection
77
+
78
+ - The target size was set near 41M parameters. `Serveurperso` independently demonstrated that an encoder at this scale could preserve track and lyric identity through code replay. This implementation does not copy that encoder's weights or architecture.
79
+ - DAV latents were selected instead of mel features. They are the continuous representation already used by the target pipeline. `marduk191`'s early mel proof of concept also showed the expected small-corpus generalization limit.
80
+ - Convolutions handle local latent structure before temporal pooling.
81
+ - The Transformer handles non-local interaction inside each 5.12-second crop.
82
+ - Independent heads match the asymmetric semantic and acoustic vocabularies.
83
+ - Width 512 and 8 heads give a fixed head dimension of 64.
84
+ - Widths 128, 256, and 512 therefore map directly to 2, 4, and 8 heads. This is the μP width family.
85
+ - Eight layers and FFN multiplier 4 place most capacity in temporal modeling while retaining a manageable DDP training cost.
86
+ - A 128-frame context is the baseline, not a claimed optimum. A 256-frame follow-up is appropriate if semantic accuracy trails acoustic accuracy.
87
+
88
+ ## Initialization and μP
89
+
90
+ Package: [`microsoft/mup`](https://github.com/microsoft/mup).
91
+
92
+ Shape family:
93
+
94
+ | Model | Width | Heads | Head dimension |
95
+ |---|---:|---:|---:|
96
+ | base | 128 | 2 | 64 |
97
+ | delta | 256 | 4 | 64 |
98
+ | target | 512 | 8 | 64 |
99
+
100
+ Initialization sequence:
101
+
102
+ 1. Construct target, base, and delta models.
103
+ 2. Call `mup.set_base_shapes(target, base, delta=delta)`.
104
+ 3. Delete base and delta models.
105
+ 4. Construct `mup.MuAdamW` after infshapes are attached.
106
+ 5. Save `mup_base_shapes.bsh` with each exported checkpoint.
107
+
108
+ Readouts:
109
+
110
+ - All eight output layers are `mup.MuReadout`.
111
+ - `output_mult = 1.0`.
112
+ - `readout_zero_init = true`.
113
+ - Readout weights and biases start at zero.
114
+ - Initial output distributions are uniform within each vocabulary.
115
+
116
+ Attention:
117
+
118
+ - Score scale: `attention_multiplier / head_dim`.
119
+ - `attention_multiplier = 8.0`.
120
+ - Target scale: `8 / 64 = 1/8`, equal to standard `1/sqrt(64)` scaling.
121
+ - Head dimension remains 64 across base, delta, and target widths.
122
+
123
+ Other parameters:
124
+
125
+ - Learned positions use `Normal(0, 0.02)`.
126
+ - Convolution, attention, FFN, and normalization modules use their PyTorch initializers before μP shape metadata is attached.
127
+ - Seed: 42, device-specific under DDP.
128
+
129
+ μP supplies width-aware parameterization and optimizer scaling. The base/delta/target family supports μTransfer. The current `3e-4` learning rate is not presented as the result of a completed base-width hyperparameter sweep.
130
+
131
+ ## Data
132
+
133
+ Dataset: [`bghira/minimax-music3-rvq-reverse-distillation`](https://huggingface.co/datasets/bghira/minimax-music3-rvq-reverse-distillation).
134
+
135
+ Run-launch snapshot:
136
+
137
+ - 2,972 one-track ZIP shards.
138
+ - 2,837 training records.
139
+ - 135 holdout records.
140
+ - Approximately 178 GB.
141
+ - Synthetic tracks generated by MiniMax Music 3.
142
+ - This is not MiniMax's original training set.
143
+
144
+ Fields consumed by this trainer:
145
+
146
+ - waveform audio;
147
+ - sampled RVQ codes;
148
+ - teacher top-50 token IDs;
149
+ - teacher top-50 logits;
150
+ - exact chunk-stitching metadata.
151
+
152
+ The corpus also contains stored flow-VAE latents. This trainer does not consume them. It re-encodes waveform audio with [`SimpleTuner/MiniMax-Music-3-Encoder`](https://huggingface.co/SimpleTuner/MiniMax-Music-3-Encoder) and caches DAV latents once.
153
+
154
+ Cached windows use `safetensors.safe_open(...).get_slice(...)`. Full-track latent tensors are not loaded for each crop.
155
+
156
+ ## Alignment
157
+
158
+ Nominal DAV ratio: `441 / 128 = 3.4453125` latents per semantic frame.
159
+
160
+ The actual stitched timeline is not a global multiplication by that ratio.
161
+
162
+ - Autoregressive rollout window: 200 semantic frames.
163
+ - Rollout hop: 100 semantic frames.
164
+ - Full stitched hop: 345 DAV latents.
165
+ - Later chunks begin ownership 25 semantic frames after their nominal start.
166
+ - Code row 0 is warm-up/priming.
167
+ - Semantic frame `i` is supervised by code row `i + 1`.
168
+ - The final partial chunk uses its own integer latent length.
169
+ - Per-shard `chunk_stitching` bounds define the pool spans.
170
+ - Training uses exact-alignment mode. Records without `chunk_stitching` metadata are excluded.
171
+
172
+ These rules prevent cumulative label drift and training across incorrectly assigned rollout seams.
173
+
174
+ ## Objective Function
175
+
176
+ ```text
177
+ loss = mean(CE_head_0 ... CE_head_7)
178
+ + 0.25 * mean(KL_head_0 ... KL_head_7)
179
+ ```
180
+
181
+ Hard targets:
182
+
183
+ - Cross-entropy against sampled RVQ codes.
184
+ - Equal weight for all eight heads.
185
+ - Padding target: `-100`.
186
+
187
+ Soft targets:
188
+
189
+ - Teacher top-k: 50.
190
+ - Temperature: 1.0.
191
+ - Hinton `T^2` scaling.
192
+ - Teacher distribution is renormalized over valid stored top-50 IDs.
193
+ - Student uses full-vocabulary log-softmax, then gathers the teacher IDs.
194
+ - Student probabilities are not renormalized over the top-50 subset.
195
+ - Negative, EOS, and out-of-vocabulary teacher IDs are excluded.
196
+ - Remaining teacher mass is renormalized after exclusion.
197
+ - Frames with no valid teacher IDs are skipped for KL.
198
+
199
+ The teacher logits come from LM predictions before audio-conditioned encoder output is available. Their uncertainty is useful but is not identical to an audio-conditioned posterior. This is why KL weight is 0.25 rather than 1.0.
200
+
201
+ Equal head averaging is simple but imperfect. The semantic head has a much larger vocabulary and can dominate early CE. Per-head weighting is a possible follow-up.
202
+
203
+ ## Training Run
204
+
205
+ | Setting | Value |
206
+ |---|---:|
207
+ | Hardware | 4 x NVIDIA L40S |
208
+ | Distribution | PyTorch DDP through Accelerate |
209
+ | Precision | bfloat16 mixed precision |
210
+ | Epochs | 20 |
211
+ | Batch per rank | 16 |
212
+ | Global batch | 64 |
213
+ | Gradient accumulation | 1 |
214
+ | Optimizer | `mup.MuAdamW` |
215
+ | Learning rate | 3e-4 |
216
+ | Weight decay | 0.01 |
217
+ | LR schedule | cosine |
218
+ | Warmup | 500 steps |
219
+ | Gradient norm limit | 1.0 |
220
+ | Train crop | random 128-frame window |
221
+ | Validation crop | deterministic 128-frame windows |
222
+ | Validation interval | 500 steps |
223
+ | Checkpoint interval | 500 steps |
224
+
225
+ Representative command:
226
+
227
+ ```bash
228
+ torchrun --standalone --nproc_per_node=4 scripts/train_minimax_music_rvq_encoder.py \
229
+ --dataset_repo_id bghira/minimax-music3-rvq-reverse-distillation \
230
+ --pretrained_vae_model_name_or_path SimpleTuner/MiniMax-Music-3-Encoder \
231
+ --latent_cache_dir cache/vae/minimaxmusic-rvq-encoder \
232
+ --output_dir output/minimaxmusic-rvq-encoder \
233
+ --require_exact_alignment \
234
+ --num_train_epochs 20 \
235
+ --train_batch_size 16 \
236
+ --mixed_precision bf16 \
237
+ --optimizer torch-adamw \
238
+ --learning_rate 3e-4 \
239
+ --weight_decay 0.01 \
240
+ --lr_scheduler cosine \
241
+ --lr_warmup_steps 500 \
242
+ --teacher_kl_weight 0.25 \
243
+ --teacher_kl_temperature 1.0 \
244
+ --window_frames 128 \
245
+ --window_stride 128 \
246
+ --d_model 512 \
247
+ --layers 8 \
248
+ --heads 8 \
249
+ --ff_mult 4 \
250
+ --dropout 0.1 \
251
+ --mup \
252
+ --mup_base_d_model 128 \
253
+ --mup_delta_d_model 256 \
254
+ --mup_readout_zero_init \
255
+ --checkpointing_steps 500 \
256
+ --validation_steps 500 \
257
+ --push_to_hub SimpleTuner/open-rvq-encoder-minimax-music-3-41m-v1-wip
258
+ ```
259
+
260
+ ## Checkpoint Format
261
+
262
+ Each exported checkpoint contains:
263
+
264
+ | File | Contents |
265
+ |---|---|
266
+ | `rvq_encoder.safetensors` | model state dictionary |
267
+ | `rvq_encoder_config.json` | architecture and μP configuration |
268
+ | `mup_base_shapes.bsh` | μP base-shape metadata |
269
+
270
+ Trainer state, optimizer state, local paths, and credentials are not uploaded to this model repository.
271
+
272
+ Loading currently requires the matching `RVQEncoderConfig` and `MiniMaxMusicRVQEncoder` definitions from `scripts/train_minimax_music_rvq_encoder.py`.
273
+
274
+ ## Evaluation
275
+
276
+ Current trainer metrics:
277
+
278
+ - total validation loss;
279
+ - hard CE;
280
+ - teacher top-50 KL;
281
+ - semantic top-1 token accuracy;
282
+ - aggregate acoustic top-1 token accuracy.
283
+
284
+ Four-rank real-data smoke testing covered forward, backward, validation, checkpoint save, and Hub export. Full-run results will be added after checkpoints are evaluated.
285
+
286
+ Required end-to-end acceptance test:
287
+
288
+ 1. Encode held-out waveform to DAV latents.
289
+ 2. Predict eight codes per frame.
290
+ 3. Replay predicted codes through the official LM path.
291
+ 4. Compare replayed condition embeddings with stored condition embeddings.
292
+ 5. Run the condition encoder, diffusion transformer, and DAV decoder.
293
+ 6. Compare reconstructed audio and lyric identity with the source generation.
294
+
295
+ This condition-embedding/replay evaluation is not implemented in the current trainer. Token top-1 is insufficient because multiple code sequences can be perceptually equivalent.
296
+
297
+ Prior independent evidence from `Serveurperso`:
298
+
299
+ - held-out STFT similarity: 0.83 to 0.87;
300
+ - exact-code replay STFT similarity: 0.998;
301
+ - acoustic exact-token match: 3% to 6%;
302
+ - same music and lyrics remained identifiable after predicted-code replay;
303
+ - a 550-track corpus overfit by epoch 17.
304
+
305
+ Those numbers are from a separate encoder and training stack. They are not results for this checkpoint.
306
+
307
+ ## Limitations
308
+
309
+ - WIP weights can regress between checkpoints.
310
+ - 5.12-second encoder context.
311
+ - No cross-window memory.
312
+ - Synthetic model-output training domain.
313
+ - Real audio is out of distribution until demonstrated otherwise.
314
+ - Teacher uncertainty is from the LM rollout, not an audio-conditioned teacher encoder.
315
+ - Exact token accuracy understates perceptual equivalence.
316
+ - Semantic CE may dominate acoustic CE early.
317
+ - End-to-end condition-embedding evaluation is pending.
318
+ - Loading is not packaged as a stable library API.
319
+ - Use is subject to the MiniMax Music 3 model terms and the reverse-distillation dataset terms.
320
+
321
+ ## Discussion and Experimental Inputs
322
+
323
+ Primary discussion: [MiniMaxAI/MiniMax-Music3 discussion #10, "Is the model trainable?"](https://huggingface.co/MiniMaxAI/MiniMax-Music3/discussions/10).
324
+
325
+ Attribution below is for public discussion, measurements, datasets, and independent experiments. It does not imply shared authorship of this implementation.
326
+
327
+ - [`bghira`](https://huggingface.co/bghira): ran the SimpleTuner training experiments; extracted sampled codes, teacher distributions, and alignment records; published the reverse-distillation corpus; organized this compatible-encoder run.
328
+ - [`marduk191`](https://huggingface.co/marduk191): published WAV/code samples; built an early mel-based encoder proof of concept; reported small-corpus and real-audio limits; tested additional encoder variants.
329
+ - [`scragnog`](https://huggingface.co/scragnog): calibrated HOT-Step CPP training against SimpleTuner; reported relative-weight-movement and loss measurements; identified structured-caption cache behavior and conditioning-rollout seam effects; confirmed SimpleTuner LoRA export interoperability with GGML.
330
+ - [`Serveurperso`](https://huggingface.co/Serveurperso): independently built a 41M encoder, corpus generator, loader, and replay evaluation stack; demonstrated viable predicted-code replay; identified the stitched-hop, warm-up-row, and final-partial-chunk alignment rules.
331
+ - [`dernet`](https://huggingface.co/dernet): explained why inference-time internal alignment does not provide target-derived alignment during training; clarified the role of RVQ token supervision; contributed tokenizer reverse-engineering analysis.
332
+
333
+ Additional public artifacts:
334
+
335
+ - [`marduk191/Minmax_music3_experiments` corpus](https://huggingface.co/marduk191/Minmax_music3_experiments/tree/main/corpus)
336
+ - [`ServeurpersoCom/minimaxmusic.cpp` encoder proof commit](https://github.com/ServeurpersoCom/minimaxmusic.cpp/commit/d19efe9f94e41ac4c900aa30d56fe90c8dac7ef1)
337
+