Signed-off-by: wangyu <410167048@qq.com> Signed-off-by: [Your Name] <your.email@example.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
db82a55162
commit
3d43571b94
21 files changed
+1012
-487
No files matched your search
@@ -0,0 +1,61 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
from contextlib import nullcontext
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.helpers import clean
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
_GIB = 2**30
|
||||
|
||||
|
||||
def _patch_wait_platform(mocker, monkeypatch, *, queried: list[int], mem_get_info):
|
||||
monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "4,5")
|
||||
monkeypatch.setattr(clean.current_omni_platform, "device_control_env_var", "CUDA_VISIBLE_DEVICES")
|
||||
|
||||
def fake_device(idx):
|
||||
queried.append(idx)
|
||||
return nullcontext()
|
||||
|
||||
mocker.patch.object(clean.current_omni_platform, "device", side_effect=fake_device)
|
||||
mocker.patch.object(clean.current_omni_platform, "mem_get_info", side_effect=mem_get_info)
|
||||
mocker.patch.object(clean.current_omni_platform, "empty_cache")
|
||||
mocker.patch.object(clean.time, "sleep")
|
||||
|
||||
|
||||
def test_wait_queries_logical_ordinals_when_visible_set_is_physical(mocker, monkeypatch):
|
||||
"""#6523 kept a physical remap after switching off NVML; device(4) is invalid."""
|
||||
queried: list[int] = []
|
||||
|
||||
def mem_get_info():
|
||||
return (99 * _GIB, 100 * _GIB)
|
||||
|
||||
_patch_wait_platform(mocker, monkeypatch, queried=queried, mem_get_info=mem_get_info)
|
||||
monkeypatch.setattr(clean, "_whisper_vram_allowance", lambda: (0.0, None))
|
||||
|
||||
clean.wait_for_gpu_memory_to_clear(devices=[0, 1], threshold_ratio=0.05, timeout_s=1)
|
||||
|
||||
assert queried == [0, 1]
|
||||
assert 4 not in queried
|
||||
assert 5 not in queried
|
||||
|
||||
|
||||
def test_wait_matches_whisper_on_physical_id_not_logical(mocker, monkeypatch):
|
||||
queried: list[int] = []
|
||||
|
||||
def mem_get_info():
|
||||
logical = queried[-1]
|
||||
if logical == 0:
|
||||
return (99 * _GIB, 100 * _GIB)
|
||||
return (50 * _GIB, 100 * _GIB)
|
||||
|
||||
_patch_wait_platform(mocker, monkeypatch, queried=queried, mem_get_info=mem_get_info)
|
||||
# logical 1 → physical 5; without physical matching this 50% used card fails 15%.
|
||||
monkeypatch.setattr(clean, "_whisper_vram_allowance", lambda: (40.0, 5))
|
||||
|
||||
clean.wait_for_gpu_memory_to_clear(devices=[0, 1], threshold_ratio=0.15, timeout_s=1)
|
||||
|
||||
assert queried == [0, 1]
|
||||
@@ -76,7 +76,7 @@ class _FakeExecutor:
|
||||
|
||||
def submit(self, fn, *args):
|
||||
self.submitted.append((fn, args))
|
||||
outcome = self._outcomes.pop(0) if self._outcomes else "London"
|
||||
outcome = self._outcomes.pop(0) if self._outcomes else ("London", "cpu")
|
||||
|
||||
def _result():
|
||||
if isinstance(outcome, BaseException):
|
||||
@@ -110,9 +110,13 @@ def _reset_transcriber_singletons():
|
||||
"""The worker and its model cache are module-level state; do not leak them across tests."""
|
||||
media.release_audio_transcriber()
|
||||
media._WHISPER_MODELS.clear()
|
||||
media._WHISPER_LOADED_DEVICE = None
|
||||
media._TRANSCRIBER_RESERVED_GIB = 0.0
|
||||
yield
|
||||
media.release_audio_transcriber()
|
||||
media._WHISPER_MODELS.clear()
|
||||
media._WHISPER_LOADED_DEVICE = None
|
||||
media._TRANSCRIBER_RESERVED_GIB = 0.0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -236,7 +240,10 @@ def test_worker_loads_each_model_size_once(monkeypatch):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("second_outcome", "recovers"),
|
||||
[(["London"], True), ([BrokenProcessPool("second")], False)],
|
||||
[
|
||||
([("London", "cpu")], True),
|
||||
([BrokenProcessPool("second")], False),
|
||||
],
|
||||
)
|
||||
def test_broken_pool_is_discarded_and_retried_once(monkeypatch, second_outcome, recovers):
|
||||
"""A dead worker is discarded and the call retried exactly once.
|
||||
@@ -286,3 +293,103 @@ def test_transcription_failure_propagates_and_discards_the_worker(monkeypatch, e
|
||||
|
||||
assert media.convert_audio_file_to_text("/tmp/b.wav") == "London"
|
||||
assert len(created) == 2 # a fresh worker for the next call
|
||||
|
||||
|
||||
def test_whisper_resident_vram_is_zero_until_a_gpu_result(monkeypatch):
|
||||
"""CPU fallback and in-flight loads must not hide engine leaks on the last GPU."""
|
||||
assert media.whisper_resident_vram_gib() == 0.0
|
||||
assert media.whisper_resident_device_index() is None
|
||||
|
||||
created = _patch_executors(monkeypatch, outcomes_per_executor=([("London", "cpu")],))
|
||||
media.convert_audio_file_to_text("/tmp/a.wav", "small")
|
||||
|
||||
assert created[0].submitted
|
||||
assert media.whisper_resident_vram_gib() == 0.0
|
||||
assert media.whisper_resident_device_index() is None
|
||||
|
||||
|
||||
def test_whisper_resident_vram_tracks_gpu_device_after_success(monkeypatch):
|
||||
_patch_executors(
|
||||
monkeypatch,
|
||||
outcomes_per_executor=([("London", "cuda:1", 2.5), ("Paris", "cuda:1", 9.6)],),
|
||||
)
|
||||
media.convert_audio_file_to_text("/tmp/a.wav", "small")
|
||||
assert media.whisper_resident_device_index() == 1
|
||||
assert media.whisper_resident_vram_gib() == pytest.approx(2.5)
|
||||
|
||||
media.convert_audio_file_to_text("/tmp/b.wav", "large-v3")
|
||||
assert media.whisper_resident_device_index() == 1
|
||||
assert media.whisper_resident_vram_gib() == pytest.approx(9.6)
|
||||
|
||||
media.release_audio_transcriber()
|
||||
assert media.whisper_resident_vram_gib() == 0.0
|
||||
assert media.whisper_resident_device_index() is None
|
||||
|
||||
|
||||
def test_whisper_unmeasured_gpu_result_credits_zero(monkeypatch):
|
||||
"""A GPU device without a reserved reading must not invent a size-table credit."""
|
||||
_patch_executors(monkeypatch, outcomes_per_executor=([("London", "cuda:0")],))
|
||||
media.convert_audio_file_to_text("/tmp/a.wav", "not-a-whisper-size")
|
||||
assert media.whisper_resident_device_index() == 0
|
||||
assert media.whisper_resident_vram_gib() == 0.0
|
||||
|
||||
|
||||
def test_whisper_resident_vram_uses_child_reserved(monkeypatch):
|
||||
_patch_executors(monkeypatch, outcomes_per_executor=([("London", "cuda:0", 1.0)],))
|
||||
media.convert_audio_file_to_text("/tmp/a.wav", "small")
|
||||
assert media.whisper_resident_vram_gib() == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_whisper_resident_vram_does_not_cap_measured_reserved(monkeypatch):
|
||||
_patch_executors(monkeypatch, outcomes_per_executor=([("London", "cuda:0", 20.0)],))
|
||||
media.convert_audio_file_to_text("/tmp/a.wav", "small")
|
||||
assert media.whisper_resident_vram_gib() == pytest.approx(20.0)
|
||||
|
||||
|
||||
def test_whisper_unknown_size_uses_measured_reserved(monkeypatch):
|
||||
_patch_executors(monkeypatch, outcomes_per_executor=([("London", "cuda:0", 3.0)],))
|
||||
media.convert_audio_file_to_text("/tmp/a.wav", "not-a-whisper-size")
|
||||
assert media.whisper_resident_vram_gib() == pytest.approx(3.0)
|
||||
|
||||
|
||||
def test_later_whisper_sizes_reuse_the_first_selected_device(monkeypatch):
|
||||
selected: list[str] = []
|
||||
|
||||
def fake_model(_size, device=None):
|
||||
return SimpleNamespace(transcribe=lambda *_a, **_k: {"text": "x"})
|
||||
|
||||
def select_device() -> str:
|
||||
selected.append("cuda:1")
|
||||
return "cuda:1"
|
||||
|
||||
monkeypatch.setattr(media, "_select_whisper_device", select_device)
|
||||
monkeypatch.setitem(sys.modules, "whisper", SimpleNamespace(load_model=fake_model))
|
||||
monkeypatch.setattr(media, "_serialize_whisper_model_download", lambda model_size: nullcontext())
|
||||
|
||||
text, device, _reserved = media._whisper_transcribe_in_current_process("/tmp/a.wav", "small")
|
||||
assert (text, device) == ("x", "cuda:1")
|
||||
media._whisper_transcribe_in_current_process("/tmp/b.wav", "large-v3")
|
||||
assert selected == ["cuda:1"]
|
||||
assert media._WHISPER_LOADED_DEVICE == "cuda:1"
|
||||
|
||||
|
||||
def test_cleanup_whisper_allowance_is_zero_on_cpu(monkeypatch):
|
||||
from tests.helpers import clean
|
||||
|
||||
monkeypatch.setattr(media, "whisper_resident_vram_gib", lambda: 11.0)
|
||||
monkeypatch.setattr(media, "whisper_resident_device_index", lambda: None)
|
||||
assert clean._whisper_vram_allowance() == (0.0, None)
|
||||
|
||||
|
||||
def test_cleanup_whisper_allowance_maps_logical_gpu(monkeypatch):
|
||||
from tests.helpers import clean
|
||||
|
||||
monkeypatch.setattr(media, "whisper_resident_vram_gib", lambda: 2.5)
|
||||
monkeypatch.setattr(media, "whisper_resident_device_index", lambda: 1)
|
||||
monkeypatch.setattr(clean, "get_physical_device_indices", lambda devices: [7] if devices == [1] else [])
|
||||
assert clean._whisper_vram_allowance() == (2.5, 7)
|
||||
|
||||
|
||||
def test_whisper_has_no_size_table():
|
||||
assert not hasattr(media, "_WHISPER_VRAM_GIB")
|
||||
assert not hasattr(media, "_WHISPER_VRAM_GIB_DEFAULT")
|
||||
Reference in new issue
Block a user