File size: 3,538 Bytes
f730521 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | """Reference arm for the benchmark: the same 100 questions sent straight to the baseline
with the reply opened by "<think>\\n" (the released reasoning examples), text out, no speech.
It answers one question the endpoint arms cannot: how much of the reasoning score is lost
when the model is asked to speak ("<tts_start>") instead of think. Same system prompt and
same scorer as eval/eval_bba.py, so the three arms compare with each other only.
python -m eval.eval_bba_text --data eval/data/bba --out eval/results/bba
"""
import argparse
import asyncio
import json
import time
from collections import defaultdict
from pathlib import Path
import aiohttp
from duplex.spec import write_json
from eval.eval_bba import SYSTEM, parse_answer
from eval.ws_client import load_16k, percentiles
from serving.baseline_client import human_turn, stream_chat
async def ask(http, args, q, sem, out):
pcm = load_16k(Path(args.data) / f"q_{q['id']}.wav")
messages = [{"role": "system", "content": SYSTEM}, human_turn(pcm), {"role": "assistant", "content": "<think>\n", "eot": False}]
text, error = "", None
async with sem:
t0 = time.perf_counter()
try:
async for _, t, _ in stream_chat(http, args.api_url, args.model, messages, max_tokens=args.max_tokens, temperature=0.7,
repetition_penalty=1.0, stop_token_ids=[151665]):
text += t
except Exception as e:
error = repr(e)
seconds = time.perf_counter() - t0
answer, official = parse_answer(text, q["official_answer"]) if "</think>" in text else (None, q["official_answer"].strip().lower())
row = {"id": q["id"], "category": q["category"], "official_answer": official, "answer": answer, "correct": answer is not None and answer == official,
"finished_thinking": "</think>" in text, "seconds": seconds, "text": text, "error": error}
write_json(out / f"q_{q['id']}.json", row)
return row
async def main():
ap = argparse.ArgumentParser()
ap.add_argument("--api-url", default="http://127.0.0.1:9999/v1/chat/completions")
ap.add_argument("--model", default="Step-Audio-R1.1")
ap.add_argument("--data", default="eval/data/bba")
ap.add_argument("--out", default="eval/results/bba")
ap.add_argument("--concurrency", type=int, default=8)
ap.add_argument("--max-tokens", type=int, default=8192)
args = ap.parse_args()
subset = json.loads((Path(args.data) / "subset.json").read_text())
out = Path(args.out) / "think_text"
out.mkdir(parents=True, exist_ok=True)
sem = asyncio.Semaphore(args.concurrency)
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=None)) as http:
rows = await asyncio.gather(*[ask(http, args, q, sem, out) for q in subset])
by_cat = defaultdict(list)
for r in rows:
by_cat[r["category"]].append(r["correct"])
summary = {"questions": len(rows), "think_text": {
"accuracy": sum(r["correct"] for r in rows) / len(rows),
"accuracy_by_category": {c: sum(v) / len(v) for c, v in sorted(by_cat.items())},
"finished_thinking": sum(r["finished_thinking"] for r in rows), "no_answer_found": sum(r["answer"] is None for r in rows),
"errors": sum(bool(r["error"]) for r in rows), "seconds_to_full_answer": percentiles([r["seconds"] for r in rows]),
}}
write_json(Path(args.out) / "summary_think_text.json", summary)
print(json.dumps(summary))
if __name__ == "__main__":
asyncio.run(main())
|