用 pass@1 和 pass^k 测量智能体可靠性
在 Pi 1.0.4 上对着一个带种子的 85% 模拟模型运行 eval.ts:pass@1 读出 0.86,pass^5 读出 0.45,而它们之间的差距就是教训。
有三种活动都被叫作"测试":脚本化(你选定的一个响应)、结构化(对事件断言,而不是对措辞)和评估(整个东西在反复运行中多久成功一次)。本页是那个评估测试骨架——被摘录出来的 eval.ts 的测量部分——运行在 Pi 1.0.4 上。下面那个"模型"是一枚带种子的 85% 硬币,所以这测量的是那个测试骨架的算术,而不是任何 provider 的;本页的台账里不含任何真实模型的证据。
运行它
本章那个标准的 eval.ts 是一个自包含的文件(类型也在内);这些是它承重的部分。evaluate() 把每个任务运行 k 次,把一次抛出的运行算作一次失败,并返回那两个比率:
export async function evaluate<T>(tasks: Task<T>[], k: number, options: EvalOptions = {}): Promise<EvalResult> {
if (!Number.isInteger(k) || k < 1) throw new Error(`k must be a positive integer, got ${k}`);
if (!tasks.length) throw new Error("evaluate needs at least one task; an empty list has no rate to report");
const guard = options.timeout ?? defaultTimeout;
const budget = options.timeoutMs;
// Spread the budget over the runs, with a floor, so one run cannot consume the
// whole evaluation's allowance.
const perRun = budget ? Math.max(1, Math.floor(budget / (tasks.length * k))) : undefined;
let single = 0;
let allK = 0;
for (const task of tasks) {
let wins = 0;
for (let i = 0; i < k; i++) {
try {
const result = perRun ? await guard(() => task.run(), perRun) : await task.run();
if (task.passes(result as T)) wins++;
} catch {
// A step that throws, or times out, is a failed run. Not a crashed
// evaluation: the point of pass^k is that a run which did not work
// counts against the task, and a timeout is exactly that.
}
}
single += wins / k;
if (wins === k) allK++;
}
return { tasks: tasks.length, k, passAt1: single / tasks.length, passPowK: allK / tasks.length };
}seeded() 给一个模拟的模型确定性的伪随机性,所以这个评估是可复现的——一次真实的运行会改为调用 provider:
// Deterministic pseudo-randomness, so an evaluation of a *simulated* model is repeatable.
export function seeded(seed: number): () => number {
let a = seed >>> 0;
return () => {
a = (a + 0x6d2b79f5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}预期结果
testing.test.ts 从一个 85% 的时候为对的模拟模型构建出 40 个任务,以种子 42 把每个任务运行 k = 5 次,并锁定两个数字(已观察):
pass@1 = 0.86
pass^5 = 0.45pass@1 是单次运行的平均比率——一个演示所报告的东西。pass^5 是在全部五次运行上都成功的那些任务所占的比例——一个服务所需要的东西。对于每次都以概率 p 独立的运行,全 k 成功就是 p^k:0.85⁵ ≈ 0.44,正是那个模拟产出的结果。可靠性向下复合,而平均值掩盖了它。一个抛出的(或超时的)步骤是一次失败的运行,而不是一次崩溃:第二个评估测试断言,在一次抛出之后运行次数保持为 5。
机制与局限
**有文档记载:**那个 faux provider 及其响应工厂(pi-ai README 与声明,1.0.4)。已观察:testing.test.ts 里的那四个测试——尤其是那两个被锁定的数字,它们是这个模拟的性质,而不是任何真实模型的。**本书提出:**这三级的区分、一次有意义的评估的那些规则(记录模型和日期、用你没有在其上调过参的情形、把要紧的那些失败包含进来),以及摊到那些运行上的 timeoutMs 预算。
把那个带种子的 run 换成一个真实 provider,凭据和账单就是从这里进来的;这两样在这里都不存在,而没有任何东西估计一个真实模型的 pass^k。
Understand this example
Copy this prompt into your AI tool. No code runs here.
Apply this example
Copy this prompt into your AI tool. No code runs here.