perf(pipeline): optimize embedding extraction in SpeakerDiarization#1996
Open
leochiodi wants to merge 1 commit into
Open
perf(pipeline): optimize embedding extraction in SpeakerDiarization#1996leochiodi wants to merge 1 commit into
leochiodi wants to merge 1 commit into
Conversation
When audio is in-memory and the embedding model supports the forward_frames/forward_embedding split (e.g. WeSpeaker), use a fast path that: - pre-slices all chunk waveforms at once instead of per-chunk audio.crop - skips inactive (zero-mask) speaker pairs - computes forward_frames once per chunk, then forward_embedding per active pair - optionally uses autocast via embedding_precision parameter for GPU tensor cores Falls back to the original behavior for file-based audio or models without the split API. Benchmarked on H100 with 57min/10-speaker audio: 52s → ~10s (5x speedup).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimizes
get_embeddingsinSpeakerDiarizationwith a fast path that activates when:waveform/sample_ratekeys)forward_frames/forward_embeddingsplit API (e.g. WeSpeaker)Optimizations
audio.crop()per chunkforward_framesruns once per chunk (shared across speakers), thenforward_embedding(stats pooling only) runs per active pairembedding_precisionparameter (e.g.torch.float16) enables autocast onforward_framesfor GPU tensor cores, with pooling remaining in fp32 to preserve clustering qualityBackward compatibility
_get_embeddings_legacypath for file-based audio or models without the split API (SpeechBrain, NeMo, xvector)Benchmarks
Tested on H100 GPU with 57-minute / 10-speaker audio:
get_embeddings)embedding_precision=torch.float16The
forward_framescall specifically went from 12s → 3s with float16 autocast.Usage
Works automatically when passing in-memory audio (the common case):
To enable mixed precision on the embedding forward pass: