Skip to content

fix: correct segment order in batched k2 forced_align - #76

Open
lumpidu wants to merge 1 commit into
Stylish-TTS:mainfrom
lumpidu:fix/k2_batched_alignment
Open

fix: correct segment order in batched k2 forced_align#76
lumpidu wants to merge 1 commit into
Stylish-TTS:mainfrom
lumpidu:fix/k2_batched_alignment

Conversation

@lumpidu

@lumpidu lumpidu commented May 29, 2026

Copy link
Copy Markdown

forced_align returned per-segment frame labels and scores in the wrong order for batches larger than one. encode_supervisions sorts the batch by length and returns the permutation, but forced_align never applied it, so each segment received another segment's alignment and score and the resulting durations did not match the token counts. Single-segment batches were correct because there was nothing to sort.

The fix splits the scores by the sorted per-segment lengths and then restores the original batch order for both the labels and the scores.

It also adds the local k2 import that forced_align was missing; without it the method raised a NameError, so the batched path had never run. The training loss is unaffected because it returns an order-independent scalar, which is why alignment training looked healthy while the exported alignments were scrambled.

forced_align returned per-segment frame labels and scores in the wrong
order for batches larger than one. encode_supervisions sorts the batch by
length and returns the permutation, but forced_align never applied it, so
each segment received another segment's alignment and score and the
resulting durations did not match the token counts. Single-segment batches
were correct because there was nothing to sort.

The fix splits the scores by the sorted per-segment lengths and then
restores the original batch order for both the labels and the scores.

It also adds the local k2 import that forced_align was missing; without it
the method raised a NameError, so the batched path had never run. The
training loss is unaffected because it returns an order-independent scalar,
which is why alignment training looked healthy while the exported
alignments were scrambled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant