@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 16863072ca
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 3, 19:00 UTC

[Bugfix] Fix scipy audio resampling ratio (#42233)

Signed-off-by: JooHo Lee <BWAAEEEK@users.noreply.github.com> Co-authored-by: JooHo Lee <BWAAEEEK@users.noreply.github.com>

JooHo Lee committed May 13, 2026 at 19:52 UTC 16863072ca26bb873527999b220b52a39143eb23
2 files changed +34 -6
tests/multimodal/test_audio.py
+21 -1
@@ -1,6 +1,7 @@
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 # test_audio.py
4 +import math
5 from unittest.mock import patch
6
7 import numpy as np
@@ -45,7 +46,6 @@ def test_resample_audio_scipy(dummy_audio):
46 assert np.all(out_same == dummy_audio)
47
48
48 -@pytest.mark.xfail(reason="resample_audio_scipy is buggy for non-integer ratios")
49 def test_resample_audio_scipy_non_integer_ratio(dummy_audio):
50 out = resample_audio_scipy(dummy_audio, orig_sr=5, target_sr=3)
51
@@ -56,6 +56,26 @@ def test_resample_audio_scipy_non_integer_ratio(dummy_audio):
56 assert np.isfinite(out).all()
57
58
59 +def test_resample_audio_scipy_non_divisible_sample_rates():
60 + audio = np.arange(441, dtype=float)
61 + out = resample_audio_scipy(audio, orig_sr=44100, target_sr=16000)
62 +
63 + expected_len = math.ceil(len(audio) * 16000 / 44100)
64 + assert len(out) == expected_len
65 +
66 + assert isinstance(out, np.ndarray)
67 + assert np.isfinite(out).all()
68 +
69 +
70 +def test_resample_audio_scipy_resamples_last_axis_for_multichannel():
71 + audio = np.arange(2 * 441, dtype=float).reshape(2, 441)
72 + out = resample_audio_scipy(audio, orig_sr=44100, target_sr=16000)
73 +
74 + expected_len = math.ceil(audio.shape[-1] * 16000 / 44100)
75 + assert out.shape == (2, expected_len)
76 + assert np.isfinite(out).all()
77 +
78 +
79 def test_audio_resampler_pyav_calls_resample(dummy_audio):
80 resampler = AudioResampler(target_sr=22050, method="pyav")
81 with patch("vllm.multimodal.audio.resample_audio_pyav") as mock_resample:
vllm/multimodal/audio.py
+13 -5
@@ -230,11 +230,19 @@ def resample_audio_scipy(
230 orig_sr: float,
231 target_sr: float,
232 ) -> npt.NDArray[np.floating]:
233 - if orig_sr > target_sr:
234 - return scipy_signal.resample_poly(audio, 1, orig_sr // target_sr)
235 - elif orig_sr < target_sr:
236 - return scipy_signal.resample_poly(audio, target_sr // orig_sr, 1)
237 - return audio
233 + orig_sr_int = int(round(orig_sr))
234 + target_sr_int = int(round(target_sr))
235 +
236 + if orig_sr_int == target_sr_int:
237 + return audio
238 +
239 + gcd = math.gcd(orig_sr_int, target_sr_int)
240 + return scipy_signal.resample_poly(
241 + audio,
242 + target_sr_int // gcd,
243 + orig_sr_int // gcd,
244 + axis=-1,
245 + )
246
247
248 class AudioResampler: