What does pass@k measure and how is it computed to reduce variance?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
pass@k is the chance at least one of k code samples passes the unit tests. The unbiased estimator generates n more than k samples, counts c passes, and computes the probability in closed form for low variance.
Imagine a student who gets several tries to solve a puzzle, and they pass if any single attempt works. pass@k asks: with k tries, what is the chance at least one succeeds? You could just hand them k attempts and see, but that is noisy. A lucky or unlucky batch swings the number a lot. So instead you let them make many attempts, count how many actually worked, and then do the math for how likely k random tries would include a winner. Using every attempt you collected gives a far steadier number than judging from one small handful. Same idea code-eval teams use to grade a model on programming problems.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: define pass@k as best of k functional correctness, derive the oversampling unbiased estimator, cover numerical stability, temperature interaction, and what the metric cannot see.
import numpy as np
def pass_at_k(n: int, c: int, k: int) -> float:
# n = samples generated, c = samples that passed, k = budget
if n - c < k:
return 1.0
# 1 - product form of C(n-c, k) / C(n, k), numerically stable
return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1, n + 1))Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Generating exactly k samples and reporting the raw hit rate. That estimate has high variance. Generate n more than k, count passes, and use the closed-form estimator instead.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.