[Frontend][Benchmark] Add judger and accuracy metrics for OmniInterac… (#7317)
Co-authored-by: Gao Han <hgaoaf@connect.ust.hk>
This commit is contained in:
1 parent
1d77e96d4d
commit
926ba72793
13 files changed
+4165
-30
No files matched your search
@@ -249,6 +249,252 @@ def test_dataset_discovers_official_layouts_and_total_selection(tmp_path: Path):
|
||||
assert [case.subset for case in selected] == ["1q1a", "1q1a_math"]
|
||||
|
||||
|
||||
def _write_scenario_dataset(root: Path) -> Path:
|
||||
data_root = root / "data"
|
||||
one_q1a = data_root / "1q1a"
|
||||
(one_q1a / "videos").mkdir(parents=True)
|
||||
(one_q1a / "annotations").mkdir()
|
||||
entries = []
|
||||
specs = [
|
||||
("realtime", "multi_turn", [{"question_time": 0.0, "answer_time": 1.0, "question_type": "realtime"}]),
|
||||
("proactive", "multi_turn", [{"question_time": 0.0, "answer_time": 1.0, "question_type": "proactive"}]),
|
||||
(
|
||||
"nested",
|
||||
"nested",
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 4.0,
|
||||
"question_type": "proactive",
|
||||
"question_text": "outer",
|
||||
"answer_text": "outer",
|
||||
},
|
||||
{
|
||||
"question_time": 1.0,
|
||||
"answer_time": 2.0,
|
||||
"question_type": "realtime",
|
||||
"question_text": "inner",
|
||||
"answer_text": "inner",
|
||||
},
|
||||
],
|
||||
),
|
||||
(
|
||||
"interrupted",
|
||||
"multi_turn",
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 1.0,
|
||||
"question_type": "realtime",
|
||||
"is_interrupted": True,
|
||||
}
|
||||
],
|
||||
),
|
||||
]
|
||||
for name, scene, annotation in specs:
|
||||
video = one_q1a / "videos" / f"{name}.mp4"
|
||||
ann = one_q1a / "annotations" / f"{name}.json"
|
||||
video.touch()
|
||||
ann.write_text(json.dumps(annotation))
|
||||
entries.append(
|
||||
{
|
||||
"video": f"videos/{name}.mp4",
|
||||
"annotation": f"annotations/{name}.json",
|
||||
"scene_type": scene,
|
||||
}
|
||||
)
|
||||
(one_q1a / "video_json_map.json").write_text(json.dumps({"entries": entries}))
|
||||
|
||||
one_qna = data_root / "1qna"
|
||||
(one_qna / "videos_bench").mkdir(parents=True)
|
||||
(one_qna / "annotations").mkdir(parents=True)
|
||||
(one_qna / "videos_bench" / "guide.mp4").touch()
|
||||
(one_qna / "annotations" / "guide.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"question_text": "q",
|
||||
"answers": [{"answer_time": 1.0, "answer_text": "a", "label": "step"}],
|
||||
}
|
||||
)
|
||||
)
|
||||
math_root = data_root / "1q1a_math"
|
||||
(math_root / "videos").mkdir(parents=True)
|
||||
(math_root / "annotations").mkdir()
|
||||
(math_root / "videos" / "math.mp4").touch()
|
||||
(math_root / "annotations" / "math.json").write_text(
|
||||
json.dumps([{"question_time": 0.0, "answer_time": 1.0, "question_type": "realtime"}])
|
||||
)
|
||||
(math_root / "video_json_map.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"entries": [
|
||||
{
|
||||
"video": "videos/math.mp4",
|
||||
"annotation": "annotations/math.json",
|
||||
"scene_type": "multi_turn",
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
)
|
||||
return data_root
|
||||
|
||||
|
||||
def test_scenario_cover_and_focus_sampling(tmp_path: Path) -> None:
|
||||
root = _write_scenario_dataset(tmp_path)
|
||||
covered = data.discover_omniinteract_cases(
|
||||
root,
|
||||
("1q1a", "1q1a_math", "1qna"),
|
||||
num_prompts=5,
|
||||
disable_shuffle=True,
|
||||
scenario_tags=("realtime", "proactive", "nested", "interrupted", "1qna"),
|
||||
)
|
||||
assert len(covered) == 5
|
||||
covered_tags = set().union(*(data.case_scenario_tags(case) for case in covered))
|
||||
assert {"realtime", "proactive", "nested", "interrupted", "1qna"} <= covered_tags
|
||||
|
||||
focused = data.discover_omniinteract_cases(
|
||||
root,
|
||||
("1q1a", "1q1a_math", "1qna"),
|
||||
num_prompts=0,
|
||||
disable_shuffle=True,
|
||||
scenario_tags=("nested", "1qna"),
|
||||
scenario_focus=True,
|
||||
)
|
||||
assert {case.scene_type for case in focused} == {"nested", "1qna"}
|
||||
|
||||
|
||||
def test_load_cases_from_video_list_preserves_order_and_caps(tmp_path: Path) -> None:
|
||||
root = _write_dataset(tmp_path)
|
||||
all_cases = data.discover_omniinteract_cases(root, data.OMNIINTERACT_SUBSETS, num_prompts=0, disable_shuffle=True)
|
||||
ordered = list(reversed(all_cases))
|
||||
video_list = tmp_path / "sampled_cases.jsonl"
|
||||
video_list.write_text("".join(json.dumps(data.sampled_case_row(case)) + "\n" for case in ordered))
|
||||
|
||||
capped = data.load_omniinteract_cases_from_video_list(video_list, num_prompts=2)
|
||||
assert [case.video_path for case in capped] == [case.video_path for case in ordered[:2]]
|
||||
|
||||
full = data.load_omniinteract_cases_from_video_list(video_list, num_prompts=0)
|
||||
assert [case.video_path for case in full] == [case.video_path for case in ordered]
|
||||
oversized = data.load_omniinteract_cases_from_video_list(video_list, num_prompts=99)
|
||||
assert [case.video_path for case in oversized] == [case.video_path for case in ordered]
|
||||
|
||||
|
||||
def test_load_cases_from_video_list_requires_existing_video(tmp_path: Path) -> None:
|
||||
root = _write_dataset(tmp_path)
|
||||
case = data.discover_omniinteract_cases(root, ("1q1a",), num_prompts=1, disable_shuffle=True)[0]
|
||||
row = data.sampled_case_row(case)
|
||||
row["video_path"] = str(tmp_path / "missing.mp4")
|
||||
video_list = tmp_path / "bad.jsonl"
|
||||
video_list.write_text(json.dumps(row) + "\n")
|
||||
with pytest.raises(FileNotFoundError, match="video missing"):
|
||||
data.load_omniinteract_cases_from_video_list(video_list, num_prompts=0)
|
||||
|
||||
|
||||
def test_get_samples_from_video_list_without_dataset_path(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
root = _write_dataset(tmp_path)
|
||||
cases = data.discover_omniinteract_cases(root, data.OMNIINTERACT_SUBSETS, num_prompts=0, disable_shuffle=True)
|
||||
video_list = tmp_path / "sampled_cases.jsonl"
|
||||
video_list.write_text("".join(json.dumps(data.sampled_case_row(case)) + "\n" for case in cases))
|
||||
ref = tmp_path / "ref.wav"
|
||||
ref.touch()
|
||||
parser = TrackingArgumentParser()
|
||||
OmniBenchmarkServingSubcommand.add_cli_args(parser)
|
||||
args = parser.parse_args(
|
||||
[
|
||||
"--backend",
|
||||
"openai-realtime-duplex",
|
||||
"--dataset-name",
|
||||
"omniinteract",
|
||||
"--model",
|
||||
MODEL,
|
||||
"--endpoint",
|
||||
"/v1/realtime",
|
||||
"--num-prompts",
|
||||
"2",
|
||||
"--omniinteract-ref-audio",
|
||||
str(ref),
|
||||
"--omniinteract-video-list",
|
||||
str(video_list),
|
||||
]
|
||||
)
|
||||
preprocess_serve_args(args)
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.clients.duplex.reference_audio_data_url",
|
||||
lambda _: "data:audio/wav;base64,ref",
|
||||
)
|
||||
monkeypatch.setattr(benchmark_patch, "prepare_media", lambda *a, **k: (1.0, b"pcm", ["frame"]))
|
||||
samples = benchmark_patch.get_samples(args, None)
|
||||
assert len(samples) == 2
|
||||
assert [sample.omniinteract_case.video_path for sample in samples] == [case.video_path for case in cases[:2]]
|
||||
|
||||
|
||||
def _write_overlapping_cover_dataset(root: Path) -> Path:
|
||||
data_root = root / "data"
|
||||
one_q1a = data_root / "1q1a"
|
||||
(one_q1a / "videos").mkdir(parents=True)
|
||||
(one_q1a / "annotations").mkdir()
|
||||
entries = []
|
||||
specs = [
|
||||
(
|
||||
"pair_a",
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 1.0,
|
||||
"question_type": "realtime",
|
||||
"is_interrupted": True,
|
||||
}
|
||||
],
|
||||
),
|
||||
(
|
||||
"pair_b",
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 1.0,
|
||||
"question_type": "realtime",
|
||||
"is_interrupted": True,
|
||||
}
|
||||
],
|
||||
),
|
||||
(
|
||||
"proactive_only",
|
||||
[{"question_time": 0.0, "answer_time": 1.0, "question_type": "proactive"}],
|
||||
),
|
||||
]
|
||||
for name, annotation in specs:
|
||||
video = one_q1a / "videos" / f"{name}.mp4"
|
||||
ann = one_q1a / "annotations" / f"{name}.json"
|
||||
video.touch()
|
||||
ann.write_text(json.dumps(annotation))
|
||||
entries.append(
|
||||
{
|
||||
"video": f"videos/{name}.mp4",
|
||||
"annotation": f"annotations/{name}.json",
|
||||
"scene_type": "multi_turn",
|
||||
}
|
||||
)
|
||||
(one_q1a / "video_json_map.json").write_text(json.dumps({"entries": entries}))
|
||||
return data_root
|
||||
|
||||
|
||||
def test_cover_sampling_skips_tags_already_covered(tmp_path: Path) -> None:
|
||||
root = _write_overlapping_cover_dataset(tmp_path)
|
||||
selected = data.discover_omniinteract_cases(
|
||||
root,
|
||||
("1q1a",),
|
||||
num_prompts=2,
|
||||
disable_shuffle=True,
|
||||
scenario_tags=("realtime", "interrupted", "proactive"),
|
||||
)
|
||||
names = [case.video_path.stem for case in selected]
|
||||
assert names == ["pair_a", "proactive_only"]
|
||||
selected_tags = set().union(*(data.case_scenario_tags(case) for case in selected))
|
||||
assert {"realtime", "interrupted", "proactive"} <= selected_tags
|
||||
|
||||
|
||||
def _archive(path: Path, member: str) -> None:
|
||||
with tarfile.open(path, "w") as archive:
|
||||
content = b"{}"
|
||||
@@ -542,6 +788,51 @@ def test_ineligible_outputs_are_excluded_from_manifest(tmp_path: Path, audio_tim
|
||||
assert reason in result.official_eval_ineligible_reasons
|
||||
oi.write_batch_artifacts(tmp_path / "out", [case], [result])
|
||||
assert (tmp_path / "out" / "official_eval_manifest.jsonl").read_text() == ""
|
||||
sampled = [
|
||||
json.loads(line) for line in (tmp_path / "out" / "sampled_cases.jsonl").read_text().splitlines() if line.strip()
|
||||
]
|
||||
assert sampled == [
|
||||
{
|
||||
"video_path": str(case.video_path.resolve()),
|
||||
"output_name": data.official_output_name(case),
|
||||
"subset": case.subset,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_official_output_name_matches_minicpmo_batch_layout(tmp_path: Path):
|
||||
one_q1a = _case(tmp_path, subset="1q1a", name="videos/clip_a.mp4")
|
||||
one_qna = _case(tmp_path, subset="1qna", name="videos_bench/nested/guide.mp4")
|
||||
assert data.official_output_name(one_q1a) == "1q1a/videos__clip_a"
|
||||
assert data.official_output_name(one_qna) == "1qna/nested__guide"
|
||||
row = data.sampled_case_row(one_q1a)
|
||||
assert row["video_path"] == str(one_q1a.video_path.resolve())
|
||||
assert row["output_name"] == "1q1a/videos__clip_a"
|
||||
assert row["subset"] == "1q1a"
|
||||
|
||||
|
||||
def test_sampled_cases_jsonl_lists_every_case_including_failures(tmp_path: Path):
|
||||
ok_case = _case(tmp_path, name="videos/ok.mp4")
|
||||
bad_case = _case(tmp_path, name="videos/bad.mp4")
|
||||
ok_result = oi.OmniInteractCaseResult(
|
||||
ok_case.subset, str(ok_case.video_path), str(oi._output_dir(tmp_path / "out", ok_case)), success=True
|
||||
)
|
||||
ok_result.eligible_for_official_eval = True
|
||||
bad_result = oi.OmniInteractCaseResult(
|
||||
bad_case.subset, str(bad_case.video_path), str(oi._output_dir(tmp_path / "out", bad_case)), success=False
|
||||
)
|
||||
oi.write_batch_artifacts(tmp_path / "out", [ok_case, bad_case], [ok_result, bad_result])
|
||||
sampled = [
|
||||
json.loads(line) for line in (tmp_path / "out" / "sampled_cases.jsonl").read_text().splitlines() if line.strip()
|
||||
]
|
||||
assert [row["output_name"] for row in sampled] == ["1q1a/videos__ok", "1q1a/videos__bad"]
|
||||
manifest = [
|
||||
json.loads(line)
|
||||
for line in (tmp_path / "out" / "official_eval_manifest.jsonl").read_text().splitlines()
|
||||
if line.strip()
|
||||
]
|
||||
assert len(manifest) == 1
|
||||
assert manifest[0]["sample_id"].startswith("1q1a__")
|
||||
|
||||
|
||||
def test_artifacts_require_complete_audio_and_transcript_response(tmp_path: Path):
|
||||
|
||||
@@ -0,0 +1,820 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import asdict
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.benchmarks.data_modules.omniinteract_dataset import (
|
||||
OmniInteractCase,
|
||||
OmniInteractEvaluationOptions,
|
||||
)
|
||||
from vllm_omni.benchmarks.omniinteract import OmniInteractCaseResult
|
||||
from vllm_omni.benchmarks.omniinteract_eval import (
|
||||
AlignedWord,
|
||||
TranscriptChunk,
|
||||
_summarize,
|
||||
build_slots,
|
||||
evaluate_batch,
|
||||
evaluate_case,
|
||||
evaluation_inputs_fingerprint,
|
||||
match_slots,
|
||||
)
|
||||
from vllm_omni.benchmarks.omniinteract_judge import (
|
||||
CoreJudgment,
|
||||
EarlyJudgment,
|
||||
OmniInteractJudge,
|
||||
PartialJudgment,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.benchmark]
|
||||
|
||||
|
||||
class _FixedJudge:
|
||||
def judge_early(
|
||||
self,
|
||||
slot: dict[str, object],
|
||||
full_context: str,
|
||||
actual_text: str,
|
||||
) -> EarlyJudgment:
|
||||
del slot, full_context, actual_text
|
||||
return EarlyJudgment("neutral", 1.0, "ok", "{}", "llm_json")
|
||||
|
||||
def judge_core(
|
||||
self,
|
||||
slot: dict[str, object],
|
||||
full_context: str,
|
||||
actual_text: str,
|
||||
future_answers: str,
|
||||
) -> CoreJudgment:
|
||||
del slot, full_context, actual_text, future_answers
|
||||
return CoreJudgment(1.0, "answer", False, "ok", "{}", "llm_json")
|
||||
|
||||
def judge_interrupted_partial(
|
||||
self,
|
||||
slot: dict[str, object],
|
||||
actual_text: str,
|
||||
) -> PartialJudgment:
|
||||
del slot, actual_text
|
||||
return PartialJudgment(1.0, False, "ok", "{}", "llm_json")
|
||||
|
||||
|
||||
class _GeneratedJudge(OmniInteractJudge):
|
||||
def __init__(self, responses: list[str]) -> None:
|
||||
super().__init__("http://judge", "judge-model")
|
||||
self.responses = iter(responses)
|
||||
|
||||
def _generate(self, system_prompt: str, user_prompt: str) -> str:
|
||||
del system_prompt, user_prompt
|
||||
return next(self.responses)
|
||||
|
||||
|
||||
def test_build_slots_and_split_word_aligned_chunk() -> None:
|
||||
slots = build_slots(
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 2.0,
|
||||
"question_text": "question",
|
||||
"answer_text": "answer",
|
||||
"question_type": "realtime",
|
||||
},
|
||||
{
|
||||
"question_time": 5.0,
|
||||
"answer_time": 6.0,
|
||||
"question_text": "next",
|
||||
"answer_text": "next answer",
|
||||
"question_type": "proactive",
|
||||
},
|
||||
],
|
||||
"multi_turn",
|
||||
)
|
||||
chunk = TranscriptChunk(
|
||||
source_id=0,
|
||||
text="okay answer",
|
||||
start=0.5,
|
||||
end=2.5,
|
||||
aligned_words=(
|
||||
AlignedWord("okay", 0.5, 0.9),
|
||||
AlignedWord("answer", 2.1, 2.5),
|
||||
),
|
||||
)
|
||||
|
||||
matched, unmatched = match_slots(slots, [chunk])
|
||||
|
||||
assert not unmatched
|
||||
assert matched[0].early_chunks[0].text == "okay"
|
||||
assert matched[0].core_chunks[0].text == "answer"
|
||||
assert matched[0].core_chunks[0].start == pytest.approx(2.1)
|
||||
|
||||
|
||||
def test_judge_parses_json_wrapped_in_model_text() -> None:
|
||||
judge = _GeneratedJudge(
|
||||
[
|
||||
'result: {"flag":"FP_Hallucination","score":1,"rationale":"early"}',
|
||||
'```json\n{"score":0.8,"trigger_phrase":"answer","spoiler":false,"rationale":"good"}\n```',
|
||||
'{"score":0.7,"hallucination":false,"rationale":"partial"}',
|
||||
]
|
||||
)
|
||||
slot = {"question_text": "q", "gt_answer": "answer"}
|
||||
|
||||
early = judge.judge_early(slot, "context", "guess")
|
||||
core = judge.judge_core(slot, "context", "answer", "(none)")
|
||||
partial = judge.judge_interrupted_partial(slot, "answer")
|
||||
|
||||
assert early.category == "hallucination"
|
||||
assert early.score == 0.0
|
||||
assert core.score == pytest.approx(0.8)
|
||||
assert core.trigger_phrase == "answer"
|
||||
assert partial.score == pytest.approx(0.7)
|
||||
|
||||
|
||||
def test_evaluate_case_persists_accuracy_artifact(tmp_path: Path) -> None:
|
||||
annotation = tmp_path / "annotation.json"
|
||||
annotation.write_text(
|
||||
json.dumps(
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 1.0,
|
||||
"question_text": "question",
|
||||
"answer_text": "answer",
|
||||
"question_type": "realtime",
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
output_dir = tmp_path / "case-output"
|
||||
output_dir.mkdir()
|
||||
(output_dir / "wav_transcript.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"chunks": [
|
||||
{
|
||||
"timestamp": [1.0, 1.5],
|
||||
"text": "answer",
|
||||
"aligned_words": [{"text": "answer", "start": 1.0, "end": 1.5}],
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
)
|
||||
video = tmp_path / "video.mp4"
|
||||
video.touch()
|
||||
case = OmniInteractCase("1q1a", "video.mp4", video, annotation, "multi_turn")
|
||||
result = OmniInteractCaseResult(
|
||||
subset="1q1a",
|
||||
video=str(video),
|
||||
output_dir=str(output_dir),
|
||||
success=True,
|
||||
eligible_for_official_eval=True,
|
||||
)
|
||||
artifact = tmp_path / "evaluation.json"
|
||||
|
||||
evaluation = evaluate_case(case, result, _FixedJudge(), artifact)
|
||||
|
||||
assert evaluation["timing_precision"] == "word-aligned"
|
||||
assert evaluation["summary"]["IA_QTF1"] == pytest.approx(1.0)
|
||||
paper = evaluation["summary"]["paper_metrics"]["exp_f1"]
|
||||
assert paper["all_global"]["IA_QTF1"] == pytest.approx(1.0)
|
||||
assert paper["realtime"]["IA_QTF1"] == pytest.approx(1.0)
|
||||
assert json.loads(artifact.read_text())["status"] == "ok"
|
||||
fingerprint = evaluation["inputs_fingerprint"]
|
||||
assert fingerprint["annotation_sha256"]
|
||||
assert fingerprint["transcript_sha256"]
|
||||
assert fingerprint["protocol_source"]
|
||||
|
||||
|
||||
def _realtime_eval_case(tmp_path: Path, *, transcript_text: str) -> tuple[OmniInteractCase, OmniInteractCaseResult]:
|
||||
annotation = tmp_path / "annotation.json"
|
||||
annotation.write_text(
|
||||
json.dumps(
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 1.0,
|
||||
"question_text": "question",
|
||||
"answer_text": "answer",
|
||||
"question_type": "realtime",
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
output_dir = tmp_path / "case-output"
|
||||
output_dir.mkdir(exist_ok=True)
|
||||
chunks: list[dict[str, object]] = []
|
||||
if transcript_text:
|
||||
chunks.append({"timestamp": [1.0, 1.5], "text": transcript_text})
|
||||
(output_dir / "wav_transcript.json").write_text(json.dumps({"chunks": chunks}))
|
||||
video = tmp_path / "video.mp4"
|
||||
video.touch()
|
||||
case = OmniInteractCase("1q1a", "video.mp4", video, annotation, "multi_turn")
|
||||
result = OmniInteractCaseResult(
|
||||
subset="1q1a",
|
||||
video=str(video),
|
||||
output_dir=str(output_dir),
|
||||
success=True,
|
||||
eligible_for_official_eval=True,
|
||||
)
|
||||
return case, result
|
||||
|
||||
|
||||
def _eval_options(tmp_path: Path, *, skip_existing: bool) -> OmniInteractEvaluationOptions:
|
||||
return OmniInteractEvaluationOptions(
|
||||
judge_base_url="http://127.0.0.1:9",
|
||||
judge_model="cached-judge",
|
||||
judge_api_key="EMPTY",
|
||||
judge_timeout_s=60.0,
|
||||
judge_max_tokens=32,
|
||||
workers=1,
|
||||
output_dir=tmp_path / "evaluation",
|
||||
skip_existing=skip_existing,
|
||||
)
|
||||
|
||||
|
||||
class _ConfiguredFixedJudge(_FixedJudge):
|
||||
def __init__(
|
||||
self,
|
||||
base_url: str,
|
||||
model: str,
|
||||
*,
|
||||
api_key: str = "EMPTY",
|
||||
timeout_s: float = 60.0,
|
||||
max_tokens: int = 512,
|
||||
) -> None:
|
||||
del api_key, timeout_s
|
||||
self.base_url = base_url
|
||||
self.model = model
|
||||
self.max_tokens = max_tokens
|
||||
|
||||
|
||||
def test_skip_existing_reuses_matching_fingerprint(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import vllm_omni.benchmarks.omniinteract_eval as eval_mod
|
||||
|
||||
case, result = _realtime_eval_case(tmp_path, transcript_text="answer")
|
||||
options = _eval_options(tmp_path, skip_existing=False)
|
||||
monkeypatch.setattr(eval_mod, "OmniInteractJudge", _ConfiguredFixedJudge)
|
||||
first = evaluate_batch([case], [result], options)
|
||||
assert first["summary"]["IA_QTF1"] == pytest.approx(1.0)
|
||||
|
||||
calls: list[str] = []
|
||||
|
||||
def _forbidden(
|
||||
case: OmniInteractCase,
|
||||
result: OmniInteractCaseResult,
|
||||
judge: object,
|
||||
output_path: Path,
|
||||
config: object = None,
|
||||
inputs_fingerprint: object = None,
|
||||
) -> dict[str, object]:
|
||||
del case, result, judge, output_path, config, inputs_fingerprint
|
||||
calls.append("evaluate_case")
|
||||
raise AssertionError("matching fingerprint must reuse the cached evaluation")
|
||||
|
||||
monkeypatch.setattr(eval_mod, "evaluate_case", _forbidden)
|
||||
reused = evaluate_batch([case], [result], _eval_options(tmp_path, skip_existing=True))
|
||||
assert calls == []
|
||||
assert reused["summary"]["IA_QTF1"] == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_skip_existing_rejects_stale_transcript(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import vllm_omni.benchmarks.omniinteract_eval as eval_mod
|
||||
|
||||
case, result = _realtime_eval_case(tmp_path, transcript_text="answer")
|
||||
options = _eval_options(tmp_path, skip_existing=True)
|
||||
fingerprint = evaluation_inputs_fingerprint(
|
||||
annotation_path=case.annotation_path,
|
||||
transcript_path=Path(result.output_dir) / "wav_transcript.json",
|
||||
judge_model=options.judge_model,
|
||||
judge_base_url=options.judge_base_url,
|
||||
judge_max_tokens=options.judge_max_tokens,
|
||||
)
|
||||
sample_id = f"{case.subset}__{Path(result.output_dir).name}"
|
||||
cache_path = options.output_dir / f"{sample_id}.unified_eval.json"
|
||||
cache_path.parent.mkdir(parents=True)
|
||||
cache_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "ok",
|
||||
"sample_id": sample_id,
|
||||
"inputs_fingerprint": asdict(fingerprint),
|
||||
"summary": {
|
||||
"IA_QTF1": 1.0,
|
||||
"num_slots": 1,
|
||||
"num_unmatched_chunks": 0,
|
||||
"Global_TP": 1,
|
||||
"Global_FP": 0,
|
||||
"Global_FN": 0,
|
||||
},
|
||||
"slots": [],
|
||||
}
|
||||
)
|
||||
)
|
||||
(Path(result.output_dir) / "wav_transcript.json").write_text(json.dumps({"chunks": []}))
|
||||
monkeypatch.setattr(eval_mod, "OmniInteractJudge", _ConfiguredFixedJudge)
|
||||
fresh = evaluate_batch([case], [result], options)
|
||||
assert fresh["summary"]["IA_QTF1"] == pytest.approx(0.0)
|
||||
|
||||
|
||||
class _MissingCoreScoreJudge(_ConfiguredFixedJudge):
|
||||
def judge_core(
|
||||
self,
|
||||
slot: dict[str, object],
|
||||
full_context: str,
|
||||
actual_text: str,
|
||||
future_answers: str,
|
||||
) -> CoreJudgment:
|
||||
del slot, full_context, actual_text, future_answers
|
||||
return CoreJudgment(0.0, "", False, "Could not evaluate", "{}", "llm_parse_failed")
|
||||
|
||||
|
||||
def test_evaluate_batch_reports_missing_score_as_parse_failure(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import vllm_omni.benchmarks.omniinteract_eval as eval_mod
|
||||
|
||||
case, result = _realtime_eval_case(tmp_path, transcript_text="answer")
|
||||
options = _eval_options(tmp_path, skip_existing=False)
|
||||
monkeypatch.setattr(eval_mod, "OmniInteractJudge", _MissingCoreScoreJudge)
|
||||
evaluation = evaluate_batch([case], [result], options)
|
||||
assert evaluation["status"] == "failed"
|
||||
assert evaluation["evaluated"] == 0
|
||||
assert evaluation["failed"] == 1
|
||||
sample_id = f"{case.subset}__{Path(result.output_dir).name}"
|
||||
cached = json.loads((options.output_dir / f"{sample_id}.unified_eval.json").read_text())
|
||||
assert cached["status"] == "parse_failed"
|
||||
|
||||
|
||||
class _CoreRationaleNumberJudge(OmniInteractJudge):
|
||||
def __init__(
|
||||
self,
|
||||
base_url: str,
|
||||
model: str,
|
||||
*,
|
||||
api_key: str = "EMPTY",
|
||||
timeout_s: float = 60.0,
|
||||
max_tokens: int = 512,
|
||||
) -> None:
|
||||
super().__init__(base_url, model, api_key=api_key, timeout_s=timeout_s, max_tokens=max_tokens)
|
||||
|
||||
def _generate(self, system_prompt: str, user_prompt: str) -> str:
|
||||
del system_prompt, user_prompt
|
||||
return '{"rationale":"Cannot score: 1 required reference is missing."}'
|
||||
|
||||
|
||||
def test_evaluate_batch_rejects_core_rationale_number_as_parse_failure(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
import vllm_omni.benchmarks.omniinteract_eval as eval_mod
|
||||
|
||||
case, result = _realtime_eval_case(tmp_path, transcript_text="answer")
|
||||
options = _eval_options(tmp_path, skip_existing=False)
|
||||
monkeypatch.setattr(eval_mod, "OmniInteractJudge", _CoreRationaleNumberJudge)
|
||||
evaluation = evaluate_batch([case], [result], options)
|
||||
assert evaluation["status"] == "failed"
|
||||
assert evaluation["evaluated"] == 0
|
||||
assert evaluation["failed"] == 1
|
||||
sample_id = f"{case.subset}__{Path(result.output_dir).name}"
|
||||
cached = json.loads((options.output_dir / f"{sample_id}.unified_eval.json").read_text())
|
||||
assert cached["status"] == "parse_failed"
|
||||
assert cached["slots"][0]["stage_core"]["parse_source"] == "llm_parse_failed"
|
||||
assert cached["slots"][0]["stage_core"]["S_core"] == 0.0
|
||||
|
||||
|
||||
def test_skip_existing_rejects_parse_failed_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import vllm_omni.benchmarks.omniinteract_eval as eval_mod
|
||||
|
||||
case, result = _realtime_eval_case(tmp_path, transcript_text="answer")
|
||||
options = _eval_options(tmp_path, skip_existing=True)
|
||||
fingerprint = evaluation_inputs_fingerprint(
|
||||
annotation_path=case.annotation_path,
|
||||
transcript_path=Path(result.output_dir) / "wav_transcript.json",
|
||||
judge_model=options.judge_model,
|
||||
judge_base_url=options.judge_base_url,
|
||||
judge_max_tokens=options.judge_max_tokens,
|
||||
)
|
||||
sample_id = f"{case.subset}__{Path(result.output_dir).name}"
|
||||
cache_path = options.output_dir / f"{sample_id}.unified_eval.json"
|
||||
cache_path.parent.mkdir(parents=True)
|
||||
cache_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "parse_failed",
|
||||
"sample_id": sample_id,
|
||||
"inputs_fingerprint": asdict(fingerprint),
|
||||
"summary": {
|
||||
"IA_QTF1": 0.0,
|
||||
"num_slots": 1,
|
||||
"num_unmatched_chunks": 0,
|
||||
"Global_TP": 0,
|
||||
"Global_FP": 0,
|
||||
"Global_FN": 1,
|
||||
},
|
||||
"slots": [
|
||||
{
|
||||
"stage_core": {"parse_source": "llm_parse_failed", "S_core": 0.0},
|
||||
"TP_n": 0.0,
|
||||
"FP_delta": 0,
|
||||
"FN_delta": 1,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
)
|
||||
monkeypatch.setattr(eval_mod, "OmniInteractJudge", _ConfiguredFixedJudge)
|
||||
fresh = evaluate_batch([case], [result], options)
|
||||
assert fresh["evaluated"] == 1
|
||||
assert fresh["failed"] == 0
|
||||
assert fresh["summary"]["IA_QTF1"] == pytest.approx(1.0)
|
||||
assert json.loads(cache_path.read_text())["status"] == "ok"
|
||||
|
||||
|
||||
def _slot_row(
|
||||
*,
|
||||
scene_type: str,
|
||||
question_type: str,
|
||||
tp_n: float,
|
||||
fp: int = 0,
|
||||
fn: int = 0,
|
||||
nested_role: str | None = None,
|
||||
nested_group_id: int | None = None,
|
||||
sample_id: str = "s",
|
||||
tp_core: float | None = None,
|
||||
answer_start: float | None = 1.0,
|
||||
) -> dict[str, object]:
|
||||
core_tp = tp_n if tp_core is None else tp_core
|
||||
return {
|
||||
"sample_id": sample_id,
|
||||
"scene_type": scene_type,
|
||||
"question_type": question_type,
|
||||
"nested_role": nested_role,
|
||||
"nested_group_id": nested_group_id,
|
||||
"TP_n": tp_n,
|
||||
"TP_core": core_tp,
|
||||
"FP_delta": fp,
|
||||
"FN_delta": fn,
|
||||
"is_interrupted": False,
|
||||
"stage_core": {"answer_start": answer_start},
|
||||
}
|
||||
|
||||
|
||||
def test_paper_metrics_exclude_nested_from_realtime_and_proactive() -> None:
|
||||
summary = _summarize(
|
||||
[
|
||||
_slot_row(scene_type="multi_turn", question_type="realtime", tp_n=1.0),
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="realtime",
|
||||
tp_n=1.0,
|
||||
nested_role="inner",
|
||||
nested_group_id=1,
|
||||
answer_start=0.5,
|
||||
),
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="proactive",
|
||||
tp_n=1.0,
|
||||
nested_role="outer",
|
||||
nested_group_id=1,
|
||||
answer_start=1.5,
|
||||
),
|
||||
_slot_row(scene_type="multi_turn", question_type="proactive", tp_n=1.0),
|
||||
_slot_row(scene_type="1QnA", question_type="step", tp_n=1.0, fn=0),
|
||||
],
|
||||
unmatched=0,
|
||||
)
|
||||
paper = summary["paper_metrics"]["exp_f1"]
|
||||
|
||||
assert paper["realtime"]["num_slots"] == 1
|
||||
assert paper["proactive"]["num_slots"] == 1
|
||||
assert paper["nested"]["num_slots"] == 2
|
||||
assert paper["one_q1a_global"]["num_slots"] == 4
|
||||
assert paper["one_qna"]["num_slots"] == 1
|
||||
assert paper["all_global"]["num_slots"] == 5
|
||||
# All Global includes 1QnA; 1Q1A Global does not.
|
||||
assert paper["all_global"]["Global_TP"] == pytest.approx(5.0)
|
||||
assert paper["one_q1a_global"]["Global_TP"] == pytest.approx(4.0)
|
||||
assert summary["nested"]["NCCS"] == pytest.approx(1.0)
|
||||
assert summary["nested"]["missing_q1_count"] == 0
|
||||
assert summary["paper_metrics"]["exp_nested"]["missed_outer"] == 0
|
||||
assert summary["paper_metrics"]["exp_nested"]["inner_IA_QTF1"] == pytest.approx(1.0)
|
||||
assert summary["paper_metrics"]["exp_nested"]["outer_IA_QTF1"] == pytest.approx(1.0)
|
||||
assert summary["scenario_case_counts"]["realtime"] == 1
|
||||
assert summary["scenario_case_counts"]["proactive"] == 1
|
||||
assert summary["scenario_case_counts"]["nested"] == 1
|
||||
assert summary["scenario_case_counts"]["1qna"] == 1
|
||||
|
||||
|
||||
def test_nccs_allows_missing_answer_start() -> None:
|
||||
summary = _summarize(
|
||||
[
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="realtime",
|
||||
tp_n=0.8,
|
||||
tp_core=0.8,
|
||||
nested_role="inner",
|
||||
nested_group_id=1,
|
||||
answer_start=None,
|
||||
),
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="proactive",
|
||||
tp_n=0.8,
|
||||
tp_core=0.8,
|
||||
nested_role="outer",
|
||||
nested_group_id=1,
|
||||
answer_start=None,
|
||||
),
|
||||
],
|
||||
unmatched=0,
|
||||
)
|
||||
assert summary["nested"]["success_pairs"] == 1
|
||||
assert summary["nested"]["NCCS"] == pytest.approx(0.8)
|
||||
|
||||
|
||||
def test_missed_outer_counts_zero_outer_core() -> None:
|
||||
summary = _summarize(
|
||||
[
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="realtime",
|
||||
tp_n=1.0,
|
||||
tp_core=1.0,
|
||||
nested_role="inner",
|
||||
nested_group_id=1,
|
||||
answer_start=0.5,
|
||||
),
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="proactive",
|
||||
tp_n=0.0,
|
||||
tp_core=0.0,
|
||||
fn=1,
|
||||
nested_role="outer",
|
||||
nested_group_id=1,
|
||||
answer_start=1.5,
|
||||
),
|
||||
],
|
||||
unmatched=0,
|
||||
)
|
||||
nested = summary["paper_metrics"]["exp_nested"]
|
||||
assert nested["missed_outer"] == 1
|
||||
assert nested["NCCS"] == pytest.approx(0.0)
|
||||
assert nested["inner_IA_QTF1"] == pytest.approx(1.0)
|
||||
assert nested["outer_IA_QTF1"] == pytest.approx(0.0)
|
||||
|
||||
|
||||
def test_cross_boundary_core_sets_effective_start_hint() -> None:
|
||||
slots = build_slots(
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 2.0,
|
||||
"question_text": "question",
|
||||
"answer_text": "answer",
|
||||
"question_type": "realtime",
|
||||
}
|
||||
],
|
||||
"multi_turn",
|
||||
)
|
||||
chunk = TranscriptChunk(
|
||||
source_id=0,
|
||||
text="okay answer",
|
||||
start=0.5,
|
||||
end=2.5,
|
||||
aligned_words=(
|
||||
AlignedWord("okay", 0.5, 0.9),
|
||||
AlignedWord("answer", 2.1, 2.5),
|
||||
),
|
||||
)
|
||||
matched, unmatched = match_slots(slots, [chunk])
|
||||
assert not unmatched
|
||||
assert matched[0].core_chunks[0].effective_start_hint == pytest.approx(2.0)
|
||||
|
||||
|
||||
class _NonNeutralEarlyJudge(_FixedJudge):
|
||||
def judge_early(
|
||||
self,
|
||||
slot: dict[str, object],
|
||||
full_context: str,
|
||||
actual_text: str,
|
||||
) -> EarlyJudgment:
|
||||
del slot, full_context, actual_text
|
||||
return EarlyJudgment("other", 1.0, "ignored", "{}", "llm_json")
|
||||
|
||||
|
||||
def test_early_tp_ack_only_for_neutral(tmp_path: Path) -> None:
|
||||
annotation = tmp_path / "annotation.json"
|
||||
annotation.write_text(
|
||||
json.dumps(
|
||||
[
|
||||
{
|
||||
"question_time": 0.0,
|
||||
"answer_time": 2.0,
|
||||
"question_text": "question",
|
||||
"answer_text": "answer",
|
||||
"question_type": "realtime",
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
output_dir = tmp_path / "case-output"
|
||||
output_dir.mkdir()
|
||||
(output_dir / "wav_transcript.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"chunks": [
|
||||
{
|
||||
"timestamp": [0.5, 0.9],
|
||||
"text": "okay",
|
||||
"aligned_words": [{"text": "okay", "start": 0.5, "end": 0.9}],
|
||||
},
|
||||
{
|
||||
"timestamp": [2.1, 2.5],
|
||||
"text": "answer",
|
||||
"aligned_words": [{"text": "answer", "start": 2.1, "end": 2.5}],
|
||||
},
|
||||
]
|
||||
}
|
||||
)
|
||||
)
|
||||
video = tmp_path / "video.mp4"
|
||||
video.touch()
|
||||
case = OmniInteractCase("1q1a", "video.mp4", video, annotation, "multi_turn")
|
||||
result = OmniInteractCaseResult(
|
||||
subset="1q1a",
|
||||
video=str(video),
|
||||
output_dir=str(output_dir),
|
||||
success=True,
|
||||
eligible_for_official_eval=True,
|
||||
)
|
||||
evaluation = evaluate_case(case, result, _NonNeutralEarlyJudge(), tmp_path / "evaluation.json")
|
||||
assert evaluation["slots"][0]["TP_ack"] == 0.0
|
||||
assert evaluation["slots"][0]["stage_early"]["category"] == "other"
|
||||
|
||||
|
||||
def test_paper_metrics_unknown_inner_does_not_underflow_realtime() -> None:
|
||||
summary = _summarize(
|
||||
[
|
||||
_slot_row(scene_type="multi_turn", question_type="realtime", tp_n=0.5),
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="unknown",
|
||||
tp_n=2.0,
|
||||
nested_role="inner",
|
||||
nested_group_id=1,
|
||||
answer_start=0.5,
|
||||
),
|
||||
_slot_row(
|
||||
scene_type="nested",
|
||||
question_type="proactive",
|
||||
tp_n=1.0,
|
||||
nested_role="outer",
|
||||
nested_group_id=1,
|
||||
answer_start=1.5,
|
||||
),
|
||||
],
|
||||
unmatched=0,
|
||||
)
|
||||
paper = summary["paper_metrics"]["exp_f1"]
|
||||
assert paper["realtime"]["Global_TP"] == pytest.approx(0.5)
|
||||
assert paper["realtime"]["num_slots"] == 1
|
||||
assert paper["realtime"]["Precision"] >= 0.0
|
||||
assert paper["one_q1a_global"]["Global_TP"] == pytest.approx(3.5)
|
||||
|
||||
|
||||
def test_core_score_float_ignores_leading_counts() -> None:
|
||||
from vllm_omni.benchmarks.omniinteract_judge import _score_float_from_text
|
||||
|
||||
assert _score_float_from_text("The answer covers 3 of the 5 key points, score: 0.6") == pytest.approx(0.6)
|
||||
assert _score_float_from_text("score: 3") is None
|
||||
assert _score_float_from_text("no score here 0.9") is None
|
||||
|
||||
judge = _GeneratedJudge(["The answer covers 3 of the 5 key points, score: 0.6"])
|
||||
core = judge.judge_core({"question_text": "q", "gt_answer": "a"}, "ctx", "answer", "(none)")
|
||||
assert core.score == pytest.approx(0.6)
|
||||
assert core.parse_source == "llm_float_text"
|
||||
|
||||
|
||||
def test_core_missing_json_score_does_not_use_rationale_number() -> None:
|
||||
raw = '{"rationale":"Cannot score: 1 required reference is missing."}'
|
||||
core = _GeneratedJudge([raw]).judge_core({"question_text": "q", "gt_answer": "a"}, "ctx", "answer", "(none)")
|
||||
assert core.score == 0.0
|
||||
assert core.parse_source == "llm_parse_failed"
|
||||
|
||||
|
||||
def test_early_missing_score_and_unparsed_flag() -> None:
|
||||
missing_score = _GeneratedJudge(['{"flag":"Neutral","rationale":"ok"}'])
|
||||
early = missing_score.judge_early({"question_text": "q", "gt_answer": "a"}, "ctx", "hi")
|
||||
assert early.category == "unparsed"
|
||||
assert early.score == 0.0
|
||||
assert early.parse_source == "llm_parse_failed"
|
||||
|
||||
garbage = _GeneratedJudge(["not json and not a known flag"])
|
||||
unparsed = garbage.judge_early({"question_text": "q", "gt_answer": "a"}, "ctx", "hi")
|
||||
assert unparsed.category == "unparsed"
|
||||
assert unparsed.score == 0.0
|
||||
assert unparsed.parse_source == "llm_parse_failed"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("path", "response"),
|
||||
[
|
||||
("early", '{"flag":"Neutral","rationale":"Could not evaluate this answer"}'),
|
||||
("early", '{"flag":"Neutral","score":"invalid","rationale":"bad"}'),
|
||||
("core", '{"rationale":"Could not evaluate this answer"}'),
|
||||
("core", '{"rationale":"Cannot score: 1 required reference is missing."}'),
|
||||
("core", '{"score":"invalid","trigger_phrase":"","spoiler":false,"rationale":"bad"}'),
|
||||
("partial", '{"rationale":"Could not evaluate this answer"}'),
|
||||
("partial", '{"score":"invalid","hallucination":false,"rationale":"bad"}'),
|
||||
],
|
||||
)
|
||||
def test_missing_or_invalid_json_scores_are_parse_failures(path: str, response: str) -> None:
|
||||
slot = {"question_text": "q", "gt_answer": "a"}
|
||||
judge = _GeneratedJudge([response])
|
||||
if path == "early":
|
||||
judgment = judge.judge_early(slot, "ctx", "hi")
|
||||
elif path == "core":
|
||||
judgment = judge.judge_core(slot, "ctx", "answer", "(none)")
|
||||
else:
|
||||
judgment = judge.judge_interrupted_partial(slot, "answer")
|
||||
assert judgment.score == 0.0
|
||||
assert judgment.parse_source == "llm_parse_failed"
|
||||
|
||||
|
||||
def test_explicit_zero_json_score_is_valid_llm_json() -> None:
|
||||
slot = {"question_text": "q", "gt_answer": "a"}
|
||||
early = _GeneratedJudge(['{"flag":"Neutral","score":0,"rationale":"zero"}']).judge_early(slot, "ctx", "hi")
|
||||
core = _GeneratedJudge(['{"score":0.0,"trigger_phrase":"","spoiler":false,"rationale":"zero"}']).judge_core(
|
||||
slot, "ctx", "answer", "(none)"
|
||||
)
|
||||
partial = _GeneratedJudge(['{"score":0,"hallucination":false,"rationale":"zero"}']).judge_interrupted_partial(
|
||||
slot, "answer"
|
||||
)
|
||||
assert early.category == "neutral"
|
||||
assert early.score == 0.0
|
||||
assert early.parse_source == "llm_json"
|
||||
assert core.score == 0.0
|
||||
assert core.parse_source == "llm_json"
|
||||
assert partial.score == 0.0
|
||||
assert partial.parse_source == "llm_json"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("score_literal", ['"NaN"', '"Infinity"', '"-Infinity"', "NaN", "Infinity", "-Infinity"])
|
||||
def test_nonfinite_json_scores_are_parse_failures(score_literal: str) -> None:
|
||||
slot = {"question_text": "q", "gt_answer": "a"}
|
||||
early = _GeneratedJudge([f'{{"flag":"Neutral","score":{score_literal},"rationale":"bad"}}']).judge_early(
|
||||
slot, "ctx", "hi"
|
||||
)
|
||||
core = _GeneratedJudge(
|
||||
[f'{{"score":{score_literal},"trigger_phrase":"answer","spoiler":false,"rationale":"bad"}}']
|
||||
).judge_core(slot, "ctx", "answer", "(none)")
|
||||
partial = _GeneratedJudge(
|
||||
[f'{{"score":{score_literal},"hallucination":false,"rationale":"bad"}}']
|
||||
).judge_interrupted_partial(slot, "answer")
|
||||
|
||||
assert early.score == 0.0
|
||||
assert early.parse_source == "llm_parse_failed"
|
||||
assert core.score == 0.0
|
||||
assert core.parse_source == "llm_parse_failed"
|
||||
assert core.trigger_phrase == ""
|
||||
assert partial.score == 0.0
|
||||
assert partial.parse_source == "llm_parse_failed"
|
||||
|
||||
|
||||
def test_fingerprint_requires_evaluator_schema_version() -> None:
|
||||
from vllm_omni.benchmarks.omniinteract_eval import EvaluationInputsFingerprint
|
||||
|
||||
payload = {
|
||||
"annotation_sha256": "a" * 64,
|
||||
"transcript_sha256": "b" * 64,
|
||||
"judge_model": "m",
|
||||
"judge_base_url": "http://127.0.0.1:9",
|
||||
"judge_max_tokens": 32,
|
||||
"protocol_source": "proto",
|
||||
}
|
||||
assert EvaluationInputsFingerprint.from_mapping(payload) is None
|
||||
payload["evaluator_schema_version"] = 1
|
||||
assert EvaluationInputsFingerprint.from_mapping(payload) is not None
|
||||
payload["evaluator_schema_version"] = 999
|
||||
matched = EvaluationInputsFingerprint.from_mapping(payload)
|
||||
assert matched is not None
|
||||
assert matched.evaluator_schema_version == 999
|
||||
|
||||
|
||||
def test_summarize_counts_parse_sources() -> None:
|
||||
rows = [
|
||||
{
|
||||
**_slot_row(scene_type="multi_turn", question_type="realtime", tp_n=1.0),
|
||||
"stage_early": {"parse_source": "llm_json"},
|
||||
"stage_core": {"parse_source": "llm_parse_failed", "trigger_fallback": True},
|
||||
}
|
||||
]
|
||||
summary = _summarize(rows, unmatched=0)
|
||||
assert summary["judge_parse"]["llm_json"] == 1
|
||||
assert summary["judge_parse"]["llm_parse_failed"] == 1
|
||||
assert summary["judge_parse"]["judge_calls"] == 2
|
||||
assert summary["trigger_fallback_slots"] == 1
|
||||
@@ -224,6 +224,53 @@ def test_preprocess_serve_args_applies_safe_omniinteract_prompt_default(
|
||||
assert args.num_prompts == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("extra", "match"),
|
||||
[
|
||||
(["--seed", "7"], "cannot be combined with --seed"),
|
||||
(["--dataset-path", "/tmp/omniinteract-data"], "cannot be combined with --dataset-path"),
|
||||
(["--omniinteract-scenario-tags", "realtime"], "cannot be combined with --omniinteract-scenario-tags"),
|
||||
(["--omniinteract-scenario-focus"], "cannot be combined with --omniinteract-scenario-focus"),
|
||||
],
|
||||
)
|
||||
def test_preprocess_serve_args_rejects_omniinteract_video_list_conflicts(
|
||||
tmp_path: Path,
|
||||
extra: list[str],
|
||||
match: str,
|
||||
) -> None:
|
||||
ref = tmp_path / "ref.wav"
|
||||
ref.touch()
|
||||
video_list = tmp_path / "list.jsonl"
|
||||
video_list.write_text("{}\n")
|
||||
parser = TrackingArgumentParser()
|
||||
parser.add_argument("--dataset-name", default="sharegpt")
|
||||
parser.add_argument("--backend", default="vllm")
|
||||
parser.add_argument("--endpoint", default="/v1/completions")
|
||||
parser.add_argument("--model", default="dummy")
|
||||
parser.add_argument("--seed", type=int, default=0)
|
||||
parser.add_argument("--dataset-path", default=None)
|
||||
parser.add_argument("--num-prompts", type=int, default=1000)
|
||||
parser.add_argument("--max-concurrency", type=int, default=None)
|
||||
add_omni_args(parser)
|
||||
args = parser.parse_args(
|
||||
[
|
||||
"--dataset-name",
|
||||
"omniinteract",
|
||||
"--backend",
|
||||
"openai-realtime-duplex",
|
||||
"--endpoint",
|
||||
"/v1/realtime",
|
||||
"--omniinteract-ref-audio",
|
||||
str(ref),
|
||||
"--omniinteract-video-list",
|
||||
str(video_list),
|
||||
*extra,
|
||||
]
|
||||
)
|
||||
with pytest.raises(ValueError, match=match):
|
||||
preprocess_serve_args(args)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("argv", "expected_extra_body", "expected_explicit"),
|
||||
[
|
||||
|
||||
@@ -100,6 +100,71 @@ class _SingleActiveContext:
|
||||
stack.close()
|
||||
|
||||
|
||||
def _config_for_test(test_name: str) -> dict[str, object] | None:
|
||||
for config in BENCHMARK_CONFIGS:
|
||||
if isinstance(config, dict) and config.get("test_name") == test_name:
|
||||
return config
|
||||
return None
|
||||
|
||||
|
||||
def _judge_server_params_for_test(test_name: str) -> dict[str, object] | None:
|
||||
config = _config_for_test(test_name)
|
||||
if config is None:
|
||||
return None
|
||||
raw = config.get("judge_server_params")
|
||||
if raw is None:
|
||||
return None
|
||||
if not isinstance(raw, dict):
|
||||
raise TypeError(f"judge_server_params for {test_name} must be an object")
|
||||
return raw
|
||||
|
||||
|
||||
def _resolve_judge_cuda_visible_devices(configured: object) -> str:
|
||||
"""Map a judge card index onto the process-visible CUDA device list.
|
||||
|
||||
``judge_server_params.cuda_visible_devices`` is an index into
|
||||
``CUDA_VISIBLE_DEVICES`` when that env is set (``1`` with
|
||||
``CUDA_VISIBLE_DEVICES=2,3`` selects physical GPU 3). Without the env it
|
||||
is used as a raw device list.
|
||||
"""
|
||||
if not isinstance(configured, str) or not configured:
|
||||
raise ValueError("judge_server_params.cuda_visible_devices must be a non-empty string")
|
||||
parent = os.environ.get("CUDA_VISIBLE_DEVICES")
|
||||
if parent is None or not parent.strip():
|
||||
return configured
|
||||
visible = [part.strip() for part in parent.split(",") if part.strip()]
|
||||
if configured.isdigit():
|
||||
index = int(configured)
|
||||
if index < 0 or index >= len(visible):
|
||||
raise ValueError(
|
||||
f"judge_server_params.cuda_visible_devices={configured!r} is outside CUDA_VISIBLE_DEVICES={parent!r}"
|
||||
)
|
||||
return visible[index]
|
||||
return configured
|
||||
|
||||
|
||||
@contextmanager
|
||||
def _start_judge_server(judge_params: dict[str, object]):
|
||||
model = judge_params.get("model")
|
||||
if not isinstance(model, str) or not model:
|
||||
raise ValueError("judge_server_params.model must be a non-empty string")
|
||||
extra = judge_params.get("extra_cli_args") or ()
|
||||
if not isinstance(extra, list | tuple):
|
||||
raise TypeError("judge_server_params.extra_cli_args must be a list")
|
||||
visible = _resolve_judge_cuda_visible_devices(judge_params.get("cuda_visible_devices", "1"))
|
||||
print(f"Starting OmniInteract judge with model: {model} on CUDA_VISIBLE_DEVICES={visible}")
|
||||
with OmniServer(
|
||||
model,
|
||||
[str(item) for item in extra],
|
||||
use_omni=bool(judge_params.get("use_omni", False)),
|
||||
env_dict={"CUDA_VISIBLE_DEVICES": visible},
|
||||
) as judge:
|
||||
print(f"OmniInteract judge started on {judge.host}:{judge.port}")
|
||||
yield judge
|
||||
print("OmniInteract judge stopping...")
|
||||
print("OmniInteract judge stopped")
|
||||
|
||||
|
||||
# OmniServer defaults for flags not already present in JSON ``serve_args`` /
|
||||
# ``extra_cli_args``. Add new (flag, value) pairs here rather than special-casing.
|
||||
_OMNI_DEFAULT_SERVER_ARGS: tuple[tuple[str, str], ...] = (
|
||||
@@ -200,10 +265,17 @@ def _start_omni_server(server_param):
|
||||
server_args = ["--stage-overrides", stage_overrides] + server_args
|
||||
if extra:
|
||||
server_args = list(extra) + server_args
|
||||
judge_params = _judge_server_params_for_test(test_name)
|
||||
with OmniServer(model, server_args, use_omni=use_omni, env_dict=_omni_server_env()) as server:
|
||||
server.test_name = test_name
|
||||
server.judge_base_url = None
|
||||
print("OmniServer started successfully")
|
||||
yield server
|
||||
if judge_params is None:
|
||||
yield server
|
||||
else:
|
||||
with _start_judge_server(judge_params) as judge:
|
||||
server.judge_base_url = f"http://{judge.host}:{judge.port}"
|
||||
yield server
|
||||
print("OmniServer stopping...")
|
||||
|
||||
print("OmniServer stopped")
|
||||
@@ -260,6 +332,120 @@ def _resolve_num_warmups(params: dict[str, Any], *, default: int) -> int:
|
||||
return value
|
||||
|
||||
|
||||
def _is_finite_number(value: object) -> bool:
|
||||
return isinstance(value, int | float) and not isinstance(value, bool) and math.isfinite(value)
|
||||
|
||||
|
||||
_OMNIINTERACT_AGGREGATE_MIN_IA_QTF1 = "omniinteract_aggregate_min_ia_qtf1"
|
||||
_OMNIINTERACT_AGGREGATE_SUBSETS = "omniinteract_aggregate_subsets"
|
||||
_OMNIINTERACT_AGGREGATE_GROUP = "omniinteract_aggregate_group"
|
||||
_OMNIINTERACT_AGGREGATE_COUNTS: dict[tuple[str, str], tuple[float, float, float]] = {}
|
||||
_OMNIINTERACT_MIN_EVALUATED_CASES = 1
|
||||
|
||||
|
||||
def _reset_omniinteract_aggregate_counts() -> None:
|
||||
_OMNIINTERACT_AGGREGATE_COUNTS.clear()
|
||||
|
||||
|
||||
def _ia_qtf1_from_counts(tp: float, fp: float, fn: float) -> float:
|
||||
precision = tp / (tp + fp) if tp + fp > 0 else 0.0
|
||||
recall = tp / (tp + fn) if tp + fn > 0 else 0.0
|
||||
return (2.0 * precision * recall / (precision + recall)) if precision + recall > 0 else 0.0
|
||||
|
||||
|
||||
def _assert_subset_evaluated(accuracy: dict[str, object]) -> None:
|
||||
"""Reject a subset whose clipped or cancelled cases left nothing to score.
|
||||
|
||||
Individual ineligible cases may be skipped. A subset with fewer than
|
||||
``_OMNIINTERACT_MIN_EVALUATED_CASES`` evaluated cases must not pass, or its
|
||||
zero TP/FP/FN would be pooled as a successful accuracy result.
|
||||
"""
|
||||
|
||||
evaluated = accuracy.get("evaluated")
|
||||
if not isinstance(evaluated, int) or isinstance(evaluated, bool):
|
||||
raise AssertionError("OmniInteract accuracy evaluated count is missing")
|
||||
if evaluated < _OMNIINTERACT_MIN_EVALUATED_CASES:
|
||||
raise AssertionError(
|
||||
f"OmniInteract subset evaluated {evaluated} cases (skipped={accuracy.get('skipped')}); "
|
||||
f"at least {_OMNIINTERACT_MIN_EVALUATED_CASES} evaluated case is required"
|
||||
)
|
||||
|
||||
|
||||
def _finite_accuracy_count(value: object, name: str) -> float:
|
||||
assert _is_finite_number(value), f"OmniInteract accuracy summary {name} is missing"
|
||||
return float(value)
|
||||
|
||||
|
||||
def _aggregate_accuracy_params_for_test(test_name: str) -> dict[str, object]:
|
||||
config = _config_for_test(test_name)
|
||||
if config is None:
|
||||
return {}
|
||||
min_ia_qtf1 = config.get(_OMNIINTERACT_AGGREGATE_MIN_IA_QTF1)
|
||||
if min_ia_qtf1 is None:
|
||||
return {}
|
||||
if not _is_finite_number(min_ia_qtf1):
|
||||
raise ValueError("omniinteract_aggregate_min_ia_qtf1 must be a finite number")
|
||||
subsets: list[str] = []
|
||||
raw_params = config.get("benchmark_params") or []
|
||||
if not isinstance(raw_params, list):
|
||||
raise TypeError(f"benchmark_params for {test_name} must be a list")
|
||||
for item in raw_params:
|
||||
if not isinstance(item, dict) or not item.get("omniinteract_evaluate"):
|
||||
continue
|
||||
subset = item.get("omniinteract_subsets")
|
||||
if not isinstance(subset, str) or not subset:
|
||||
raise ValueError("omniinteract_aggregate_min_ia_qtf1 requires omniinteract_subsets on each evaluated case")
|
||||
subsets.append(subset)
|
||||
if not subsets:
|
||||
raise ValueError("omniinteract_aggregate_min_ia_qtf1 requires at least one evaluated OmniInteract subset")
|
||||
if len(set(subsets)) != len(subsets):
|
||||
raise ValueError("omniinteract_aggregate_subsets must not contain duplicates")
|
||||
return {
|
||||
_OMNIINTERACT_AGGREGATE_MIN_IA_QTF1: float(min_ia_qtf1),
|
||||
_OMNIINTERACT_AGGREGATE_SUBSETS: subsets,
|
||||
_OMNIINTERACT_AGGREGATE_GROUP: test_name,
|
||||
}
|
||||
|
||||
|
||||
def _maybe_assert_aggregate_ia_qtf1(params: dict[str, object], acc_summary: dict[str, object]) -> None:
|
||||
min_ia_qtf1 = params.get(_OMNIINTERACT_AGGREGATE_MIN_IA_QTF1)
|
||||
if min_ia_qtf1 is None:
|
||||
return
|
||||
assert _is_finite_number(min_ia_qtf1), "omniinteract_aggregate_min_ia_qtf1 must be a finite number"
|
||||
subsets = params.get(_OMNIINTERACT_AGGREGATE_SUBSETS)
|
||||
if not isinstance(subsets, list | tuple) or not subsets:
|
||||
raise ValueError("omniinteract_aggregate_min_ia_qtf1 requires omniinteract_aggregate_subsets")
|
||||
if len(set(subsets)) != len(subsets):
|
||||
raise ValueError("omniinteract_aggregate_subsets must not contain duplicates")
|
||||
if not all(isinstance(item, str) and item for item in subsets):
|
||||
raise ValueError("omniinteract_aggregate_subsets must be non-empty strings")
|
||||
subset = params.get("omniinteract_subsets")
|
||||
if not isinstance(subset, str) or not subset:
|
||||
raise ValueError("omniinteract_aggregate_min_ia_qtf1 requires omniinteract_subsets")
|
||||
if subset not in subsets:
|
||||
raise ValueError(f"omniinteract_subsets {subset!r} is not in omniinteract_aggregate_subsets")
|
||||
group = params.get(_OMNIINTERACT_AGGREGATE_GROUP)
|
||||
if not isinstance(group, str) or not group:
|
||||
raise ValueError("omniinteract_aggregate_min_ia_qtf1 requires omniinteract_aggregate_group")
|
||||
tp = _finite_accuracy_count(acc_summary.get("Global_TP"), "Global_TP")
|
||||
fp = _finite_accuracy_count(acc_summary.get("Global_FP"), "Global_FP")
|
||||
fn = _finite_accuracy_count(acc_summary.get("Global_FN"), "Global_FN")
|
||||
_OMNIINTERACT_AGGREGATE_COUNTS[(group, subset)] = (tp, fp, fn)
|
||||
recorded = [_OMNIINTERACT_AGGREGATE_COUNTS.get((group, name)) for name in subsets]
|
||||
present = [counts for counts in recorded if counts is not None]
|
||||
if len(present) != len(subsets):
|
||||
return
|
||||
total_tp = sum(counts[0] for counts in present)
|
||||
total_fp = sum(counts[1] for counts in present)
|
||||
total_fn = sum(counts[2] for counts in present)
|
||||
ia_qtf1 = _ia_qtf1_from_counts(total_tp, total_fp, total_fn)
|
||||
print(
|
||||
f"OmniInteract aggregate All Global IA-QTF1: {ia_qtf1:.6f} "
|
||||
f"(TP={total_tp:.6f} / FP={total_fp:.6f} / FN={total_fn:.6f})"
|
||||
)
|
||||
assert ia_qtf1 >= float(min_ia_qtf1), f"OmniInteract aggregate All Global IA-QTF1 {ia_qtf1} is below {min_ia_qtf1}"
|
||||
|
||||
|
||||
def assert_result(result, params, num_prompt) -> None:
|
||||
assert result["completed"] == num_prompt, "Request failures exist"
|
||||
if params.get("dataset_name") == "omniinteract":
|
||||
@@ -271,6 +457,23 @@ def assert_result(result, params, num_prompt) -> None:
|
||||
0,
|
||||
), "OmniInteract requests did not all succeed"
|
||||
assert summary.get("artifacts_complete") is True, "OmniInteract artifacts are incomplete"
|
||||
if params.get("omniinteract_evaluate"):
|
||||
accuracy = summary.get("accuracy")
|
||||
assert isinstance(accuracy, dict), "OmniInteract accuracy is missing"
|
||||
assert accuracy.get("status") == "ok", "OmniInteract accuracy did not complete"
|
||||
assert accuracy.get("failed") == 0, "OmniInteract accuracy reported failed cases"
|
||||
_assert_subset_evaluated(accuracy)
|
||||
acc_summary = accuracy.get("summary")
|
||||
assert isinstance(acc_summary, dict), "OmniInteract accuracy summary is missing"
|
||||
ia_qtf1 = acc_summary.get("IA_QTF1")
|
||||
assert _is_finite_number(ia_qtf1), "OmniInteract All Global IA-QTF1 is missing"
|
||||
min_ia_qtf1 = params.get("omniinteract_min_ia_qtf1")
|
||||
if min_ia_qtf1 is not None:
|
||||
assert _is_finite_number(min_ia_qtf1), "omniinteract_min_ia_qtf1 must be a finite number"
|
||||
assert float(ia_qtf1) >= float(min_ia_qtf1), (
|
||||
f"OmniInteract All Global IA-QTF1 {ia_qtf1} is below {min_ia_qtf1}"
|
||||
)
|
||||
_maybe_assert_aggregate_ia_qtf1(params, acc_summary)
|
||||
baseline = params.get("baseline")
|
||||
hardware = result.get("Hardware")
|
||||
hardware_baseline = baseline.get(hardware) if isinstance(baseline, dict) and isinstance(hardware, str) else None
|
||||
@@ -304,8 +507,13 @@ def assert_result(result, params, num_prompt) -> None:
|
||||
)
|
||||
def test_performance_benchmark(omni_server, benchmark_params):
|
||||
test_name = benchmark_params["test_name"]
|
||||
params = benchmark_params["params"]
|
||||
params = dict(benchmark_params["params"])
|
||||
dataset_name = params.get("dataset_name", "")
|
||||
if params.get("omniinteract_evaluate"):
|
||||
judge_base_url = getattr(omni_server, "judge_base_url", None)
|
||||
if not isinstance(judge_base_url, str) or not judge_base_url:
|
||||
raise ValueError("omniinteract_evaluate requires top-level judge_server_params to start a judge")
|
||||
params["omniinteract_judge_base_url"] = judge_base_url
|
||||
|
||||
host = omni_server.host
|
||||
port = omni_server.port
|
||||
@@ -349,6 +557,11 @@ def test_performance_benchmark(omni_server, benchmark_params):
|
||||
"eval_phase",
|
||||
"trust_remote_code",
|
||||
"expected_duplex_audio_turns_per_session",
|
||||
"omniinteract_min_ia_qtf1",
|
||||
_OMNIINTERACT_AGGREGATE_MIN_IA_QTF1,
|
||||
_OMNIINTERACT_AGGREGATE_SUBSETS,
|
||||
_OMNIINTERACT_AGGREGATE_GROUP,
|
||||
"judge_server_params",
|
||||
"name",
|
||||
"enable_negative_prompt",
|
||||
"random_request_config",
|
||||
@@ -403,7 +616,7 @@ def test_performance_benchmark(omni_server, benchmark_params):
|
||||
num_warmups=_resolve_num_warmups(params, default=2),
|
||||
benchmark_params_name=params.get("name") if isinstance(params.get("name"), str) else None,
|
||||
)
|
||||
assert_result(result, params, num_prompt)
|
||||
assert_result(result, {**params, **_aggregate_accuracy_params_for_test(test_name)}, num_prompt)
|
||||
|
||||
# concurrency test
|
||||
for sweep_index, (concurrency, num_prompt) in enumerate(zip(max_concurrency_list, num_prompt_list)):
|
||||
@@ -422,4 +635,4 @@ def test_performance_benchmark(omni_server, benchmark_params):
|
||||
num_warmups=_resolve_num_warmups(params, default=max(2, int(concurrency))),
|
||||
benchmark_params_name=params.get("name") if isinstance(params.get("name"), str) else None,
|
||||
)
|
||||
assert_result(result, params, num_prompt)
|
||||
assert_result(result, {**params, **_aggregate_accuracy_params_for_test(test_name)}, num_prompt)
|
||||
@@ -7,7 +7,7 @@
|
||||
"res": {
|
||||
"cuda": "H100"
|
||||
},
|
||||
"num_cards": 1
|
||||
"num_cards": 2
|
||||
}
|
||||
},
|
||||
"local_model",
|
||||
@@ -21,6 +21,16 @@
|
||||
"--trust-remote-code"
|
||||
]
|
||||
},
|
||||
"judge_server_params": {
|
||||
"model": "Qwen/Qwen2.5-7B-Instruct",
|
||||
"use_omni": false,
|
||||
"cuda_visible_devices": "1",
|
||||
"extra_cli_args": [
|
||||
"--served-model-name",
|
||||
"Qwen2.5-7B-Instruct"
|
||||
]
|
||||
},
|
||||
"omniinteract_aggregate_min_ia_qtf1": 0.2,
|
||||
"benchmark_params": [
|
||||
{
|
||||
"dataset_name": "omniinteract",
|
||||
@@ -40,6 +50,8 @@
|
||||
"omniinteract_ref_audio": "tests/assets/minicpmo_4_5/response_required_16k.wav",
|
||||
"omniinteract_output_dir": "tests/dfx/perf/results/omniinteract/1q1a",
|
||||
"omniinteract_max_video_duration_s": 600,
|
||||
"omniinteract_evaluate": true,
|
||||
"omniinteract_judge_model": "Qwen2.5-7B-Instruct",
|
||||
"percentile-metrics": "ttft,tpot,itl,e2el,audio_ttfp,audio_rtf,audio_duration"
|
||||
},
|
||||
{
|
||||
@@ -60,6 +72,8 @@
|
||||
"omniinteract_ref_audio": "tests/assets/minicpmo_4_5/response_required_16k.wav",
|
||||
"omniinteract_output_dir": "tests/dfx/perf/results/omniinteract/1q1a_math",
|
||||
"omniinteract_max_video_duration_s": 600,
|
||||
"omniinteract_evaluate": true,
|
||||
"omniinteract_judge_model": "Qwen2.5-7B-Instruct",
|
||||
"percentile-metrics": "ttft,tpot,itl,e2el,audio_ttfp,audio_rtf,audio_duration"
|
||||
},
|
||||
{
|
||||
@@ -80,6 +94,8 @@
|
||||
"omniinteract_ref_audio": "tests/assets/minicpmo_4_5/response_required_16k.wav",
|
||||
"omniinteract_output_dir": "tests/dfx/perf/results/omniinteract/1qna",
|
||||
"omniinteract_max_video_duration_s": 600,
|
||||
"omniinteract_evaluate": true,
|
||||
"omniinteract_judge_model": "Qwen2.5-7B-Instruct",
|
||||
"percentile-metrics": "ttft,tpot,itl,e2el,audio_ttfp,audio_rtf,audio_duration"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -694,6 +694,204 @@ def test_omniinteract_result_rejects_incomplete_artifacts():
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_result_accepts_accuracy_at_floor():
|
||||
from tests.dfx.perf.scripts.run_benchmark import assert_result
|
||||
|
||||
assert_result(
|
||||
{
|
||||
"completed": 4,
|
||||
"omniinteract": {
|
||||
"total": 4,
|
||||
"success": 4,
|
||||
"failed": 0,
|
||||
"artifacts_complete": True,
|
||||
"accuracy": {
|
||||
"status": "ok",
|
||||
"failed": 0,
|
||||
"evaluated": 4,
|
||||
"summary": {"IA_QTF1": 0.25},
|
||||
},
|
||||
},
|
||||
},
|
||||
{"dataset_name": "omniinteract", "omniinteract_evaluate": True, "omniinteract_min_ia_qtf1": 0.2},
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_result_rejects_missing_accuracy():
|
||||
from tests.dfx.perf.scripts.run_benchmark import assert_result
|
||||
|
||||
with pytest.raises(AssertionError, match="accuracy is missing"):
|
||||
assert_result(
|
||||
{
|
||||
"completed": 4,
|
||||
"omniinteract": {"total": 4, "success": 4, "failed": 0, "artifacts_complete": True},
|
||||
},
|
||||
{"dataset_name": "omniinteract", "omniinteract_evaluate": True},
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_result_rejects_failed_accuracy():
|
||||
from tests.dfx.perf.scripts.run_benchmark import assert_result
|
||||
|
||||
with pytest.raises(AssertionError, match="accuracy did not complete"):
|
||||
assert_result(
|
||||
{
|
||||
"completed": 4,
|
||||
"omniinteract": {
|
||||
"total": 4,
|
||||
"success": 4,
|
||||
"failed": 0,
|
||||
"artifacts_complete": True,
|
||||
"accuracy": {"status": "failed", "failed": 1, "summary": {"IA_QTF1": 0.9}},
|
||||
},
|
||||
},
|
||||
{"dataset_name": "omniinteract", "omniinteract_evaluate": True, "omniinteract_min_ia_qtf1": 0.0},
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_result_rejects_ia_qtf1_below_floor():
|
||||
from tests.dfx.perf.scripts.run_benchmark import assert_result
|
||||
|
||||
with pytest.raises(AssertionError, match="IA-QTF1"):
|
||||
assert_result(
|
||||
{
|
||||
"completed": 4,
|
||||
"omniinteract": {
|
||||
"total": 4,
|
||||
"success": 4,
|
||||
"failed": 0,
|
||||
"artifacts_complete": True,
|
||||
"accuracy": {
|
||||
"status": "ok",
|
||||
"failed": 0,
|
||||
"evaluated": 4,
|
||||
"summary": {"IA_QTF1": 0.1},
|
||||
},
|
||||
},
|
||||
},
|
||||
{"dataset_name": "omniinteract", "omniinteract_evaluate": True, "omniinteract_min_ia_qtf1": 0.2},
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def _omniinteract_accuracy_result(
|
||||
*,
|
||||
tp: float,
|
||||
fp: float,
|
||||
fn: float,
|
||||
ia_qtf1: float = 0.5,
|
||||
evaluated: int = 4,
|
||||
skipped: int = 0,
|
||||
) -> dict[str, object]:
|
||||
return {
|
||||
"completed": 4,
|
||||
"omniinteract": {
|
||||
"total": 4,
|
||||
"success": 4,
|
||||
"failed": 0,
|
||||
"artifacts_complete": True,
|
||||
"accuracy": {
|
||||
"status": "ok",
|
||||
"failed": 0,
|
||||
"evaluated": evaluated,
|
||||
"skipped": skipped,
|
||||
"total": 4,
|
||||
"summary": {"IA_QTF1": ia_qtf1, "Global_TP": tp, "Global_FP": fp, "Global_FN": fn},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _omniinteract_aggregate_params(subset: str, *, group: str) -> dict[str, object]:
|
||||
return {
|
||||
"dataset_name": "omniinteract",
|
||||
"omniinteract_evaluate": True,
|
||||
"omniinteract_subsets": subset,
|
||||
"omniinteract_aggregate_min_ia_qtf1": 0.2,
|
||||
"omniinteract_aggregate_subsets": ["1q1a", "1q1a_math", "1qna"],
|
||||
"omniinteract_aggregate_group": group,
|
||||
}
|
||||
|
||||
|
||||
def test_omniinteract_aggregate_waits_until_all_subsets():
|
||||
from tests.dfx.perf.scripts.run_benchmark import _reset_omniinteract_aggregate_counts, assert_result
|
||||
|
||||
_reset_omniinteract_aggregate_counts()
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=6.157502, fp=9, fn=8),
|
||||
_omniinteract_aggregate_params("1q1a", group="wait"),
|
||||
4,
|
||||
)
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=1.133541, fp=2, fn=2),
|
||||
_omniinteract_aggregate_params("1q1a_math", group="wait"),
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_aggregate_accepts_pooled_ia_qtf1_at_floor():
|
||||
from tests.dfx.perf.scripts.run_benchmark import _reset_omniinteract_aggregate_counts, assert_result
|
||||
|
||||
_reset_omniinteract_aggregate_counts()
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=6.157502, fp=9, fn=8),
|
||||
_omniinteract_aggregate_params("1q1a", group="pass"),
|
||||
4,
|
||||
)
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=1.133541, fp=2, fn=2),
|
||||
_omniinteract_aggregate_params("1q1a_math", group="pass"),
|
||||
4,
|
||||
)
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=0.0, fp=11, fn=18, ia_qtf1=0.0),
|
||||
_omniinteract_aggregate_params("1qna", group="pass"),
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_aggregate_rejects_pooled_ia_qtf1_below_floor():
|
||||
from tests.dfx.perf.scripts.run_benchmark import _reset_omniinteract_aggregate_counts, assert_result
|
||||
|
||||
_reset_omniinteract_aggregate_counts()
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=0.0, fp=1, fn=1, ia_qtf1=0.0),
|
||||
_omniinteract_aggregate_params("1q1a", group="fail"),
|
||||
4,
|
||||
)
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=0.0, fp=1, fn=1, ia_qtf1=0.0),
|
||||
_omniinteract_aggregate_params("1q1a_math", group="fail"),
|
||||
4,
|
||||
)
|
||||
with pytest.raises(AssertionError, match="aggregate All Global IA-QTF1"):
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=0.0, fp=1, fn=1, ia_qtf1=0.0),
|
||||
_omniinteract_aggregate_params("1qna", group="fail"),
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omniinteract_aggregate_rejects_entirely_skipped_subset():
|
||||
from tests.dfx.perf.scripts.run_benchmark import _reset_omniinteract_aggregate_counts, assert_result
|
||||
|
||||
_reset_omniinteract_aggregate_counts()
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=4.0, fp=0.0, fn=0.0, ia_qtf1=1.0),
|
||||
_omniinteract_aggregate_params("1q1a", group="skipped-subset"),
|
||||
4,
|
||||
)
|
||||
with pytest.raises(AssertionError, match="evaluated 0 cases"):
|
||||
assert_result(
|
||||
_omniinteract_accuracy_result(tp=0.0, fp=0.0, fn=0.0, ia_qtf1=1.0, evaluated=0, skipped=4),
|
||||
_omniinteract_aggregate_params("1q1a_math", group="skipped-subset"),
|
||||
4,
|
||||
)
|
||||
|
||||
|
||||
def test_omni_tpot_baseline_accepts_measured_finite_sample():
|
||||
from tests.dfx.perf.scripts.run_benchmark import assert_result
|
||||
|
||||
|
||||
Reference in new issue
Block a user