Skip to content

Fix: Alignment stream analyzer added a new forward hook for each utterance#455

Open
tobmi1 wants to merge 1 commit intoresemble-ai:masterfrom
tobmi1:fix_alignment_stream_analyzer
Open

Fix: Alignment stream analyzer added a new forward hook for each utterance#455
tobmi1 wants to merge 1 commit intoresemble-ai:masterfrom
tobmi1:fix_alignment_stream_analyzer

Conversation

@tobmi1
Copy link

@tobmi1 tobmi1 commented Feb 1, 2026

A new instance of the alignment stream analyzer is currently being instantiated for each call of T3.inference:

self.compiled = False
# TODO? synchronize the expensive compile function
# with self.compile_lock:
if not self.compiled:
# Default to None for English models, only create for multilingual
alignment_stream_analyzer = None
if self.hp.is_multilingual:
alignment_stream_analyzer = AlignmentStreamAnalyzer(
self.tfmr,
None,
text_tokens_slice=(len_cond, len_cond + text_tokens.size(-1)),
alignment_layer_idx=9, # TODO: hparam or something?
eos_idx=self.hp.stop_speech_token,
)
assert alignment_stream_analyzer.eos_idx == self.hp.stop_speech_token

Hence, each time a new forward hook is added to the backbone's self-attention layers. When generating multiple utterances, this will eventually slow down the generation. After 1000 utterances, the attention masks will be copied 1000 times from GPU to CPU when running on CUDA. This affects the multilingual model since the alignment stream analyzer is enabled by default for it, see, for example, #352.

This PR changes the logic so that the alignment stream analyzer is only instantiated once, and its internal state is instead reset for each utterance without adding new forward hooks to the backbone model.

I tested the fix by generating ~8500 short utterances, which now takes ~4.5h instead of ~50h on my setup.

A big thanks to @benHeid for pointing out the issue in #352! 😊

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