diff --git a/docs/benchmarks.md b/docs/benchmarks.md index b1c0be3..62fcaf1 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -43,10 +43,26 @@ | 结构化输出 | `json-strict` | JSON Schema 约束解码 | grammar 对 TTFT/TPOT 的影响 | | 长上下文 | `needle-32k` | 约 32K 填充 + 中段检索 | prefill 规模对 TTFT | | 长上下文 | `needle-128k` | 约 128K 填充 + 中段检索 | 更大的 prefill 规模 | +| Agent 单轮 | `agent-turn` | 约 67K 填充 + 约 400 token 输出 | 真实 agent 形态:长输入、中等输出 | | 多轮缓存 | `multiturn` | 三轮共享前缀 | 前缀缓存对第 2、3 轮 TTFT 的收益 | `needle-*` 的填充段落由 `bench.py` 内的中性文本生成,检索目标是虚构校准码,不含业务数据。 -`needle-128k` 会占用较多 KV,**在共享或生产服务上应谨慎或跳过**。 +`needle-128k` 与 `agent-turn` 会占用较多 KV,**在共享或生产服务上应谨慎或跳过**。 + +填充长度从 token 目标反推字符数,而中英混合文本的字符/token 比例取决于 tokenizer:同一份 +用例在不同引擎上可能偏离目标一两成。**用例名只是量级,真实长度以收据里的 `prompt_tokens` +为准**。 + +## 合成用例与真实负载的差距 + +基准里的短用例(几十到几百 token 输入)和线上的 agent 请求不是一回事。真实 agent 一轮 +往往带着数万到数十万 token 的上下文进来,输入规模会明显改变每 token 时间:解码阶段每步都要 +扫过全部 KV,上下文越长单步越慢。 + +因此**只跑短用例会高估实际负载下的解码速度**。评估一个要用于 agent 后端的部署时,至少用 +`agent-turn` 这类长输入 + 中等输出的用例复测一次;如果知道线上请求的长度分布,按分布的 +分位数取值构造几档更有意义。仓内 `agent-turn` 的输入量级刻意贴近常见 agent 单轮,但任何 +固定用例都不能替代自己环境里的真实分布。 ## 运行方法 diff --git a/tools/bench/bench.py b/tools/bench/bench.py index 4c1738e..fbbb8b1 100644 --- a/tools/bench/bench.py +++ b/tools/bench/bench.py @@ -64,8 +64,13 @@ def read_snippet(name): def build_haystack(spec): - """Place a needle in the middle of generated filler of roughly the asked size.""" - haystack_chars = max(1, int(spec['tokens'] * 1.6)) + """Place a needle in the middle of generated filler of roughly the asked size. + + FILLER is mixed Chinese/English and measures about 2.9 characters per token + on this tokenizer family. The factor is a calibration, not a guarantee: + always report the server's own prompt_tokens, which every receipt keeps. + """ + haystack_chars = max(1, int(spec['tokens'] * 2.92)) repeats = max(1, haystack_chars // len(FILLER)) body = FILLER * repeats needle = spec['needle'] diff --git a/tools/bench/cases/15-agent-turn.json b/tools/bench/cases/15-agent-turn.json new file mode 100644 index 0000000..5871c3d --- /dev/null +++ b/tools/bench/cases/15-agent-turn.json @@ -0,0 +1,19 @@ +{ + "schema": 2, + "id": "agent-turn", + "title": "Agent 单轮(长输入 + 中等输出)", + "kind": "agent", + "max_tokens": 700, + "temperature": 0, + "note": "长度刻意贴合真实 agent 请求的中间态:输入数万 token、输出数百 token。短 prompt 用例会低估实际负载下的每 token 时间,本用例用于补齐这一段。", + "haystack": { + "tokens": 67000, + "needle": "维护窗口记录:本次变更只允许在 02:00 至 04:00 之间执行,回滚命令为 deploy rollback --to rev-1183。" + }, + "messages": [ + { + "role": "user", + "content": "{haystack}\n\n以上是一份运维资料。请基于它回答三点,每点两三句话:\n1) 允许的维护窗口是什么;\n2) 出问题时的回滚动作是什么;\n3) 如果要提前完成,还需要确认哪些信息。\n\n不要复述资料原文,不要罗列无关内容。" + } + ] +}