Repository navigation
fix: run Sortformer inference off the event loop - #461
Open
guhyun9454 wants to merge 1 commit into
Open
guhyun9454 wants to merge 1 commit into
guhyun9454 wants to merge 1 commit into
Conversation
SortformerDiarizationOnline.diarize() is a coroutine but ran the mel features and forward_streaming_step synchronously, blocking the asyncio loop for the whole forward pass. On a loaded host this starves the WebSocket keepalive, the server drops the connection (1011 keepalive ping timeout), and the client reconnects into a fresh session. Slice the buffer on the loop as before, then run the chunk inference via asyncio.to_thread, matching how the ASR path was fixed in QuentinFuxa#220.
This branch has not been deployed
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
SortformerDiarizationOnline.diarize()isasync def, but it ran the mel feature extraction andforward_streaming_stepsynchronously, so every chunk blocked the asyncio event loop for the whole forward pass. This is the same failure mode #220 described and fixed for the ASR path (asyncio.to_thread(process_iter)); the Sortformer path was left on the loop.This PR keeps the buffer slicing on the loop (so
insert_audio_chunkanddiarizestill never touchbuffer_audioconcurrently) and moves the per-chunk inference into_diarize_chunk, run viaasyncio.to_thread.User impact
--backend mlx-whisper --diarization, Sortformer on an Apple M1 Pro under memory pressure): the web UI repeatedly showedConnected. Using MediaRecorder (WebM).. The client auto-reconnected, each reconnect started a new session, and speaker labels were reset. Per-chunk inference that takes ~0.6 s on an idle machine grows to several seconds when the host is swapping, which is enough to miss the server's keepalive ping.diar_modelis shared across sessions, so with several sessions the forward passes can now overlap in worker threads, as the ASR backends already do withto_thread. Streaming state is per session; the model runs undertorch.inference_mode().Validation
Regression test:
tests/test_sortformer_event_loop.py. It uses a fake model whose forward pass blocks for 0.5 s and asserts that a heartbeat coroutine keeps ticking duringdiarize(). It also checks the returned segments,_chunk_indexand buffer consumption.assert 0.521 < 0.25(the loop was blocked for the whole forward pass).Real model:
nvidia/diar_streaming_sortformer_4spk-v2on CPU, Apple M1 Pro, Python 3.13.12, torch 2.14.1, NeMo 3.0.0. I fed the twotests/fixtures/sortformer_2spkclips at real-time pace and measured event-loop stalls with a 10 ms heartbeat.Suite:
uv run ruff check .: all checks passeduv lock --check: OKuv run pytest -q tests/ --ignore=tests/test_pipeline.py --ignore=tests/test_asr_coalescing_pipeline.py: 314 passed, 16 skippedChecklist
ruff check ..