跳转到内容

性能实验实战

以下命令适用于 Bash 或 Zsh。先完成CLI 登录,将 pilot 换成你的项目 slug。已安装 jq 和 Python 3。

下载单次实验 JSON,保存为 benchmark.json,替换 endpoint_url、model 和实验名称。初始参数是并发 1、请求数 40、输入 256 tokens、输出 64 tokens。

硬件和运行时字段留空表示未知,应按事实补充。不要把示例值当作已采集的环境信息。

需要鉴权时,通过隐藏输入设置变量,避免将 Key 写进示例 JSON:

终端窗口
export MODEL_API_KEY="$(python3 -c 'import getpass; print(getpass.getpass("Model API Key: "))')"

下面的 --api-key-env MODEL_API_KEY 传入的是环境变量名称。无需鉴权的服务省略该参数即可。

终端窗口
umask 077
discernctl benchmark create --project pilot --file benchmark.json \
--api-key-env MODEL_API_KEY --output json > benchmark-created.json
benchmark_id=$(jq -er '.data.benchmark_id' benchmark-created.json)
discernctl benchmark get "$benchmark_id" --project pilot --output json

单次创建没有幂等保证。网络中断、无法确认提交结果时,先查看 benchmark list,再决定是否创建新实验。

4. 跟踪日志并等待结果

跳转到「4. 跟踪日志并等待结果」
终端窗口
discernctl benchmark logs "$benchmark_id" --project pilot --follow
discernctl benchmark wait "$benchmark_id" --project pilot \
--timeout 30m --poll 2s --output json
discernctl benchmark get "$benchmark_id" --project pilot --output json \
> benchmark-result.json
jq '.data | {benchmark_id, status, metrics}' benchmark-result.json

日志只保留最近 64 KiB。--follow --output json 按变化输出 NDJSON,不是单个 JSON 文档。

get 和日志读取成功返回 0,即使远端实验失败。需要用任务结果控制脚本时,使用 wait 并保留其退出码。

终端窗口
discernctl benchmark list --project pilot --status SUCCEEDED --limit 20 --output json
discernctl benchmark cancel "$benchmark_id" --project pilot

列表返回分页元信息;有下一页时,将 meta.next_cursor 传给 --cursor。日期边界使用 RFC3339,开始包含、结束不包含。

等待超时或 Ctrl-C 默认只停止本机等待,远端继续运行。--cancel-on-interrupt 仅在用户中断时请求取消,超时不会取消任务。

重试实验需要新建请求并填写 retry_of,再次提供凭据。原实验的 API Key 不会回填。

继续阅读多实验编排与 CI,批量执行不同负载。