-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Support encoder input chunking for SALM vLLM inference #15716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20b19ff
Support encoder input chunking for SALM vLLM inference
pzelasko d9f0a09
Merge branch 'main' into chunked-vllm-salm-inference
pzelasko 0c3e9dd
Fixes for multi-audio turns, audiobench
pzelasko 1ff85ad
Add missing constants
pzelasko 25bb66b
Address SALM vLLM review feedback
pzelasko 98e5e43
Merge branch 'main' into chunked-vllm-salm-inference
pzelasko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,12 @@ | |
| pytest.importorskip("vllm") | ||
|
|
||
| from nemo.collections.asr.parts.submodules.subsampling import calc_length | ||
| from nemo.collections.speechlm2.vllm.salm.audio import NeMoSpeechLMProcessingInfo | ||
| from nemo.collections.speechlm2.vllm.salm.audio import ( | ||
| _DUMMY_AUDIO_MAX_DURATION_S, | ||
| _MIN_CHUNK_SIZE_SAMPLES, | ||
| _SAMPLING_RATE, | ||
| NeMoSpeechLMProcessingInfo, | ||
| ) | ||
|
|
||
|
|
||
| def _reference(audio_length_samples: int) -> int: | ||
|
|
@@ -80,3 +85,85 @@ def test_estimator_matches_calc_length(samples: int) -> None: | |
| def test_estimator_min_one() -> None: | ||
| """Even for very short audio the estimator must return at least 1.""" | ||
| assert NeMoSpeechLMProcessingInfo._estimate_audio_tokens(1) >= 1 | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also need test for |
||
|
|
||
| def test_estimator_chunking_disabled_matches_single_pass() -> None: | ||
| """``chunk_size_seconds=None`` must match the legacy single-pass estimate.""" | ||
| samples = 30 * 16_000 | ||
| assert NeMoSpeechLMProcessingInfo._estimate_audio_tokens( | ||
| samples, chunk_size_seconds=None | ||
| ) == NeMoSpeechLMProcessingInfo._estimate_audio_tokens_single_pass(samples) | ||
|
|
||
|
|
||
| def test_estimator_short_audio_falls_back_to_single_pass() -> None: | ||
| """Audio shorter than the chunk size collapses to a single forward.""" | ||
| samples = 5 * 16_000 | ||
| assert NeMoSpeechLMProcessingInfo._estimate_audio_tokens( | ||
| samples, chunk_size_seconds=30.0 | ||
| ) == NeMoSpeechLMProcessingInfo._estimate_audio_tokens_single_pass(samples) | ||
|
|
||
|
|
||
| def test_estimator_chunked_sums_per_chunk_frames() -> None: | ||
| """Long audio is split into chunks and per-chunk frame counts are summed, | ||
| matching ``encode_audio_with_optional_chunking``'s concat behavior.""" | ||
| samples = 90 * 16_000 | ||
| chunk_size_seconds = 30.0 | ||
| chunk_samples = int(round(chunk_size_seconds * 16_000)) | ||
| expected = sum( | ||
| NeMoSpeechLMProcessingInfo._estimate_audio_tokens_single_pass(min(chunk_samples, samples - i)) | ||
| for i in range(0, samples, chunk_samples) | ||
| ) | ||
| assert ( | ||
| NeMoSpeechLMProcessingInfo._estimate_audio_tokens(samples, chunk_size_seconds=chunk_size_seconds) == expected | ||
| ) | ||
|
|
||
|
|
||
| def test_estimator_chunked_tail_folded_into_previous_chunk() -> None: | ||
| """A tiny tail (< min chunk size) is folded into the previous chunk so | ||
| the total token count matches the runtime helper instead of producing a | ||
| spurious single-frame chunk that the audio preprocessor would reject.""" | ||
| chunk_size_seconds = 30.0 | ||
| chunk_samples = int(round(chunk_size_seconds * 16_000)) | ||
| samples = chunk_samples + 100 # 100 sample tail < min_chunk_size_samples (320) | ||
| # Folded: one chunk of `samples` samples (no split). | ||
| expected = NeMoSpeechLMProcessingInfo._estimate_audio_tokens_single_pass(samples) | ||
| assert ( | ||
| NeMoSpeechLMProcessingInfo._estimate_audio_tokens(samples, chunk_size_seconds=chunk_size_seconds) == expected | ||
| ) | ||
|
|
||
|
|
||
| def test_estimator_clamps_tiny_chunk_size_to_min_samples() -> None: | ||
| assert _MIN_CHUNK_SIZE_SAMPLES == 320 | ||
|
|
||
| chunk_size_seconds = 1 / _SAMPLING_RATE | ||
| samples = 2 * _MIN_CHUNK_SIZE_SAMPLES + 100 | ||
| expected = NeMoSpeechLMProcessingInfo._estimate_audio_tokens_single_pass( | ||
| _MIN_CHUNK_SIZE_SAMPLES | ||
| ) + NeMoSpeechLMProcessingInfo._estimate_audio_tokens_single_pass(_MIN_CHUNK_SIZE_SAMPLES + 100) | ||
|
|
||
| assert ( | ||
| NeMoSpeechLMProcessingInfo._estimate_audio_tokens(samples, chunk_size_seconds=chunk_size_seconds) == expected | ||
| ) | ||
|
|
||
|
|
||
| def test_estimator_negative_chunk_size_raises() -> None: | ||
| with pytest.raises(ValueError, match="encoder_chunk_size_seconds"): | ||
| NeMoSpeechLMProcessingInfo._estimate_audio_tokens(16_000, chunk_size_seconds=-1.0) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("chunk_size_seconds", [None, 30.0]) | ||
| def test_samples_for_audio_tokens_returns_minimum_sample_count(chunk_size_seconds: float | None) -> None: | ||
| target_tokens = 17 | ||
|
|
||
| samples = NeMoSpeechLMProcessingInfo._samples_for_audio_tokens(target_tokens, chunk_size_seconds) | ||
|
|
||
| assert NeMoSpeechLMProcessingInfo._estimate_audio_tokens(samples, chunk_size_seconds) >= target_tokens | ||
| assert NeMoSpeechLMProcessingInfo._estimate_audio_tokens(samples - 1, chunk_size_seconds) < target_tokens | ||
|
|
||
|
|
||
| def test_samples_for_audio_tokens_rejects_unreachable_target() -> None: | ||
| max_samples = int(_DUMMY_AUDIO_MAX_DURATION_S * _SAMPLING_RATE) | ||
| max_tokens = NeMoSpeechLMProcessingInfo._estimate_audio_tokens(max_samples) | ||
|
|
||
| with pytest.raises(ValueError, match="Cannot produce"): | ||
| NeMoSpeechLMProcessingInfo._samples_for_audio_tokens(max_tokens + 1) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_samples_for_audio_tokens()can return the max-duration cap even when that audio is still too short to produce target_tokens (e.g., ifmax_model_lenis very large)