[Refactor] Centralize metrics related helpers to metrics/ (#5168)
This commit is contained in:
1 parent
e9a06d5bdc
commit
778959797c
9 files changed
+480
-259
No files matched your search
@@ -30,7 +30,6 @@ from vllm_omni.engine.orchestrator import (
|
||||
Orchestrator,
|
||||
OrchestratorRequestState,
|
||||
_build_terminal_empty_output,
|
||||
_infer_stage_audio_sample_rate,
|
||||
)
|
||||
from vllm_omni.engine.stage_pool import StagePool
|
||||
from vllm_omni.experimental.fullduplex.engine.duplex_control_plane import DuplexControlPlane
|
||||
@@ -201,12 +200,12 @@ class FakeStageClient:
|
||||
def test_terminal_empty_audio_output_uses_stage_sample_rate() -> None:
|
||||
final_stage = FakeStageClient(final_output=True, final_output_type="audio")
|
||||
final_stage.sample_rate = 44100
|
||||
final_pool = SimpleNamespace(stage_client=final_stage, _stage_vllm_config=None)
|
||||
final_pool = StagePool(0, [final_stage])
|
||||
|
||||
terminal_output = _build_terminal_empty_output(
|
||||
"req-1",
|
||||
final_output_type="audio",
|
||||
audio_sample_rate=_infer_stage_audio_sample_rate(final_pool),
|
||||
audio_sample_rate=final_pool._infer_audio_sample_rate(),
|
||||
)
|
||||
|
||||
assert terminal_output.outputs[0].multimodal_output["sr"] == 44100
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.metrics.utils import (
|
||||
count_audio_chunk_frames,
|
||||
count_audio_frames,
|
||||
count_image_pixels,
|
||||
count_tokens_from_outputs,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("audio_chunk", "expected"),
|
||||
[
|
||||
(SimpleNamespace(shape=(2, 320)), 320),
|
||||
([0.0, 0.0, 0.0], 3),
|
||||
(1.0, 1),
|
||||
],
|
||||
)
|
||||
def test_count_audio_chunk_frames(audio_chunk: object, expected: int) -> None:
|
||||
assert count_audio_chunk_frames(audio_chunk) == expected
|
||||
|
||||
|
||||
def test_count_audio_frames_sums_audio_chunks() -> None:
|
||||
mm_out = {
|
||||
"audio": [
|
||||
SimpleNamespace(shape=(1, 120)),
|
||||
SimpleNamespace(shape=(2, 80)),
|
||||
]
|
||||
}
|
||||
|
||||
assert count_audio_frames(mm_out) == 200
|
||||
|
||||
|
||||
def test_count_audio_frames_supports_model_outputs() -> None:
|
||||
mm_out = {
|
||||
"model_outputs": [
|
||||
SimpleNamespace(shape=(1, 120)),
|
||||
SimpleNamespace(shape=(2, 80)),
|
||||
]
|
||||
}
|
||||
|
||||
assert count_audio_frames(mm_out) == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mm_out", [{}, {"audio": None}, {"model_outputs": None}])
|
||||
def test_count_audio_frames_returns_zero_without_audio(mm_out: dict[str, object]) -> None:
|
||||
assert count_audio_frames(mm_out) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected"),
|
||||
[
|
||||
(None, 0),
|
||||
(object(), 0),
|
||||
(SimpleNamespace(size=(10, 20)), 200),
|
||||
(SimpleNamespace(shape=(2, 3, 4, 5)), 40),
|
||||
(SimpleNamespace(shape=(3, 4, 5)), 20),
|
||||
(SimpleNamespace(shape=(6, 7, 3)), 42),
|
||||
(SimpleNamespace(shape=(6, 7)), 42),
|
||||
],
|
||||
)
|
||||
def test_count_image_pixels(value: object, expected: int) -> None:
|
||||
assert count_image_pixels(value) == expected
|
||||
|
||||
|
||||
def test_count_image_pixels_sums_nested_values() -> None:
|
||||
images = [
|
||||
SimpleNamespace(size=(10, 20)),
|
||||
(
|
||||
SimpleNamespace(shape=(3, 4, 5)),
|
||||
SimpleNamespace(shape=(6, 7, 3)),
|
||||
),
|
||||
]
|
||||
|
||||
assert count_image_pixels(images) == 262
|
||||
|
||||
|
||||
def test_count_tokens_from_outputs() -> None:
|
||||
engine_outputs = [
|
||||
SimpleNamespace(
|
||||
outputs=[
|
||||
SimpleNamespace(cumulative_token_ids=[1, 2, 3], token_ids=[3]),
|
||||
SimpleNamespace(cumulative_token_ids=None, token_ids=[4, 5]),
|
||||
SimpleNamespace(cumulative_token_ids=None, token_ids=None),
|
||||
]
|
||||
),
|
||||
SimpleNamespace(outputs=None),
|
||||
SimpleNamespace(
|
||||
outputs=[
|
||||
SimpleNamespace(cumulative_token_ids=[6], token_ids=[6]),
|
||||
]
|
||||
),
|
||||
]
|
||||
|
||||
assert count_tokens_from_outputs(engine_outputs) == 6
|
||||
Reference in new issue
Block a user