YuE #06: Audio Codec and Two-Stage Generation Pipeline
YuE turns a waveform into discrete codes, plans the song at a coarse level, then fills in the detail on a second pass. Here is what each stage does.
Most people meet YuE through its command line and never look at what happens between the lyrics file and the output segments. It is worth understanding, because every failure you will blame on the model has a specific place in this chain where it was decided: either the codes were wrong, or the second pass did not repair them. Here is the whole route, in order.
From Waveform To Discrete Codes
Audio cannot go straight into a language model, so YuE starts with a tokenizer that converts waveforms into discrete codes using a semantic-acoustic approach. The bottom codebook carries the meaning-level structure: what is being sung, where the syllables land, the rough shape of the accompaniment. The upper codebooks carry texture and detail. This split is the whole design, because it lets the model plan the hard part on a small alphabet and leave the expensive part to a later pass.
Stage One Writes The Skeleton
Stage one is a 7B-scale autoregressive model built on the LLaMA2 architecture. It reads your text tokens and predicts the bottom-level audio codes for the vocal track and the accompaniment track as separate streams, then keeps them aligned. This is the stage that decides whether the words are sung in the right order and whether the song still has structure three minutes in. It also explains why track separation matters: one dense stream mixing voice and instruments is far harder to predict, and earlier systems blurred as a result.
Stage Two Fills In The Residual Detail
Stage two is a 1B model that takes the codes stage one produced and predicts the remaining residual codes needed to reconstruct audio. It never sees your lyrics directly, which is a feature: its job is fidelity, not decisions. A lightweight vocoder then upsamples the result from 16kHz to 44.1kHz for delivery. If a section sounds thin or plasticky while the words and structure are fine, the problem lives here rather than in the prompt you wrote.
Why Two Passes Beat One Pass
Predicting everything in a single pass means a model must hold melodic shape, pronunciation, harmony and texture in one forward move over a very long sequence. Splitting the job gives each pass a narrow question. The first pass answers what happens and when, the second answers what it sounds like up close. Long generations stay coherent for the same reason a rough edit followed by a detail pass beats editing blind: decisions are made once and refined, not renegotiated halfway through.
Driving The Pipeline From The Command Line
The inference script exposes the pieces you actually tune. --stage1_model and --stage2_model choose the checkpoints, --genre_txt and --lyrics_txt point at your two input files, and --run_n_segments should equal the number of lyric sections you wrote, so the first pass knows where to stop. --max_new_tokens sets the budget per section, with 3000 as the shipped default, and --stage2_batch_size trades memory against speed during the second pass. --repetition_penalty is the first knob to move when a vocal loops a phrase it should have left behind.
Where The Token Chain Goes Wrong
Three failures repeat. Sections merge when your blank lines are inconsistent, so the pass reads two blocks as one and runs out of budget. A language mismatch between the style tags and the lyrics produces accented, unstable singing, which is why the tag list carries explicit language entries. And a second pass run with too large a batch on a constrained card gets interrupted partway, leaving you with a complete first stage and half a second. Check those three before you change the model.
— Nam Hoai (Nam Hoài Đất Mỏ)