Code view
Error bars on an LLM eval
The study's statistics and its determinism fixes, read in the code: the paired difference behind Gemma's lead, the split of variance into prompt draw and rerun noise, the flip rate, and the reseeded grader.
Every number on the study page is produced by functions in studies/ifeval_error_bars of the private ml_research repo. The excerpts are trimmed to the code; comments and docstrings are left out, and line numbers are the file's own.
01One answer per prompt, paired
The headline test, H1, compares the two models on the same 541 prompts. Each prompt gives a difference d of −1, 0 or +1: Gemma right and Qwen wrong, both the same, or the reverse. Gemma's lead is the mean of d.
def paired_clt(d: Sequence[float], *, alpha: float = ALPHA) -> PairedCLTResult: import numpy as np arr = np.asarray(d, dtype=float) n = int(arr.size) nan = float("nan") if n == 0: return PairedCLTResult(delta=nan, se=nan, ci_low=nan, ci_high=nan, n=0) delta = float(arr.mean()) if n < 2: return PairedCLTResult(delta=delta, se=nan, ci_low=nan, ci_high=nan, n=n) se = float(arr.std(ddof=1) / math.sqrt(n)) z = _z(1 - alpha / 2) return PairedCLTResult(delta=delta, se=se, ci_low=delta - z * se, ci_high=delta + z * se, n=n)02The error bar is the paired CLT
The standard error is just sd(d)/√n, and the 95% interval is Δ ± 1.96 SE. That gives 15.7 points, from 11.7 to 19.7: about ±4.
if n < 2: return PairedCLTResult(delta=delta, se=nan, ci_low=nan, ci_high=nan, n=n) se = float(arr.std(ddof=1) / math.sqrt(n)) z = _z(1 - alpha / 2) return PairedCLTResult(delta=delta, se=se, ci_low=delta - z * se, ci_high=delta + z * se, n=n)03What pairing buys
The models tend to get the same prompts right or wrong, so their verdicts are correlated, and that correlation cancels out of the paired SE. unpaired_se is computed only for comparison, so the page can show what treating the two runs as independent would have cost.
def unpaired_se(p_a: float, p_b: float, n: int) -> float: if n <= 0: return float("nan") return math.sqrt(p_a * (1 - p_a) / n + p_b * (1 - p_b) / n)def verdict_correlation(a: Sequence[int], b: Sequence[int]) -> float: import numpy as np av, bv = np.asarray(a, dtype=float), np.asarray(b, dtype=float) if av.size < 2 or av.std() == 0 or bv.std() == 0: return float("nan") return float(np.corrcoef(av, bv)[0, 1])04H1 assembles it
h1 pairs the records by prompt, computes d, and runs the paired CLT. It reports the unpaired SE, the correlation and an exact McNemar test beside the main result. It reports them only as checks. The decision rests on the CI alone: whether it excludes zero.
def h1( q_records: Sequence[PassRecord], g_records: Sequence[PassRecord], *, flip_rate_q: float | None = None, flip_rate_g: float | None = None,) -> H1Result: pairs = paired_by_prompt(q_records, g_records) n = len(pairs) d = [int(bool(g.strict_follow_all)) - int(bool(q.strict_follow_all)) for q, g in pairs] pc = paired_clt(d) if n: p_q = sum(int(bool(q.strict_follow_all)) for q, _ in pairs) / n p_g = sum(int(bool(g.strict_follow_all)) for _, g in pairs) / n u_se = unpaired_se(p_q, p_g, n) corr = verdict_correlation( [int(bool(q.strict_follow_all)) for q, _ in pairs], [int(bool(g.strict_follow_all)) for _, g in pairs], ) b = sum(1 for q, g in pairs if q.strict_follow_all and not g.strict_follow_all) c = sum(1 for q, g in pairs if not q.strict_follow_all and g.strict_follow_all) mcnemar_p = mcnemar_exact(b, c) else: u_se = corr = mcnemar_p = float("nan") decision = ( f"different (CI excludes 0, n={n})" if math.isfinite(pc.ci_low) and (pc.ci_low > 0 or pc.ci_high < 0) else f"no detectable difference at n={n}" ) evt = ( engine_variance_term(flip_rate_q, flip_rate_g, n) if flip_rate_q is not None and flip_rate_g is not None else None ) return H1Result( delta=pc.delta, se=pc.se, ci_low=pc.ci_low, ci_high=pc.ci_high, n=n, decision=decision, unpaired_se=u_se, correlation=corr, mcnemar_p=mcnemar_p, engine_variance_term=evt, )05Splitting the variance: prompt draw vs. sampling
With K samples per prompt, each prompt has a sampled accuracy p̂. Their variance splits into a between-prompt term, which is the luck of which prompts the benchmark holds, and a within-prompt term, which is the noise of sampling the same prompt again. The −within/(K−1) correction removes the sampling noise from the between term. This is the decomposition behind "about 78% is the luck of the draw."
def s3_decomposition(p_hat: Sequence[float], k: int) -> S3Result: import numpy as np p = np.asarray(p_hat, dtype=float) n = int(p.size) if n < 2 or k < 2: return S3Result( between=float("nan"), within=float("nan"), clipped=False, se_at_k=float("nan"), se_at_1=float("nan"), k_threshold=None, n=n, k=k, ) var_p = float(p.var(ddof=1)) within_mean = float(np.mean(p * (1 - p))) between_raw = var_p - within_mean / (k - 1) clipped = between_raw < 0 between = max(between_raw, 0.0) within = float(np.mean(p * (1 - p) * k / (k - 1))) se_at_k = float(p.std(ddof=1) / math.sqrt(n)) se_at_1 = float(math.sqrt(between + within) / math.sqrt(n)) threshold = None if clipped else se_k_threshold(between, within) return S3Result( between=between, within=within, clipped=clipped, se_at_k=se_at_k, se_at_1=se_at_1, k_threshold=threshold, n=n, k=k, )06How much would more reruns help?
se_k_threshold finds the K past which one more sample per prompt cuts the SE by less than 1%. Averaging reruns only shrinks the within term, so the error bar bottoms out at the between term. That floor is why it only goes from ±4.0 to ±3.5.
def se_k_threshold(between: float, within: float, *, max_k: int = 10_000) -> int | None: if between <= 0 or within <= 0: return None se_k = math.sqrt(between + within) k = 1 while k < max_k: se_next = math.sqrt(between + within / (k + 1)) if se_k == 0: return k if (se_k - se_next) / se_k < 0.01: return k se_k = se_next k += 1 return None@dataclass(frozen=True)07The rerun flip rate
Running the same greedy eval twice gives each prompt a delta of −1, 0 or +1 between runs. The flip rate f is the share that changed. For Qwen it was 7.2%, with a Wilson interval because it is a proportion.
rerun_se_share turns f into the rerun noise's share of the error bar. The √n cancels, so the share doesn't depend on how many prompts there are.
def flip_rate_and_movement(delta: Sequence[int]) -> FlipRateResult: import numpy as np d = np.asarray(delta, dtype=float) n = int(d.size) if n == 0: return FlipRateResult( flip_rate=float("nan"), ci_low=float("nan"), ci_high=float("nan"), delta_rep=float("nan"), delta_rep_se=float("nan"), n=0, ) flips = int(np.sum(d != 0)) f = flips / n lo, hi = wilson_interval(flips, n) delta_rep = float(d.mean()) se = float(d.std(ddof=1) / math.sqrt(n)) if n > 1 else float("nan") return FlipRateResult( flip_rate=f, ci_low=lo, ci_high=hi, delta_rep=delta_rep, delta_rep_se=se, n=n )def rerun_se_share(f: float, p_hat: float) -> float: denom = p_hat * (1 - p_hat) if denom <= 0: return float("nan") return math.sqrt(f / (2 * denom))08Batch-invariant mode, requested, not confirmed
The rerun-noise arm (C′) reran with VLLM_BATCH_INVARIANT=1, and its reruns matched exactly. The engine code is honest about what that flag proves. vLLM logs no confirmation that the invariant kernels are active, so this check only gathers a log line for a person to read. It is never a gate.
if "VLLM_BATCH_INVARIANT" not in spec.env: return None for line in log_text.splitlines(): lowered = line.lower() if "batch" in lowered and "invarian" in lowered: return line.strip() return None09The grader was random too
IFEval's official checkers reach two unseeded random number generators: langdetect's, and Python's own random module, through the letter-frequency check's fallback. The study's wrapper reseeds both before every scoring call. That makes a verdict a pure function of the prompt, the response and the instruction arguments. A lock keeps a future parallel caller from interleaving reseeds.
SCORER_SEED = 0_lock = threading.RLock()def _reseed() -> None: detector_factory, _ = _vendor() detector_factory.seed = SCORER_SEED random.seed(SCORER_SEED)10Every run checks itself
Before a cell's results count, it scores a vendored 20-example bundle and compares the verdicts to stored ones. A pod whose scorer, NLTK data or langdetect seeding differs fails this gate clause instead of quietly producing different numbers.
def selfcheck_bundle_passes(score: Callable[..., Any]) -> bool: from importlib import resources try: bundle = json.loads( resources.files("mlr_ifeval_error_bars") .joinpath("data", "selfcheck_bundle.json") .read_text() ) except Exception: return False if not bundle: return False for record in bundle: try: verdict = score( prompt=record["prompt"], instruction_id_list=record["instruction_id_list"], kwargs=record["kwargs"], response=record["response"], ) except Exception: return False want_strict_list = record["strict_follow_instruction_list"] want_loose_list = record["loose_follow_instruction_list"] if ( verdict.strict_follow_all != record["strict_follow_all"] or list(verdict.strict_follow_instruction_list) != want_strict_list or verdict.loose_follow_all != record["loose_follow_all"] or list(verdict.loose_follow_instruction_list) != want_loose_list ): return False return True