[Accuracy Benchmark] feat: add accuracy benchmark integrations for t2i and i2i (#1917)
Signed-off-by: David Chen <530634352@qq.com> Signed-off-by: WeiQing Chen <40507679+david6666666@users.noreply.github.com>
This commit is contained in:
1 parent
ce916f4233
commit
c392ce21e9
20 files changed
+3370
-7
No files matched your search
@@ -0,0 +1,685 @@
|
||||
# ruff: noqa: E402, I001
|
||||
import math
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(REPO_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(REPO_ROOT))
|
||||
|
||||
from benchmarks.accuracy.common import VllmOmniImageClient
|
||||
from benchmarks.accuracy.image_to_image.gedit_bench import (
|
||||
GROUPS as GEDIT_GROUPS,
|
||||
GEditBenchEvaluator,
|
||||
GEditBenchRunner,
|
||||
_load_gedit_dataset,
|
||||
_resolve_gedit_split,
|
||||
infer_model_name,
|
||||
resolve_model_name,
|
||||
select_balanced_gedit_rows,
|
||||
parse_score_payload,
|
||||
summarize_generated_records as summarize_gedit_generated_records,
|
||||
summarize_gedit_rows,
|
||||
summarize_gedit_rows_with_backbone,
|
||||
)
|
||||
from benchmarks.accuracy.text_to_image.gbench import (
|
||||
_expand_sample_path,
|
||||
_trajectory_judge_payload,
|
||||
_write_json_with_timestamp,
|
||||
LocalJudgeClient,
|
||||
GEBenchEvaluator,
|
||||
TYPE_TO_FOLDER,
|
||||
select_balanced_gebench_samples,
|
||||
summarize_generated_records as summarize_gebench_generated_records,
|
||||
summarize_gebench_results,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
|
||||
def test_summarize_gebench_generated_records_groups_by_type():
|
||||
records = [
|
||||
{"data_type": "type1", "sample_name": "english_phone/folder_1", "output_path": "a.png"},
|
||||
{"data_type": "type1", "sample_name": "english_phone/folder_2", "output_path": "b.png"},
|
||||
{"data_type": "type2", "sample_name": "english_phone/folder_3", "output_path": "c.png"},
|
||||
]
|
||||
|
||||
summary = summarize_gebench_generated_records(records)
|
||||
|
||||
assert summary["count"] == 3
|
||||
assert summary["by_type"]["type1"]["count"] == 2
|
||||
assert summary["by_type"]["type2"]["count"] == 1
|
||||
assert "samples" not in summary["by_type"]["type1"]
|
||||
|
||||
|
||||
def test_summarize_gebench_results_computes_type_and_global_means():
|
||||
results = [
|
||||
{"data_type": "type1", "overall": 0.8, "scores": {"goal": 5, "logic": 4}},
|
||||
{"data_type": "type1", "overall": 0.6, "scores": {"goal": 3, "logic": 4}},
|
||||
{"data_type": "type2", "overall": 0.5, "scores": {"goal": 2, "logic": 3}},
|
||||
]
|
||||
|
||||
summary = summarize_gebench_results(results)
|
||||
|
||||
assert math.isclose(summary["overall_mean"], (0.8 + 0.6 + 0.5) / 3)
|
||||
assert math.isclose(summary["by_type"]["type1"]["overall_mean"], 0.7)
|
||||
assert math.isclose(summary["by_type"]["type2"]["overall_mean"], 0.5)
|
||||
assert math.isclose(summary["by_type"]["type1"]["score_means"]["goal"], 4.0)
|
||||
|
||||
|
||||
def test_write_json_with_timestamp_writes_stable_and_timestamped_files(monkeypatch, tmp_path: Path):
|
||||
monkeypatch.setattr(
|
||||
"benchmarks.accuracy.text_to_image.gbench._utc_timestamp",
|
||||
lambda: "20260325T130000Z",
|
||||
)
|
||||
|
||||
timestamped_path = _write_json_with_timestamp(tmp_path / "summary.json", {"ok": True})
|
||||
|
||||
assert (tmp_path / "summary.json").exists()
|
||||
assert timestamped_path == tmp_path / "summary_20260325T130000Z.json"
|
||||
assert timestamped_path.exists()
|
||||
|
||||
|
||||
def test_select_balanced_gebench_samples_limits_each_type_independently():
|
||||
sample_paths_by_type = {
|
||||
"type1": [Path(f"/tmp/type1_{idx}") for idx in range(12)],
|
||||
"type2": [Path(f"/tmp/type2_{idx}") for idx in range(8)],
|
||||
"type3": [Path(f"/tmp/type3_{idx}") for idx in range(15)],
|
||||
}
|
||||
|
||||
selected = select_balanced_gebench_samples(sample_paths_by_type, samples_per_type=10)
|
||||
|
||||
assert len(selected["type1"]) == 10
|
||||
assert len(selected["type2"]) == 8
|
||||
assert len(selected["type3"]) == 10
|
||||
assert selected["type1"][0].name == "type1_0"
|
||||
assert selected["type3"][-1].name == "type3_9"
|
||||
|
||||
|
||||
def test_expand_sample_path_flattens_json_list_samples(tmp_path: Path):
|
||||
sample_path = tmp_path / "trajectories.json"
|
||||
sample_path.write_text(
|
||||
"""
|
||||
[
|
||||
{"id": "sample_a", "lang_device": "english_phone", "instruction": "do a"},
|
||||
{"id": "sample_b", "lang_device": "english_phone", "instruction": "do b"}
|
||||
]
|
||||
""".strip(),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
specs = _expand_sample_path(sample_path)
|
||||
|
||||
assert len(specs) == 2
|
||||
assert specs[0].sample_name == "sample_a"
|
||||
assert specs[1].sample_name == "sample_b"
|
||||
assert specs[0].lang_device == "english_phone"
|
||||
|
||||
|
||||
def test_gebench_evaluate_skips_missing_output_folder(tmp_path: Path):
|
||||
dataset_type_root = tmp_path / TYPE_TO_FOLDER["type3"] / "english_phone"
|
||||
sample_dir = dataset_type_root / "sample_a"
|
||||
sample_dir.mkdir(parents=True)
|
||||
(sample_dir / "meta_data.json").write_text("{}", encoding="utf-8")
|
||||
|
||||
judge = LocalJudgeClient(base_url="http://127.0.0.1:8094", api_key="EMPTY", model="judge")
|
||||
evaluator = GEBenchEvaluator(dataset_root=tmp_path, output_root=tmp_path / "outputs", judge=judge)
|
||||
|
||||
payload = evaluator.evaluate(data_type="type3")
|
||||
|
||||
assert payload["results"] == []
|
||||
assert payload["summary"]["count"] == 0
|
||||
|
||||
|
||||
def test_local_judge_client_retries_when_first_response_is_not_json(monkeypatch):
|
||||
responses = iter(
|
||||
[
|
||||
"The image looks like a GUI screenshot with several controls.",
|
||||
'{"goal": 4, "logic": 4, "cons": 5, "ui": 4, "qual": 4, "reasoning": "mostly correct"}',
|
||||
]
|
||||
)
|
||||
|
||||
def fake_request_text(self, prompt, images):
|
||||
return next(responses)
|
||||
|
||||
monkeypatch.setattr(LocalJudgeClient, "_request_text", fake_request_text)
|
||||
|
||||
judge = LocalJudgeClient(base_url="http://127.0.0.1:8094", api_key="EMPTY", model="judge")
|
||||
result = judge.evaluate(prompt="Evaluate this GUI trajectory.", images=[Image.new("RGB", (2, 2), color="white")])
|
||||
|
||||
assert result["goal"] == 4
|
||||
assert result["cons"] == 5
|
||||
|
||||
|
||||
def test_local_judge_client_returns_zero_scores_when_retry_is_still_invalid(monkeypatch):
|
||||
responses = iter(
|
||||
[
|
||||
"not json",
|
||||
"still not json",
|
||||
]
|
||||
)
|
||||
|
||||
def fake_request_text(self, prompt, images):
|
||||
return next(responses)
|
||||
|
||||
monkeypatch.setattr(LocalJudgeClient, "_request_text", fake_request_text)
|
||||
|
||||
judge = LocalJudgeClient(base_url="http://127.0.0.1:8094", api_key="EMPTY", model="judge")
|
||||
result = judge.evaluate(prompt="Evaluate this GUI trajectory.", images=[Image.new("RGB", (2, 2), color="white")])
|
||||
|
||||
assert result["goal"] == 0
|
||||
assert result["logic"] == 0
|
||||
assert result["cons"] == 0
|
||||
assert result["ui"] == 0
|
||||
assert result["qual"] == 0
|
||||
assert result["reasoning"] == "still not json"
|
||||
|
||||
|
||||
def test_trajectory_judge_payload_collapses_six_frames_into_single_storyboard():
|
||||
frames = [Image.new("RGB", (8, 6), color=(idx * 10, idx * 10, idx * 10)) for idx in range(6)]
|
||||
|
||||
prompt_suffix, judge_images = _trajectory_judge_payload(frames)
|
||||
|
||||
assert "frame0" in prompt_suffix
|
||||
assert len(judge_images) == 1
|
||||
assert judge_images[0].size == (24, 12)
|
||||
|
||||
|
||||
def test_image_edit_client_uses_openai_image_edit_endpoint(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
class FakeResponse:
|
||||
status_code = 200
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
"data": [
|
||||
{
|
||||
"b64_json": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aY0cAAAAASUVORK5CYII="
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def fake_post(url, data=None, files=None, headers=None, timeout=None, **kwargs):
|
||||
captured["url"] = url
|
||||
captured["data"] = data
|
||||
captured["files"] = files
|
||||
captured["headers"] = headers
|
||||
captured["timeout"] = timeout
|
||||
return FakeResponse()
|
||||
|
||||
monkeypatch.setattr("benchmarks.accuracy.common.requests.post", fake_post)
|
||||
|
||||
client = VllmOmniImageClient(base_url="http://127.0.0.1:8093", api_key="EMPTY")
|
||||
image = Image.new("RGB", (2, 2), color="white")
|
||||
output = client.generate_image_edit(
|
||||
model="Qwen/Qwen-Image-Edit",
|
||||
prompt="edit this image",
|
||||
images=image,
|
||||
width=512,
|
||||
height=512,
|
||||
)
|
||||
|
||||
assert output.size == (1, 1)
|
||||
assert captured["url"] == "http://127.0.0.1:8093/v1/images/edits"
|
||||
assert captured["data"]["prompt"] == "edit this image"
|
||||
assert captured["data"]["size"] == "512x512"
|
||||
assert captured["files"][0][0] == "image"
|
||||
|
||||
|
||||
def test_text_to_image_client_forwards_output_compression(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
class FakeResponse:
|
||||
status_code = 200
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
"data": [
|
||||
{
|
||||
"b64_json": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aY0cAAAAASUVORK5CYII="
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def fake_post(url, json=None, headers=None, timeout=None, **kwargs):
|
||||
captured["url"] = url
|
||||
captured["json"] = json
|
||||
return FakeResponse()
|
||||
|
||||
monkeypatch.setattr("benchmarks.accuracy.common.requests.post", fake_post)
|
||||
|
||||
client = VllmOmniImageClient(base_url="http://127.0.0.1:8093", api_key="EMPTY")
|
||||
output = client.generate_text_to_image(
|
||||
model="Qwen/Qwen-Image",
|
||||
prompt="generate a gui",
|
||||
width=768,
|
||||
height=576,
|
||||
num_inference_steps=8,
|
||||
output_compression=98,
|
||||
)
|
||||
|
||||
assert output.size == (1, 1)
|
||||
assert captured["url"] == "http://127.0.0.1:8093/v1/images/generations"
|
||||
assert captured["json"]["size"] == "768x576"
|
||||
assert captured["json"]["num_inference_steps"] == 8
|
||||
assert captured["json"]["output_compression"] == 98
|
||||
|
||||
|
||||
def test_parse_score_payload_handles_raw_json_and_delimited_json():
|
||||
raw = '{"score": [7, 8], "reasoning": "ok"}'
|
||||
wrapped = 'prefix ||V^=^V|| {"score": [6], "reasoning": "fine"} ||V^=^V|| suffix'
|
||||
|
||||
assert parse_score_payload(raw)["score"] == [7, 8]
|
||||
assert parse_score_payload(wrapped)["score"] == [6]
|
||||
|
||||
|
||||
def test_summarize_gedit_generated_records_groups_by_task_and_language():
|
||||
records = []
|
||||
for group in GEDIT_GROUPS[:2]:
|
||||
records.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "en",
|
||||
"key": f"{group}_en",
|
||||
"output_path": f"{group}_en.png",
|
||||
}
|
||||
)
|
||||
records.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "cn",
|
||||
"key": f"{group}_cn",
|
||||
"output_path": f"{group}_cn.png",
|
||||
}
|
||||
)
|
||||
|
||||
summary = summarize_gedit_generated_records(records)
|
||||
|
||||
assert summary["count"] == 4
|
||||
assert summary["by_task"][GEDIT_GROUPS[0]]["count"] == 2
|
||||
assert summary["by_language"]["en"]["count"] == 2
|
||||
assert summary["by_language"]["cn"]["samples"] == [
|
||||
f"{GEDIT_GROUPS[0]}_cn",
|
||||
f"{GEDIT_GROUPS[1]}_cn",
|
||||
]
|
||||
|
||||
|
||||
def test_select_balanced_gedit_rows_limits_each_group_independently():
|
||||
rows = []
|
||||
for idx in range(12):
|
||||
rows.append(
|
||||
{
|
||||
"task_type": "background_change",
|
||||
"instruction_language": "en",
|
||||
"key": f"background_change_{idx}",
|
||||
}
|
||||
)
|
||||
for idx in range(7):
|
||||
rows.append(
|
||||
{
|
||||
"task_type": "color_alter",
|
||||
"instruction_language": "en",
|
||||
"key": f"color_alter_{idx}",
|
||||
}
|
||||
)
|
||||
|
||||
selected = select_balanced_gedit_rows(
|
||||
rows,
|
||||
task_type="all",
|
||||
instruction_language="en",
|
||||
samples_per_group=10,
|
||||
)
|
||||
|
||||
selected_background = [row for row in selected if row["task_type"] == "background_change"]
|
||||
selected_color = [row for row in selected if row["task_type"] == "color_alter"]
|
||||
|
||||
assert len(selected_background) == 10
|
||||
assert len(selected_color) == 7
|
||||
assert selected_background[0]["key"] == "background_change_0"
|
||||
assert selected_background[-1]["key"] == "background_change_9"
|
||||
|
||||
|
||||
def test_select_balanced_gedit_rows_balances_languages_when_all_requested():
|
||||
rows = []
|
||||
for idx in range(10):
|
||||
rows.append(
|
||||
{
|
||||
"task_type": "background_change",
|
||||
"instruction_language": "cn",
|
||||
"key": f"background_change_cn_{idx}",
|
||||
}
|
||||
)
|
||||
for idx in range(10):
|
||||
rows.append(
|
||||
{
|
||||
"task_type": "background_change",
|
||||
"instruction_language": "en",
|
||||
"key": f"background_change_en_{idx}",
|
||||
}
|
||||
)
|
||||
|
||||
selected = select_balanced_gedit_rows(
|
||||
rows,
|
||||
task_type="all",
|
||||
instruction_language="all",
|
||||
samples_per_group=10,
|
||||
)
|
||||
|
||||
selected_background = [row for row in selected if row["task_type"] == "background_change"]
|
||||
|
||||
assert len(selected_background) == 10
|
||||
assert sum(1 for row in selected_background if row["instruction_language"] == "en") == 5
|
||||
assert sum(1 for row in selected_background if row["instruction_language"] == "cn") == 5
|
||||
|
||||
|
||||
def test_infer_model_name_uses_last_path_segment():
|
||||
assert infer_model_name("/workspace/models/Qwen/Qwen-Image-Edit") == "Qwen-Image-Edit"
|
||||
|
||||
|
||||
def test_resolve_model_name_prefers_explicit_value_then_model_then_output_root(tmp_path: Path):
|
||||
assert (
|
||||
resolve_model_name(
|
||||
model_name="explicit_name",
|
||||
model="/workspace/models/Qwen/Qwen-Image-Edit",
|
||||
)
|
||||
== "explicit_name"
|
||||
)
|
||||
assert (
|
||||
resolve_model_name(
|
||||
model_name=None,
|
||||
model="/workspace/models/Qwen/Qwen-Image-Edit",
|
||||
)
|
||||
== "Qwen-Image-Edit"
|
||||
)
|
||||
|
||||
output_root = tmp_path / "results"
|
||||
(output_root / "qwen_image_edit").mkdir(parents=True)
|
||||
assert resolve_model_name(model_name=None, output_root=output_root) == "qwen_image_edit"
|
||||
|
||||
|
||||
def test_resolve_gedit_split_accepts_dataset_dict_like_input():
|
||||
train_rows = [{"key": "a"}]
|
||||
dataset = {"train": train_rows}
|
||||
|
||||
assert _resolve_gedit_split(dataset) == train_rows
|
||||
|
||||
|
||||
def test_resolve_gedit_split_accepts_dataset_like_input():
|
||||
rows = [{"key": "a"}]
|
||||
|
||||
assert _resolve_gedit_split(rows) == rows
|
||||
|
||||
|
||||
def test_load_gedit_dataset_uses_load_from_disk_for_saved_dataset(monkeypatch, tmp_path: Path):
|
||||
(tmp_path / "state.json").write_text("{}", encoding="utf-8")
|
||||
(tmp_path / "dataset_info.json").write_text("{}", encoding="utf-8")
|
||||
captured = {}
|
||||
|
||||
def fake_load_dataset(path):
|
||||
captured["load_dataset"] = path
|
||||
return "load_dataset"
|
||||
|
||||
def fake_load_from_disk(path):
|
||||
captured["load_from_disk"] = path
|
||||
return "load_from_disk"
|
||||
|
||||
monkeypatch.setattr(
|
||||
"benchmarks.accuracy.image_to_image.gedit_bench._require_datasets",
|
||||
lambda: (fake_load_dataset, fake_load_from_disk),
|
||||
)
|
||||
|
||||
result = _load_gedit_dataset(str(tmp_path))
|
||||
|
||||
assert result == "load_from_disk"
|
||||
assert captured["load_from_disk"] == str(tmp_path)
|
||||
assert "load_dataset" not in captured
|
||||
|
||||
|
||||
def test_load_gedit_dataset_uses_load_dataset_for_local_snapshot_path(monkeypatch, tmp_path: Path):
|
||||
(tmp_path / "README.md").write_text("dataset repo snapshot", encoding="utf-8")
|
||||
captured = {}
|
||||
|
||||
def fake_load_dataset(path):
|
||||
captured["load_dataset"] = path
|
||||
return "load_dataset"
|
||||
|
||||
def fake_load_from_disk(path):
|
||||
captured["load_from_disk"] = path
|
||||
return "load_from_disk"
|
||||
|
||||
monkeypatch.setattr(
|
||||
"benchmarks.accuracy.image_to_image.gedit_bench._require_datasets",
|
||||
lambda: (fake_load_dataset, fake_load_from_disk),
|
||||
)
|
||||
|
||||
result = _load_gedit_dataset(str(tmp_path))
|
||||
|
||||
assert result == "load_dataset"
|
||||
assert captured["load_dataset"] == str(tmp_path)
|
||||
assert "load_from_disk" not in captured
|
||||
|
||||
|
||||
def test_gedit_runner_generate_skips_failed_samples(monkeypatch, tmp_path: Path):
|
||||
rows = [
|
||||
{"key": "ok", "task_type": "background_change", "instruction_language": "en"},
|
||||
{"key": "bad", "task_type": "background_change", "instruction_language": "en"},
|
||||
]
|
||||
|
||||
monkeypatch.setattr("benchmarks.accuracy.image_to_image.gedit_bench._load_gedit_dataset", lambda ref: rows)
|
||||
runner = GEditBenchRunner(
|
||||
dataset_ref="dataset",
|
||||
output_root=tmp_path,
|
||||
base_url="http://127.0.0.1:8093",
|
||||
model="model",
|
||||
)
|
||||
|
||||
def fake_generate_one(self, model_name, item):
|
||||
if item["key"] == "bad":
|
||||
raise RuntimeError("boom")
|
||||
return {
|
||||
"key": item["key"],
|
||||
"task_type": item["task_type"],
|
||||
"instruction_language": item["instruction_language"],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(GEditBenchRunner, "_generate_one", fake_generate_one)
|
||||
|
||||
outputs = runner.generate(model_name="demo", workers=1)
|
||||
|
||||
assert outputs == [{"key": "ok", "task_type": "background_change", "instruction_language": "en"}]
|
||||
|
||||
|
||||
def test_gedit_runner_uses_tqdm_progress(monkeypatch, tmp_path: Path):
|
||||
rows = [
|
||||
{"key": "one", "task_type": "background_change", "instruction_language": "en"},
|
||||
{"key": "two", "task_type": "background_change", "instruction_language": "en"},
|
||||
]
|
||||
updates = []
|
||||
|
||||
monkeypatch.setattr("benchmarks.accuracy.image_to_image.gedit_bench._load_gedit_dataset", lambda ref: rows)
|
||||
runner = GEditBenchRunner(
|
||||
dataset_ref="dataset",
|
||||
output_root=tmp_path,
|
||||
base_url="http://127.0.0.1:8093",
|
||||
model="model",
|
||||
)
|
||||
|
||||
def fake_generate_one(self, model_name, item):
|
||||
return {
|
||||
"key": item["key"],
|
||||
"task_type": item["task_type"],
|
||||
"instruction_language": item["instruction_language"],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(GEditBenchRunner, "_generate_one", fake_generate_one)
|
||||
|
||||
class FakeTqdm:
|
||||
def __init__(self, total, desc, unit):
|
||||
self.total = total
|
||||
self.desc = desc
|
||||
self.unit = unit
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def update(self, value):
|
||||
updates.append(value)
|
||||
|
||||
monkeypatch.setattr("benchmarks.accuracy.image_to_image.gedit_bench.tqdm", FakeTqdm)
|
||||
|
||||
runner.generate(model_name="demo", workers=1)
|
||||
|
||||
assert updates == [1, 1]
|
||||
|
||||
|
||||
def test_gedit_evaluator_skips_failed_samples(monkeypatch, tmp_path: Path):
|
||||
rows = [
|
||||
{"key": "ok", "task_type": "background_change", "instruction_language": "en"},
|
||||
{"key": "bad", "task_type": "background_change", "instruction_language": "en"},
|
||||
]
|
||||
|
||||
monkeypatch.setattr("benchmarks.accuracy.image_to_image.gedit_bench._load_gedit_dataset", lambda ref: rows)
|
||||
evaluator = GEditBenchEvaluator(dataset_ref="dataset", output_root=tmp_path / "results", scorer=object())
|
||||
|
||||
def fake_evaluate_one(self, model_name, item):
|
||||
if item["key"] == "bad":
|
||||
raise RuntimeError("boom")
|
||||
return {
|
||||
"key": item["key"],
|
||||
"task_type": item["task_type"],
|
||||
"edited_image": "ok.png",
|
||||
"instruction": "edit",
|
||||
"semantics_score": 8.0,
|
||||
"quality_score": 7.0,
|
||||
"overall_score": math.sqrt(56.0),
|
||||
"intersection_exist": True,
|
||||
"instruction_language": item["instruction_language"],
|
||||
}
|
||||
|
||||
monkeypatch.setattr(GEditBenchEvaluator, "_evaluate_one", fake_evaluate_one)
|
||||
monkeypatch.setattr(
|
||||
"benchmarks.accuracy.image_to_image.gedit_bench._utc_timestamp",
|
||||
lambda: "20260325T120000Z",
|
||||
)
|
||||
|
||||
payload = evaluator.evaluate(
|
||||
model_name="demo",
|
||||
save_dir=tmp_path / "scores",
|
||||
instruction_language="en",
|
||||
workers=1,
|
||||
)
|
||||
|
||||
assert len(payload["results"]) == 1
|
||||
assert payload["results"][0]["key"] == "ok"
|
||||
assert payload["summary"]["overall"]["count"] == 1
|
||||
assert Path(payload["csv_path"]).name == "demo_all_en_vie_score.csv"
|
||||
assert Path(payload["summary_path"]).name == "demo_all_en_summary.json"
|
||||
assert Path(payload["timestamped_csv_path"]).name == "demo_all_en_vie_score_20260325T120000Z.csv"
|
||||
assert Path(payload["timestamped_summary_path"]).name == "demo_all_en_summary_20260325T120000Z.json"
|
||||
assert Path(payload["timestamped_csv_path"]).exists()
|
||||
assert Path(payload["timestamped_summary_path"]).exists()
|
||||
|
||||
|
||||
def test_summarize_gedit_rows_computes_group_and_intersection_means():
|
||||
rows = []
|
||||
for group in GEDIT_GROUPS:
|
||||
rows.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "en",
|
||||
"semantics_score": 8.0,
|
||||
"quality_score": 9.0,
|
||||
"intersection_exist": True,
|
||||
}
|
||||
)
|
||||
rows.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "en",
|
||||
"semantics_score": 6.0,
|
||||
"quality_score": 4.0,
|
||||
"intersection_exist": False,
|
||||
}
|
||||
)
|
||||
|
||||
summary = summarize_gedit_rows(rows, language="en")
|
||||
|
||||
expected_overall = (math.sqrt(8.0 * 9.0) + math.sqrt(6.0 * 4.0)) / 2
|
||||
assert math.isclose(summary["overall"]["Q_SC"], 7.0)
|
||||
assert math.isclose(summary["overall"]["Q_PQ"], 6.5)
|
||||
assert math.isclose(summary["overall"]["Q_O"], expected_overall)
|
||||
assert math.isclose(summary["intersection"]["Q_SC"], 8.0)
|
||||
|
||||
|
||||
def test_summarize_gedit_rows_uses_macro_average_across_groups():
|
||||
rows = []
|
||||
for idx in range(10):
|
||||
rows.append(
|
||||
{
|
||||
"task_type": "background_change",
|
||||
"instruction_language": "en",
|
||||
"semantics_score": 10.0,
|
||||
"quality_score": 10.0,
|
||||
"intersection_exist": True,
|
||||
}
|
||||
)
|
||||
for group in GEDIT_GROUPS[1:]:
|
||||
rows.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "en",
|
||||
"semantics_score": 1.0,
|
||||
"quality_score": 1.0,
|
||||
"intersection_exist": True,
|
||||
}
|
||||
)
|
||||
|
||||
summary = summarize_gedit_rows_with_backbone(rows, language="en")
|
||||
|
||||
expected_macro = (10.0 + 10.0 * 1.0) / 11
|
||||
assert math.isclose(summary["overall"]["Q_SC"], expected_macro)
|
||||
assert math.isclose(summary["overall"]["Q_O"], expected_macro)
|
||||
assert math.isclose(summary["by_group"]["background_change"]["Q_SC"], 10.0)
|
||||
|
||||
|
||||
def test_summarize_gedit_rows_with_all_language_splits_en_and_cn():
|
||||
rows = []
|
||||
for group in GEDIT_GROUPS:
|
||||
rows.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "en",
|
||||
"semantics_score": 8.0,
|
||||
"quality_score": 6.0,
|
||||
"intersection_exist": True,
|
||||
}
|
||||
)
|
||||
rows.append(
|
||||
{
|
||||
"task_type": group,
|
||||
"instruction_language": "cn",
|
||||
"semantics_score": 4.0,
|
||||
"quality_score": 2.0,
|
||||
"intersection_exist": True,
|
||||
}
|
||||
)
|
||||
|
||||
summary = summarize_gedit_rows_with_backbone(rows, language="all")
|
||||
|
||||
assert set(summary["languages"]) == {"en", "cn"}
|
||||
assert math.isclose(summary["languages"]["en"]["overall"]["Q_SC"], 8.0)
|
||||
assert math.isclose(summary["languages"]["en"]["overall"]["Q_PQ"], 6.0)
|
||||
assert math.isclose(summary["languages"]["cn"]["overall"]["Q_O"], math.sqrt(8.0))
|
||||
+29
-7
@@ -54,6 +54,8 @@ class OmniServerParams(NamedTuple):
|
||||
port: int | None = None
|
||||
stage_config_path: str | None = None
|
||||
server_args: list[str] | None = None
|
||||
env_dict: dict[str, str] | None = None
|
||||
use_omni: bool = True
|
||||
|
||||
|
||||
def assert_image_valid(image: Path | Image.Image, *, width: int | None = None, height: int | None = None):
|
||||
@@ -1076,6 +1078,7 @@ class OmniServer:
|
||||
*,
|
||||
port: int | None = None,
|
||||
env_dict: dict[str, str] | None = None,
|
||||
use_omni: bool = True,
|
||||
) -> None:
|
||||
_run_pre_test_cleanup(enable_force=True)
|
||||
_run_post_test_cleanup(enable_force=True)
|
||||
@@ -1083,6 +1086,7 @@ class OmniServer:
|
||||
self.model = model
|
||||
self.serve_args = serve_args
|
||||
self.env_dict = env_dict
|
||||
self.use_omni = use_omni
|
||||
self.proc: subprocess.Popen | None = None
|
||||
self.host = "127.0.0.1"
|
||||
if port is None:
|
||||
@@ -1103,12 +1107,14 @@ class OmniServer:
|
||||
"vllm_omni.entrypoints.cli.main",
|
||||
"serve",
|
||||
self.model,
|
||||
"--omni",
|
||||
"--host",
|
||||
self.host,
|
||||
"--port",
|
||||
str(self.port),
|
||||
] + self.serve_args
|
||||
]
|
||||
if self.use_omni:
|
||||
cmd.append("--omni")
|
||||
cmd += self.serve_args
|
||||
|
||||
print(f"Launching OmniServer with: {' '.join(cmd)}")
|
||||
self.proc = subprocess.Popen(
|
||||
@@ -1237,19 +1243,35 @@ def omni_server(request: pytest.FixtureRequest, run_level: str, model_prefix: st
|
||||
stage_config_path = params.stage_config_path
|
||||
if run_level == "advanced_model" and stage_config_path is not None:
|
||||
with open(stage_config_path, encoding="utf-8") as f:
|
||||
_cfg = yaml.safe_load(f) or {}
|
||||
_stage_ids = [s["stage_id"] for s in _cfg.get("stage_args", []) if "stage_id" in s]
|
||||
cfg = yaml.safe_load(f) or {}
|
||||
stage_ids = [stage["stage_id"] for stage in cfg.get("stage_args", []) if "stage_id" in stage]
|
||||
stage_config_path = modify_stage_config(
|
||||
stage_config_path,
|
||||
deletes={"stage_args": {sid: ["engine_args.load_format"] for sid in _stage_ids}},
|
||||
deletes={"stage_args": {stage_id: ["engine_args.load_format"] for stage_id in stage_ids}},
|
||||
)
|
||||
|
||||
server_args = params.server_args or []
|
||||
server_args = ["--stage-init-timeout", "120", *server_args]
|
||||
if params.use_omni:
|
||||
server_args = ["--stage-init-timeout", "120", *server_args]
|
||||
if stage_config_path is not None:
|
||||
server_args += ["--stage-configs-path", stage_config_path]
|
||||
|
||||
with OmniServer(model, server_args, port=port) if port else OmniServer(model, server_args) as server:
|
||||
with (
|
||||
OmniServer(
|
||||
model,
|
||||
server_args,
|
||||
port=port,
|
||||
env_dict=params.env_dict,
|
||||
use_omni=params.use_omni,
|
||||
)
|
||||
if port
|
||||
else OmniServer(
|
||||
model,
|
||||
server_args,
|
||||
env_dict=params.env_dict,
|
||||
use_omni=params.use_omni,
|
||||
)
|
||||
) as server:
|
||||
print("OmniServer started successfully")
|
||||
yield server
|
||||
print("OmniServer stopping...")
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from tests.conftest import OmniServer, OmniServerParams
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
group = parser.getgroup("accuracy-e2e")
|
||||
group.addoption("--gebench-root", action="store", default=None, help="Local GEBench dataset root")
|
||||
group.addoption("--gedit-root", action="store", default=None, help="Local GEdit-Bench dataset root")
|
||||
group.addoption(
|
||||
"--gebench-model", action="store", default="Qwen/Qwen-Image-2512", help="Generate model for GEBench smoke"
|
||||
)
|
||||
group.addoption(
|
||||
"--gedit-model", action="store", default="Qwen/Qwen-Image-Edit", help="Generate model for GEdit-Bench smoke"
|
||||
)
|
||||
group.addoption(
|
||||
"--accuracy-judge-model",
|
||||
action="store",
|
||||
default="QuantTrio/Qwen3-VL-30B-A3B-Instruct-AWQ",
|
||||
help="Judge model path",
|
||||
)
|
||||
group.addoption("--accuracy-gpu", action="store", default="0", help="Single GPU id used sequentially")
|
||||
group.addoption("--gebench-port", action="store", type=int, default=8093, help="Generate port for GEBench")
|
||||
group.addoption("--gedit-port", action="store", type=int, default=8093, help="Generate port for GEdit-Bench")
|
||||
group.addoption(
|
||||
"--gebench-samples-per-type",
|
||||
action="store",
|
||||
type=int,
|
||||
default=10,
|
||||
help="Balanced sample count per GEBench type",
|
||||
)
|
||||
group.addoption(
|
||||
"--gedit-samples-per-group",
|
||||
action="store",
|
||||
type=int,
|
||||
default=20,
|
||||
help="Balanced sample count per GEdit task group",
|
||||
)
|
||||
group.addoption("--accuracy-workers", action="store", type=int, default=1, help="Worker count for accuracy benches")
|
||||
|
||||
|
||||
def _hf_cache_root() -> Path:
|
||||
return Path(os.environ.get("HF_HOME", "/root/.cache/huggingface"))
|
||||
|
||||
|
||||
def _dataset_cache_dirs(dataset_id: str) -> list[Path]:
|
||||
cache_root = _hf_cache_root() / "hub" / f"datasets--{dataset_id.replace('/', '--')}" / "snapshots"
|
||||
if not cache_root.exists():
|
||||
return []
|
||||
return sorted(
|
||||
(path for path in cache_root.iterdir() if path.is_dir()), key=lambda path: path.stat().st_mtime, reverse=True
|
||||
)
|
||||
|
||||
|
||||
def _ensure_dataset_snapshot(dataset_id: str) -> Path:
|
||||
candidates = _dataset_cache_dirs(dataset_id)
|
||||
if candidates:
|
||||
return candidates[0]
|
||||
|
||||
subprocess.run(
|
||||
["huggingface-cli", "download", "--repo-type", "dataset", dataset_id],
|
||||
check=True,
|
||||
)
|
||||
candidates = _dataset_cache_dirs(dataset_id)
|
||||
if not candidates:
|
||||
raise FileNotFoundError(
|
||||
f"Dataset {dataset_id} was downloaded but no snapshot was found under {_hf_cache_root()}"
|
||||
)
|
||||
return candidates[0]
|
||||
|
||||
|
||||
def _resolve_dataset_root(request: pytest.FixtureRequest, option_name: str, dataset_id: str) -> Path:
|
||||
value = request.config.getoption(option_name)
|
||||
if value:
|
||||
path = Path(value)
|
||||
if not path.exists():
|
||||
pytest.skip(f"Dataset path does not exist: {path}")
|
||||
return path
|
||||
return _ensure_dataset_snapshot(dataset_id)
|
||||
|
||||
|
||||
@dataclass
|
||||
class AccuracyServerConfig:
|
||||
generate_params: OmniServerParams
|
||||
judge_params: OmniServerParams
|
||||
run_level: str
|
||||
model_prefix: str
|
||||
|
||||
@contextmanager
|
||||
def generate_server(self):
|
||||
params = self.generate_params
|
||||
model = self.model_prefix + params.model
|
||||
server_args = params.server_args or []
|
||||
if params.use_omni:
|
||||
server_args = ["--stage-init-timeout", "120", *server_args]
|
||||
with OmniServer(
|
||||
model,
|
||||
server_args,
|
||||
port=params.port,
|
||||
env_dict=params.env_dict,
|
||||
use_omni=params.use_omni,
|
||||
) as server:
|
||||
yield server
|
||||
|
||||
@contextmanager
|
||||
def judge_server(self):
|
||||
params = self.judge_params
|
||||
model = self.model_prefix + params.model
|
||||
server_args = params.server_args or []
|
||||
with OmniServer(
|
||||
model,
|
||||
server_args,
|
||||
port=params.port,
|
||||
env_dict=params.env_dict,
|
||||
use_omni=params.use_omni,
|
||||
) as server:
|
||||
yield server
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def gebench_dataset_root(request: pytest.FixtureRequest) -> Path:
|
||||
return _resolve_dataset_root(request, "gebench_root", "stepfun-ai/GEBench")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def gedit_dataset_root(request: pytest.FixtureRequest) -> Path:
|
||||
return _resolve_dataset_root(request, "gedit_root", "stepfun-ai/GEdit-Bench")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def accuracy_workers(request: pytest.FixtureRequest) -> int:
|
||||
return int(request.config.getoption("accuracy_workers"))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def gebench_samples_per_type(request: pytest.FixtureRequest) -> int:
|
||||
return int(request.config.getoption("gebench_samples_per_type"))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def gedit_samples_per_group(request: pytest.FixtureRequest) -> int:
|
||||
return int(request.config.getoption("gedit_samples_per_group"))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def accuracy_artifact_root() -> Path:
|
||||
root = Path(__file__).resolve().parent / "artifacts"
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
return root
|
||||
|
||||
|
||||
def reset_artifact_dir(path: Path) -> Path:
|
||||
if path.exists():
|
||||
shutil.rmtree(path)
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return path
|
||||
|
||||
|
||||
def infer_model_label(model: str) -> str:
|
||||
label = Path(model.rstrip("/\\")).name or "model"
|
||||
return "".join(char if char.isalnum() or char in {"-", "_"} else "_" for char in label)
|
||||
|
||||
|
||||
def _build_accuracy_server_config(
|
||||
*,
|
||||
generate_model: str,
|
||||
judge_model: str,
|
||||
shared_gpu: str,
|
||||
port: int,
|
||||
run_level: str,
|
||||
model_prefix: str,
|
||||
) -> AccuracyServerConfig:
|
||||
if torch.cuda.device_count() < 1:
|
||||
pytest.skip("Need at least 1 CUDA GPU for accuracy benchmark smoke tests.")
|
||||
|
||||
if not generate_model:
|
||||
pytest.skip("No generate model configured for accuracy benchmark test.")
|
||||
generate_server_args = ["--num-gpus", "1"]
|
||||
judge_server_args = [
|
||||
"--max-model-len",
|
||||
"32768",
|
||||
"--gpu-memory-utilization",
|
||||
"0.8",
|
||||
]
|
||||
|
||||
judge_env = {"CUDA_VISIBLE_DEVICES": shared_gpu}
|
||||
|
||||
return AccuracyServerConfig(
|
||||
generate_params=OmniServerParams(
|
||||
model=generate_model,
|
||||
port=port,
|
||||
server_args=generate_server_args,
|
||||
env_dict={"CUDA_VISIBLE_DEVICES": shared_gpu},
|
||||
use_omni=True,
|
||||
),
|
||||
judge_params=OmniServerParams(
|
||||
model=judge_model,
|
||||
port=port,
|
||||
server_args=judge_server_args,
|
||||
env_dict=judge_env,
|
||||
use_omni=False,
|
||||
),
|
||||
run_level=run_level,
|
||||
model_prefix=model_prefix,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gebench_accuracy_servers(
|
||||
request: pytest.FixtureRequest,
|
||||
run_level: str,
|
||||
model_prefix: str,
|
||||
) -> AccuracyServerConfig:
|
||||
return _build_accuracy_server_config(
|
||||
generate_model=request.config.getoption("gebench_model"),
|
||||
judge_model=request.config.getoption("accuracy_judge_model"),
|
||||
shared_gpu=str(request.config.getoption("accuracy_gpu")),
|
||||
port=int(request.config.getoption("gebench_port")),
|
||||
run_level=run_level,
|
||||
model_prefix=model_prefix,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gedit_accuracy_servers(
|
||||
request: pytest.FixtureRequest,
|
||||
run_level: str,
|
||||
model_prefix: str,
|
||||
) -> AccuracyServerConfig:
|
||||
return _build_accuracy_server_config(
|
||||
generate_model=request.config.getoption("gedit_model"),
|
||||
judge_model=request.config.getoption("accuracy_judge_model"),
|
||||
shared_gpu=str(request.config.getoption("accuracy_gpu")),
|
||||
port=int(request.config.getoption("gedit_port")),
|
||||
run_level=run_level,
|
||||
model_prefix=model_prefix,
|
||||
)
|
||||
@@ -0,0 +1,96 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from benchmarks.accuracy.text_to_image.gbench import main as gbench_main
|
||||
from tests.e2e.accuracy.conftest import infer_model_label, reset_artifact_dir
|
||||
from tests.utils import hardware_test
|
||||
|
||||
|
||||
@pytest.mark.advanced_model
|
||||
@pytest.mark.benchmark
|
||||
@pytest.mark.diffusion
|
||||
@hardware_test(res={"cuda": "H100"}, num_cards=1)
|
||||
def test_gebench_h100_smoke(
|
||||
gebench_accuracy_servers,
|
||||
accuracy_artifact_root: Path,
|
||||
gebench_dataset_root: Path,
|
||||
accuracy_workers: int,
|
||||
) -> None:
|
||||
model_label = infer_model_label(gebench_accuracy_servers.generate_params.model).lower()
|
||||
output_root = reset_artifact_dir(accuracy_artifact_root / f"gebench_{model_label}")
|
||||
|
||||
with gebench_accuracy_servers.generate_server() as generate_server:
|
||||
for data_type in ("type3", "type4"):
|
||||
assert (
|
||||
gbench_main(
|
||||
[
|
||||
"generate",
|
||||
"--dataset-root",
|
||||
str(gebench_dataset_root),
|
||||
"--output-root",
|
||||
str(output_root),
|
||||
"--base-url",
|
||||
f"http://{generate_server.host}:{generate_server.port}",
|
||||
"--model",
|
||||
generate_server.model,
|
||||
"--data-type",
|
||||
data_type,
|
||||
"--width",
|
||||
"768",
|
||||
"--height",
|
||||
"576",
|
||||
"--output-compression",
|
||||
"98",
|
||||
"--num-inference-steps",
|
||||
"8",
|
||||
"--workers",
|
||||
str(accuracy_workers),
|
||||
]
|
||||
)
|
||||
== 0
|
||||
)
|
||||
|
||||
with gebench_accuracy_servers.judge_server() as judge_server:
|
||||
for data_type in ("type3", "type4"):
|
||||
assert (
|
||||
gbench_main(
|
||||
[
|
||||
"evaluate",
|
||||
"--dataset-root",
|
||||
str(gebench_dataset_root),
|
||||
"--output-root",
|
||||
str(output_root),
|
||||
"--data-type",
|
||||
data_type,
|
||||
"--judge-base-url",
|
||||
f"http://{judge_server.host}:{judge_server.port}",
|
||||
"--judge-model",
|
||||
judge_server.model,
|
||||
"--judge-api-key",
|
||||
"EMPTY",
|
||||
"--workers",
|
||||
str(accuracy_workers),
|
||||
]
|
||||
)
|
||||
== 0
|
||||
)
|
||||
|
||||
assert gbench_main(["summarize", "--output-root", str(output_root)]) == 0
|
||||
|
||||
summary = json.loads((output_root / "summary.json").read_text(encoding="utf-8"))
|
||||
assert "generation" in summary
|
||||
assert "evaluation" in summary
|
||||
|
||||
for data_type in ("type3", "type4"):
|
||||
assert data_type in summary["generation"]["by_type"]
|
||||
assert summary["generation"]["by_type"][data_type]["count"] > 0
|
||||
assert data_type in summary["evaluation"]["by_type"]
|
||||
assert summary["evaluation"]["by_type"][data_type]["count"] > 0
|
||||
|
||||
assert summary["evaluation"]["overall_mean"] >= 0.45
|
||||
assert summary["evaluation"]["by_type"]["type3"]["overall_mean"] >= 0.45
|
||||
assert summary["evaluation"]["by_type"]["type4"]["overall_mean"] >= 0.45
|
||||
@@ -0,0 +1,114 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from benchmarks.accuracy.image_to_image.gedit_bench import GROUPS
|
||||
from benchmarks.accuracy.image_to_image.gedit_bench import main as gedit_main
|
||||
from tests.e2e.accuracy.conftest import infer_model_label, reset_artifact_dir
|
||||
from tests.utils import hardware_test
|
||||
|
||||
|
||||
@pytest.mark.advanced_model
|
||||
@pytest.mark.benchmark
|
||||
@pytest.mark.diffusion
|
||||
@hardware_test(res={"cuda": "H100"}, num_cards=1)
|
||||
def test_gedit_bench_h100_smoke(
|
||||
gedit_accuracy_servers,
|
||||
accuracy_artifact_root: Path,
|
||||
gedit_dataset_root: Path,
|
||||
gedit_samples_per_group: int,
|
||||
accuracy_workers: int,
|
||||
) -> None:
|
||||
model_label = infer_model_label(gedit_accuracy_servers.generate_params.model).lower()
|
||||
output_root = reset_artifact_dir(accuracy_artifact_root / f"gedit_results_{model_label}")
|
||||
score_root = reset_artifact_dir(accuracy_artifact_root / f"gedit_scores_{model_label}")
|
||||
model_name = model_label
|
||||
|
||||
with gedit_accuracy_servers.generate_server() as generate_server:
|
||||
assert (
|
||||
gedit_main(
|
||||
[
|
||||
"generate",
|
||||
"--dataset-ref",
|
||||
str(gedit_dataset_root),
|
||||
"--output-root",
|
||||
str(output_root),
|
||||
"--base-url",
|
||||
f"http://{generate_server.host}:{generate_server.port}",
|
||||
"--model",
|
||||
generate_server.model,
|
||||
"--model-name",
|
||||
model_name,
|
||||
"--task-type",
|
||||
"all",
|
||||
"--instruction-language",
|
||||
"all",
|
||||
"--samples-per-group",
|
||||
str(gedit_samples_per_group),
|
||||
"--workers",
|
||||
str(accuracy_workers),
|
||||
]
|
||||
)
|
||||
== 0
|
||||
)
|
||||
|
||||
with gedit_accuracy_servers.judge_server() as judge_server:
|
||||
assert (
|
||||
gedit_main(
|
||||
[
|
||||
"evaluate",
|
||||
"--dataset-ref",
|
||||
str(gedit_dataset_root),
|
||||
"--output-root",
|
||||
str(output_root),
|
||||
"--model-name",
|
||||
model_name,
|
||||
"--save-dir",
|
||||
str(score_root),
|
||||
"--task-type",
|
||||
"all",
|
||||
"--instruction-language",
|
||||
"all",
|
||||
"--judge-base-url",
|
||||
f"http://{judge_server.host}:{judge_server.port}",
|
||||
"--judge-model",
|
||||
judge_server.model,
|
||||
"--judge-api-key",
|
||||
"EMPTY",
|
||||
"--samples-per-group",
|
||||
str(gedit_samples_per_group),
|
||||
"--workers",
|
||||
str(accuracy_workers),
|
||||
]
|
||||
)
|
||||
== 0
|
||||
)
|
||||
|
||||
csv_path = score_root / f"{model_name}_all_all_vie_score.csv"
|
||||
assert gedit_main(["summarize", "--csv-path", str(csv_path), "--language", "all"]) == 0
|
||||
|
||||
summary_path = score_root / f"{model_name}_all_all_summary.json"
|
||||
summary = json.loads(summary_path.read_text(encoding="utf-8"))
|
||||
assert set(summary["languages"]) == {"en", "cn"}
|
||||
|
||||
for language in ["en", "cn"]:
|
||||
language_summary = summary["languages"][language]
|
||||
assert language_summary["overall"]["count"] is not None
|
||||
assert language_summary["intersection"]["count"] is not None
|
||||
assert language_summary["overall"]["Q_SC"] is not None
|
||||
assert language_summary["overall"]["Q_PQ"] is not None
|
||||
assert language_summary["overall"]["Q_O"] is not None
|
||||
|
||||
for group in GROUPS:
|
||||
group_summary = language_summary["by_group"][group]
|
||||
assert set(group_summary) == {"count", "Q_SC", "Q_PQ", "Q_O"}
|
||||
|
||||
assert summary["languages"]["en"]["overall"]["Q_SC"] >= 7.1
|
||||
assert summary["languages"]["en"]["overall"]["Q_PQ"] >= 5.9
|
||||
assert summary["languages"]["en"]["overall"]["Q_O"] >= 6.3
|
||||
assert summary["languages"]["cn"]["overall"]["Q_SC"] >= 7.0
|
||||
assert summary["languages"]["cn"]["overall"]["Q_PQ"] >= 5.8
|
||||
assert summary["languages"]["cn"]["overall"]["Q_O"] >= 6.2
|
||||
Reference in new issue
Block a user