The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Evaluation harness: the promote rule judges each look on its own, clips included
Claudec4d38686399b
diff --git a/scripts/eval/README.md b/scripts/eval/README.mdindex 3a346986..c8b4575f 100644--- a/scripts/eval/README.md+++ b/scripts/eval/README.md@@ -306,8 +306,9 @@ needs people's ratings.page shows two results side by side. Their order comes from a hash, and nothing on the page namesthe variant, model or file.-- `--against variants` is the default when the run has two or more variants. It pairs the first- variant with each of the others on the same case, prompt and seed.+- `--against variants` is the default when the run has two or more variants. It pairs the run's+ candidate (see [the promote rule](#the-promote-rule)) with each of the others on the same case,+ prompt and seed.- `--against references` is the default otherwise. It pairs each output with one of your referencesfrom `local/references/…`.- `--against <otherRunId>` pairs the same jobs across two runs, for example before and after a@@ -336,21 +337,28 @@ check can't pass just because the metric never ran. Every report appends its per## The promote rule-A recipe (the candidate variant, `recipe` by default) is **eligible** to become a look's default-only when one run, on the same prompts and seeds, shows all of the following:+The candidate is the variant a suite names in `defaults.candidate` (DoP: `research`), else `recipe`+when the run has it, else the run's first variant; `--candidate` picks another. It is **eligible** to+become the default only when one run, on the same prompts and seeds, shows all of the following for+the case:1. **Licence**: every LoRA it loaded is commercial, and is hostable when the run is on the cloud.- None of the recipe's LoRAs was left out on that engine.-2. **Enough results**: at least 3 for the look.+ None of the recipe's LoRAs was left out on that engine. A licence problem holds the recipe whatever+ else won.+2. **Enough results**: at least 3 for the case.3. **Metrics**: against every alternative in the run (prompt only, half strength, the bare base,- today's default), it scores at least as well on the look's main metric. That is style when the- look has references, else aesthetic. It also gives up no more than 1.0 CLIP or 0.15 aesthetic.-4. **People**: at least 6 blind ratings against the alternatives, with at least 55 % of the non-tie- ratings going to the candidate.+ today's default), it scores at least as well on the case's main metric: the first of style (a look+ with references), lip-sync, identity, aesthetic, CLIP (a DoP motion's words) and warp error that the+ case has scores for. It also gives up no more than 1.0 CLIP, 0.15 aesthetic, and on clips 0.002 warp+ error and 0.004 drift.+4. **People**: at least 6 blind ratings of this case's own pairs against the alternatives (every pair+ the review offered, when it offered fewer), with at least 55 % of the non-tie ratings going to the+ candidate. Ratings of other looks don't count.If half strength wins, the verdict is **lower strengths**, not another recipe: the LoRAs over-cook,-so lower them in the research JSON and run again. Demo runs never promote anything. A run on one-engine says to check the other engine too.+so lower them in the research JSON and run again. When the candidate and an alternative ran on+different endpoints (fal's Z-Image runs LoRAs on `/lora`), the verdict says so. Demo runs never+promote anything. A run on one engine says to check the other engine too.`pnpm eval:promote <runId>` writes `promote.json`. `--record` also writes each case's verdict intothe research JSON (`docs/research/fuobe-originals-recipes-5.json`). The verdict goes in the `eval`diff --git a/scripts/eval/cases/case.schema.json b/scripts/eval/cases/case.schema.jsonindex 101c4735..11778139 100644--- a/scripts/eval/cases/case.schema.json+++ b/scripts/eval/cases/case.schema.json@@ -538,6 +538,10 @@"type": "string","pattern": "^[a-z0-9][a-z0-9-]*$"},+ "candidate": {+ "type": "string",+ "pattern": "^[a-z0-9][a-z0-9-]*$"+ },"timeoutSeconds": {"default": 1800,"type": "number",diff --git a/scripts/eval/cases/dop.json b/scripts/eval/cases/dop.jsonindex fcae9520..15204cab 100644--- a/scripts/eval/cases/dop.json+++ b/scripts/eval/cases/dop.json@@ -51,6 +51,7 @@"clip"],"variant": "catalog",+ "candidate": "research","timeoutSeconds": 2700},"variants": {diff --git a/scripts/eval/gen-cases.mjs b/scripts/eval/gen-cases.mjsindex 57fbde97..a908a60c 100644--- a/scripts/eval/gen-cases.mjs+++ b/scripts/eval/gen-cases.mjs@@ -142,6 +142,7 @@ function dopSuite() {prompts: [{ id: "bridge", text: "a woman in a red coat on a city bridge at golden hour" }],metrics: ["temporal", "clip"],variant: "catalog",+ candidate: "research",timeoutSeconds: 2700,},variants: {diff --git a/scripts/eval/lib/compare.mjs b/scripts/eval/lib/compare.mjsindex 8be0a7d1..1d4e46fa 100644--- a/scripts/eval/lib/compare.mjs+++ b/scripts/eval/lib/compare.mjs@@ -13,7 +13,7 @@ import path from "node:path";import { fmt, gain, METRIC_INFO, METRIC_ORDER, verdict } from "./metric-info.mjs";import { jobScores, loadRun } from "./report.mjs";import { aggregateRatings } from "./review.mjs";-import { writeJson } from "./store.mjs";+import { candidateOf, writeJson } from "./store.mjs";const mean = (xs) => {const v = xs.filter((x) => typeof x === "number" && !Number.isNaN(x));@@ -151,25 +151,38 @@ export function compareText(c) {* with the same prompts and seeds:* 1. its licence allows it: every LoRA it loaded is commercial, hostable when the run is on the* cloud, and none of the recipe's LoRAs was left out on this engine;- * 2. it made at least `minJobs` results for the look;+ * 2. it made at least `minJobs` results for the case;* 3. against every alternative in the run (prompt only, half strength, the bare base, today's- * default…) it scores at least as well on the look's main metric (style when the look has- * references, else aesthetic), and it doesn't give up more than 1.0 CLIP or 0.15 aesthetic;- * 4. people prefer it in a blind review: at least `minRatings` ratings against the alternatives,- * and at least 55% of the non-tie ones for the candidate.- * Half strength beating the full recipe means the LoRAs over-cook: lower them (and run again).- * Passing the rule makes a recipe eligible; the catalog default is still changed by hand, in a- * reviewed commit, on both engines.+ * default…) it scores at least as well on the case's main metric, and gives up no more than the+ * guards allow on the others (CLIP, aesthetic, and on clips the warp error and drift). The main+ * metric is the first the case has scores for, in MAIN_METRICS order: style when it has references,+ * lip-sync and identity where those are measured, then aesthetic, then CLIP (a DoP motion's+ * words), then warp error;+ * 4. people prefer it in a blind review of this case's own pictures: at least `minRatings` ratings+ * against the alternatives (every pair the review offered when it offered fewer), and at least+ * `minPreference` of the non-tie ones for the candidate.+ * Half strength beating the full recipe means the LoRAs over-cook: lower them (and run again). A licence+ * problem holds the recipe whatever else happened. Passing the rule makes a recipe eligible; the catalog+ * default is still changed by hand, in a reviewed commit, on both engines.*/-export const PROMOTE_RULE = { minJobs: 3, clipGuard: 1.0, aestheticGuard: 0.15, minRatings: 6, minPreference: 0.55 };+export const PROMOTE_RULE = { minJobs: 3, clipGuard: 1.0, aestheticGuard: 0.15, warpGuard: 0.002, driftGuard: 0.004, minRatings: 6, minPreference: 0.55 };++/** The metrics a case is judged on, most specific first (see PROMOTE_RULE). */+export const MAIN_METRICS = ["style", "lipsync", "identity", "aesthetic", "clip", "warp"];++/** b is at least as good as a on `metric` (each metric's own direction). */+const atLeast = (metric, b, a) => (METRIC_INFO[metric]?.better === "lower" ? b <= a : b >= a);+/** How much worse b is than a on `metric` (positive: worse). */+const worseBy = (metric, b, a) => (METRIC_INFO[metric]?.better === "lower" ? b - a : a - b);export function promote(dir, { candidate, alternatives, rule = PROMOTE_RULE } = {}) {+ rule = { ...PROMOTE_RULE, ...rule };const L = loadRun(dir);const variants = L.run.variants ?? [...new Set(L.rows.map((r) => r.variant))];- const cand = candidate ?? variants[0];+ const cand = candidate ?? candidateOf(L.run, variants);if (!variants.includes(cand)) throw new Error(`The run has no variant “${cand}” (it has ${variants.join(", ")})`);const alts = (alternatives?.length ? alternatives : variants.filter((v) => v !== cand)).filter((v) => variants.includes(v));- const ratings = aggregateRatings(L);+ const guards = { clip: rule.clipGuard, aesthetic: rule.aestheticGuard, warp: rule.warpGuard, drift: rule.driftGuard };const results = [];for (const caseId of [...new Set(L.rows.map((r) => r.caseId))]) {const rows = L.rows.filter((r) => r.caseId === caseId);@@ -177,9 +190,11 @@ export function promote(dir, { candidate, alternatives, rule = PROMOTE_RULE } =const ok = mine.filter((r) => r.status === "succeeded");const scoresOf = (list) => list.map((r) => jobScores(r, L.metrics));const m = (list, k) => mean(scoresOf(list).map((s) => s[k]));+ /** Licence problems hold a recipe whatever the scores say; the rest can be fixed by another run. */+ const licence = [];const reasons = [];const notes = [];- let verdictText;+ let overcooked = false;/** The strengths a winning half-strength variant ran at: what the record suggests. */let suggested = null;const recipe = ok[0]?.recipe ?? mine[0]?.recipe;@@ -188,42 +203,61 @@ export function promote(dir, { candidate, alternatives, rule = PROMOTE_RULE } =const lib = new Map((recipe?.loras ?? []).map((l) => [l.file, l]));const nonCommercial = applied.filter((l) => lib.get(l.file)?.commercial === false);const notHostable = L.run.engine === "cloud" ? applied.filter((l) => lib.get(l.file)?.hostedOk === false) : [];- if (recipe?.commercialOk === false || nonCommercial.length) reasons.push(`non-commercial LoRA${nonCommercial.length > 1 ? "s" : ""}: ${nonCommercial.map((l) => l.file).join(", ") || "the recipe is flagged"}`);- if (notHostable.length) reasons.push(`not allowed on hosted services: ${notHostable.map((l) => l.file).join(", ")}`);+ if (recipe?.commercialOk === false || nonCommercial.length) licence.push(`non-commercial LoRA${nonCommercial.length > 1 ? "s" : ""}: ${nonCommercial.map((l) => l.file).join(", ") || "the recipe is flagged"}`);+ if (notHostable.length) licence.push(`not allowed on hosted services: ${notHostable.map((l) => l.file).join(", ")}`);if (mine.some((r) => r.recipe?.complete === false || r.recipe?.sent?.complete === false)) reasons.push("some of the recipe's LoRAs were left out on this engine, so this isn't the recipe");// 2. enough resultsif (ok.length < rule.minJobs) reasons.push(`${ok.length} result${ok.length === 1 ? "" : "s"}, the rule wants ${rule.minJobs}`);// 3. metrics against each alternative- const main = scoresOf(ok).some((s) => s.style != null) ? "style" : "aesthetic";+ const main = MAIN_METRICS.find((k) => scoresOf(ok).some((x) => typeof x[k] === "number")) ?? null;+ if (ok.length && !main) reasons.push("no scores to judge it by (run pnpm eval:report)");const against = [];+ const endpointsOf = (list) => [...new Set(list.map((r) => r.route?.endpoint).filter(Boolean))];for (const alt of alts) {const theirs = rows.filter((r) => r.variant === alt && r.status === "succeeded");if (!theirs.length) continue;- const row = { variant: alt, [main]: { candidate: m(ok, main), alternative: m(theirs, main) }, clip: { candidate: m(ok, "clip"), alternative: m(theirs, "clip") }, aesthetic: { candidate: m(ok, "aesthetic"), alternative: m(theirs, "aesthetic") } };+ const row = { variant: alt };+ for (const k of [...new Set([main, "clip", "aesthetic", "warp", "drift"].filter(Boolean))]) {+ const pair = { candidate: m(ok, k), alternative: m(theirs, k) };+ if (pair.candidate != null || pair.alternative != null) row[k] = pair;+ }against.push(row);- const mc = row[main];- if (mc.candidate == null || mc.alternative == null) reasons.push(`no ${main} scores against ${alt} (run pnpm eval:report)`);- else if (mc.candidate < mc.alternative) {- reasons.push(`${alt} scores higher on ${main} (${fmt(main, mc.alternative)} vs ${fmt(main, mc.candidate)})`);+ const mc = main ? row[main] : null;+ if (main && (mc?.candidate == null || mc?.alternative == null)) reasons.push(`no ${main} scores against ${alt} (run pnpm eval:report)`);+ else if (main && !atLeast(main, mc.candidate, mc.alternative)) {+ reasons.push(`${alt} scores better on ${main} (${fmt(main, mc.alternative)} vs ${fmt(main, mc.candidate)})`);if (/half/.test(alt)) {+ overcooked = true;notes.push("half strength wins: the LoRAs over-cook here — lower their strengths in the research JSON and run again");suggested = (theirs[0].recipe?.applied ?? theirs[0].recipe?.sent?.loras ?? []).map((l) => ({ file: l.file, strength: l.strength ?? 1 }));}}- if (row.clip.candidate != null && row.clip.alternative != null && row.clip.candidate < row.clip.alternative - rule.clipGuard) reasons.push(`it follows the prompt worse than ${alt} (CLIP ${fmt("clip", row.clip.candidate)} vs ${fmt("clip", row.clip.alternative)})`);- if (main !== "aesthetic" && row.aesthetic.candidate != null && row.aesthetic.alternative != null && row.aesthetic.candidate < row.aesthetic.alternative - rule.aestheticGuard) reasons.push(`it looks worse than ${alt} (aesthetic ${fmt("aesthetic", row.aesthetic.candidate)} vs ${fmt("aesthetic", row.aesthetic.alternative)})`);+ for (const [k, limit] of Object.entries(guards)) {+ const g = row[k];+ if (k === main || g?.candidate == null || g?.alternative == null) continue;+ if (worseBy(k, g.candidate, g.alternative) > limit) reasons.push(`it gives up ${METRIC_INFO[k].label.toLowerCase()} against ${alt} (${fmt(k, g.candidate)} vs ${fmt(k, g.alternative)}, the rule allows ${fmt(k, limit)})`);+ }+ // Different endpoints may have different defaults (fal's Z-Image runs LoRAs on /lora): said, not held against it.+ const ea = endpointsOf(ok);+ const eb = endpointsOf(theirs);+ if (ea.length && eb.length && ea.join() !== eb.join()) notes.push(`ran on ${ea.join(", ")}, ${alt} on ${eb.join(", ")}: their defaults may differ`);}if (!against.length) reasons.push("no alternative in this run to beat (run it with --variants recipe,prompt-only,half-strength,plain)");- // 4. blind review- const rated = ratings.pairs.filter((p) => (p.a === cand && alts.includes(p.b)) || (p.b === cand && alts.includes(p.a)));+ // 4. blind review of this case's own pairs+ const ratings = aggregateRatings(L, { caseId });+ const isAgainst = (p) => (p.a === cand && alts.includes(p.b)) || (p.b === cand && alts.includes(p.a));+ const rated = ratings.pairs.filter(isAgainst);+ const offered = Object.entries(ratings.available ?? {}).filter(([k]) => isAgainst({ a: k.split("|")[0], b: k.split("|")[1] })).reduce((n, [, c]) => n + c, 0);const forCand = rated.reduce((n, p) => n + (p.a === cand ? p.aWins : p.bWins), 0);const forAlt = rated.reduce((n, p) => n + (p.a === cand ? p.bWins : p.aWins), 0);const ties = rated.reduce((n, p) => n + p.ties, 0);- if (forCand + forAlt + ties < rule.minRatings) reasons.push(`needs a blind review: ${forCand + forAlt + ties} rating${forCand + forAlt + ties === 1 ? "" : "s"} for the whole run, the rule wants ${rule.minRatings} (pnpm eval:review)`);+ const want = offered ? Math.min(rule.minRatings, offered) : rule.minRatings;+ const got = forCand + forAlt + ties;+ if (got < want) reasons.push(`needs a blind review of this case: ${got} rating${got === 1 ? "" : "s"} against the alternatives, the rule wants ${want}${offered && offered < rule.minRatings ? " (every pair the review offered)" : ""} (pnpm eval:review)`);else if (forCand + forAlt && forCand / (forCand + forAlt) < rule.minPreference) reasons.push(`people preferred it ${Math.round((100 * forCand) / (forCand + forAlt))}% of the time, the rule wants ${Math.round(rule.minPreference * 100)}%`);- // Over-cooking is its own verdict: the fix is a lower strength, not another recipe.- verdictText = !reasons.length ? "promote" : notes.length ? "lower strengths" : "hold";- results.push({ caseId, title: mine[0]?.caseTitle ?? caseId, look: recipe?.look ?? null, target: researchTarget(recipe), candidate: cand, verdict: verdictText, reasons, notes, mainMetric: main, against, recipe: recipe ? { loras: applied.map((l) => ({ file: l.file, strength: l.strength ?? 1 })), source: recipe.source } : null, ...(suggested && { suggested }) });+ // A licence problem holds the recipe; over-cooking is its own verdict (the fix is a lower strength, not another recipe).+ const verdictText = licence.length ? "hold" : !reasons.length ? "promote" : overcooked ? "lower strengths" : "hold";+ results.push({ caseId, title: mine[0]?.caseTitle ?? caseId, look: recipe?.look ?? null, target: researchTarget(recipe), candidate: cand, verdict: verdictText, reasons: [...licence, ...reasons], notes, mainMetric: main, against, ratings: { forCandidate: forCand, forAlternatives: forAlt, ties, offered }, recipe: recipe ? { loras: applied.map((l) => ({ file: l.file, strength: l.strength ?? 1 })), source: recipe.source } : null, ...(suggested && { suggested }) });}const doc = {runId: L.run.runId,diff --git a/scripts/eval/lib/report.mjs b/scripts/eval/lib/report.mjsindex 75f12b6e..2a8c5f31 100644--- a/scripts/eval/lib/report.mjs+++ b/scripts/eval/lib/report.mjs@@ -7,7 +7,7 @@ import { esc, href, page } from "./html.mjs";import { fmt, gain, METRIC_INFO, METRIC_ORDER, verdict } from "./metric-info.mjs";import { aggregateRatings } from "./review.mjs";import { money } from "./run.mjs";-import { latestJobs, readJson, writeHistory, writeJson } from "./store.mjs";+import { candidateOf, latestJobs, readJson, writeHistory, writeJson } from "./store.mjs";const mean = (xs) => {const v = xs.filter((x) => typeof x === "number" && !Number.isNaN(x));@@ -82,11 +82,11 @@ export function summarize(loaded) {};}- // Variants of the same job key (case/prompt/seed), each against the first variant of the run.- const base = variants[0];+ // Variants of the same job key (case/prompt/seed), each against the run's candidate (the recipe under test).+ const base = candidateOf(run, variants);const byKey = new Map();for (const x of scored) if (x.row.status === "succeeded") byKey.set(`${x.row.key}|${x.row.variant}`, x);- const pairs = variants.slice(1).map((other) => {+ const pairs = variants.filter((v) => v !== base).map((other) => {const res = {};for (const k of metricKeys) {const s = { wins: 0, losses: 0, ties: 0, gains: [] };@@ -158,6 +158,7 @@ export function summarize(loaded) {metrics: { keys: metricKeys, models: metrics?.models ?? {}, skipped: metrics?.skipped ?? (metrics ? {} : { all: "not scored yet: pnpm eval:report runs the metrics" }), device: metrics?.device ?? null },variants: perVariant,pairs,+ candidate: base,ratings: aggregateRatings(loaded),cases,failures: rows.filter((r) => r.status !== "succeeded" && r.status !== "skipped").map((r) => ({ id: r.id, status: r.status, error: r.error })),diff --git a/scripts/eval/lib/review.mjs b/scripts/eval/lib/review.mjsindex 7c6dddfc..55ac9979 100644--- a/scripts/eval/lib/review.mjs+++ b/scripts/eval/lib/review.mjs@@ -9,7 +9,7 @@ import fs from "node:fs";import http from "node:http";import path from "node:path";import { esc, page } from "./html.mjs";-import { latestJobs, readJson, writeJson } from "./store.mjs";+import { candidateOf, latestJobs, readJson, writeJson } from "./store.mjs";const IMAGE = /\.(png|jpe?g|webp|gif|svg)$/i;const VIDEO = /\.(mp4|mov|m4v|webm)$/i;@@ -21,7 +21,8 @@ const mainOutput = (row) => (row.outputs ?? []).find((o) => (o.kind === "image"/*** The pairs to rate.* @param {{ dir: string, rows: object[] }} run- * @param {{ against?: "variants" | "references" | { dir: string, runId: string, rows: object[] }, limit?: number }} [opts]+ * @param {{ against?: "variants" | "references" | { dir: string, runId: string, rows: object[] }, limit?: number, base?: string }} [opts]+ * base: the variant paired with each of the others (default: the run's candidate, see candidateOf)*/export function buildPairs(run, opts = {}) {const ok = run.rows.filter((r) => r.status === "succeeded" && mainOutput(r));@@ -30,12 +31,13 @@ export function buildPairs(run, opts = {}) {const side = (label, file, extra = {}) => ({ label, file, ...extra });const pairs = [];if (against === "variants") {- const base = variants[0];+ // The candidate against each alternative: the pairs the promote rule reads.+ const base = opts.base && variants.includes(opts.base) ? opts.base : candidateOf(run.run ?? readJson(path.join(run.dir, "run.json"), null), variants);const byKey = new Map(ok.map((r) => [`${r.key}|${r.variant}`, r]));for (const r of ok.filter((x) => x.variant === base)) {- for (const v of variants.slice(1)) {+ for (const v of variants.filter((x) => x !== base)) {const o = byKey.get(`${r.key}|${v}`);- if (o) pairs.push({ a: side(base, path.join(run.dir, mainOutput(r).file), { job: r.id }), b: side(v, path.join(run.dir, mainOutput(o).file), { job: o.id }), prompt: r.prompt, caseTitle: r.caseTitle });+ if (o) pairs.push({ a: side(base, path.join(run.dir, mainOutput(r).file), { job: r.id }), b: side(v, path.join(run.dir, mainOutput(o).file), { job: o.id }), prompt: r.prompt, caseTitle: r.caseTitle, caseId: r.caseId });}}} else if (against === "references") {@@ -45,13 +47,13 @@ export function buildPairs(run, opts = {}) {if (!refs.length) continue;// Spread the references over the case's jobs, so one image isn't the yardstick for all of them.const ref = refs[parseInt(hash(r.id).slice(0, 8), 16) % refs.length];- pairs.push({ a: side(r.variant, path.join(run.dir, out.file), { job: r.id }), b: side("reference", ref, { reference: ref }), prompt: r.prompt, caseTitle: r.caseTitle });+ pairs.push({ a: side(r.variant, path.join(run.dir, out.file), { job: r.id }), b: side("reference", ref, { reference: ref }), prompt: r.prompt, caseTitle: r.caseTitle, caseId: r.caseId });}} else {const other = new Map(against.rows.filter((r) => r.status === "succeeded" && mainOutput(r)).map((r) => [`${r.key}|${r.variant}`, r]));for (const r of ok) {const o = other.get(`${r.key}|${r.variant}`);- if (o) pairs.push({ a: side(`${r.variant} (this run)`, path.join(run.dir, mainOutput(r).file), { job: r.id }), b: side(`${o.variant} (${against.runId})`, path.join(against.dir, mainOutput(o).file), { job: o.id, run: against.runId }), prompt: r.prompt, caseTitle: r.caseTitle });+ if (o) pairs.push({ a: side(`${r.variant} (this run)`, path.join(run.dir, mainOutput(r).file), { job: r.id }), b: side(`${o.variant} (${against.runId})`, path.join(against.dir, mainOutput(o).file), { job: o.id, run: against.runId }), prompt: r.prompt, caseTitle: r.caseTitle, caseId: r.caseId });}}return pairs.slice(0, opts.limit ?? Infinity).map((p) => {@@ -89,7 +91,7 @@ export function writeReview(run, opts = {}) {writeJson(path.join(out, "key.json"), {runId: run.runId,against: opts.against?.runId ?? opts.against ?? null,- pairs: pairs.map((p) => ({ id: p.id, a: p.a, b: p.b, left: p.aLeft ? "a" : "b" })),+ pairs: pairs.map((p) => ({ id: p.id, caseId: p.caseId, a: p.a, b: p.b, left: p.aLeft ? "a" : "b" })),});fs.writeFileSync(path.join(out, "index.html"), reviewHtml(run.runId, items));return { pairs: items.length, file: path.join(out, "index.html") };@@ -202,12 +204,24 @@ document.addEventListener("keydown", (e) => {return page({ title: `Blind review · ${runId}`, body, head: css, script });}-/** Ratings unblinded with the key: per pair of labels, how often each side won. */-export function aggregateRatings(loaded) {+/**+ * Ratings unblinded with the key: per pair of labels, how often each side won. With `caseId`, only that+ * case's pairs count (a look is judged on its own pictures), and `available` says how many pairs of each+ * kind the review offered for it.+ * @param {{ dir: string, rows?: object[], key?: object, ratings?: object }} loaded+ * @param {{ caseId?: string }} [opts]+ */+export function aggregateRatings(loaded, opts = {}) {const key = loaded.key ?? readJson(path.join(loaded.dir, "review", "key.json"), null);const ratings = loaded.ratings ?? readJson(path.join(loaded.dir, "review", "ratings.json"), null);- if (!key || !ratings?.ratings?.length) return { total: 0, pairs: [] };- const byId = new Map(key.pairs.map((p) => [p.id, p]));+ // Keys written before pairs carried their case: the case of the job on either side.+ const caseOfJob = new Map((loaded.rows ?? []).map((r) => [r.id, r.caseId]));+ const caseOf = (p) => p.caseId ?? caseOfJob.get(p.a?.job) ?? caseOfJob.get(p.b?.job) ?? null;+ const keyPairs = (key?.pairs ?? []).filter((p) => !opts.caseId || caseOf(p) === opts.caseId);+ const available = {};+ for (const p of keyPairs) available[`${p.a.label}|${p.b.label}`] = (available[`${p.a.label}|${p.b.label}`] ?? 0) + 1;+ if (!key || !ratings?.ratings?.length) return { total: 0, pairs: [], ...(opts.caseId && { available }) };+ const byId = new Map(keyPairs.map((p) => [p.id, p]));const last = new Map();for (const r of ratings.ratings) last.set(r.pair, r);const groups = new Map();@@ -223,7 +237,7 @@ export function aggregateRatings(loaded) {else g.ties++;groups.set(`${p.a.label}|${p.b.label}`, g);}- return { total, pairs: [...groups.values()].map((g) => ({ ...g, preferA: g.aWins + g.bWins ? g.aWins / (g.aWins + g.bWins) : null })) };+ return { total, pairs: [...groups.values()].map((g) => ({ ...g, preferA: g.aWins + g.bWins ? g.aWins / (g.aWins + g.bWins) : null })), ...(opts.caseId && { available }) };}const TYPES = { ".html": "text/html; charset=utf-8", ".json": "application/json", ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".gif": "image/gif", ".svg": "image/svg+xml", ".mp4": "video/mp4", ".webm": "video/webm", ".mov": "video/quicktime", ".m4v": "video/mp4" };diff --git a/scripts/eval/lib/run.mjs b/scripts/eval/lib/run.mjsindex 49b4495b..55e66ffc 100644--- a/scripts/eval/lib/run.mjs+++ b/scripts/eval/lib/run.mjs@@ -260,6 +260,7 @@ export async function runEval(opts, io) {comfy: comfy ? { url: comfy.url, ...(comfyInfo ?? { unreachable: true }), ...(missingLoras?.length && { missingLoras }) } : null,filters,variants: summary.variants,+ ...(suite.defaults.candidate && { candidate: suite.defaults.candidate }),variantInfo: Object.fromEntries(summary.variants.map((v) => [v, suite.variants?.[v]?.description ?? ""])),maxUsd: Number.isFinite(maxUsd) ? maxUsd : null,estimateUsd: estimate,diff --git a/scripts/eval/lib/schema.mjs b/scripts/eval/lib/schema.mjsindex 32cd15b5..2d9f2cda 100644--- a/scripts/eval/lib/schema.mjs+++ b/scripts/eval/lib/schema.mjs@@ -203,6 +203,8 @@ export const SuiteSchema = zextra: Json.optional(),metrics: z.array(z.enum(METRICS)).default(["clip"]),variant: Slug.optional(),+ /** The variant the promote rule judges and the blind review pairs with the others (default: recipe, else the first). */+ candidate: Slug.optional(),timeoutSeconds: z.number().positive().default(1800),}).strict()@@ -228,8 +230,8 @@ export const SuiteSchema = z}});const variants = Object.keys(s.variants ?? { default: {} });- if (s.defaults.variant && !variants.includes(s.defaults.variant)) {- ctx.addIssue({ code: "custom", path: ["defaults", "variant"], message: `no variant ${s.defaults.variant} (have ${variants.join(", ")})` });+ for (const k of ["variant", "candidate"]) {+ if (s.defaults[k] && !variants.includes(s.defaults[k])) ctx.addIssue({ code: "custom", path: ["defaults", k], message: `no variant ${s.defaults[k]} (have ${variants.join(", ")})` });}});diff --git a/scripts/eval/lib/store.mjs b/scripts/eval/lib/store.mjsindex 03cd2f04..3a872d87 100644--- a/scripts/eval/lib/store.mjs+++ b/scripts/eval/lib/store.mjs@@ -7,6 +7,16 @@ import path from "node:path";export const runDir = (root, runId) => path.join(root, runId);+/**+ * The variant a run puts up for promotion: the one run.json names (the suite's defaults.candidate), else+ * "recipe" when the run has it, else its first variant. The review pairs it with each of the others.+ */+export function candidateOf(run, variants) {+ const named = run?.candidate;+ if (named && variants.includes(named)) return named;+ return variants.includes("recipe") ? "recipe" : variants[0];+}+/** 20261023-224501-soul-open-a1b2 */export function newRunId(suite, engine, now = new Date()) {const p = (n) => String(n).padStart(2, "0");diff --git a/tests/eval-harness.test.ts b/tests/eval-harness.test.tsindex 56fea9d0..5694a232 100644--- a/tests/eval-harness.test.ts+++ b/tests/eval-harness.test.ts@@ -48,7 +48,7 @@ const review = (await import("../scripts/eval/lib/review.mjs")) as {writeReview: (run: object, opts?: object) => { pairs: number };serveReview: (dir: string, opts?: object) => Promise<{ server: http.Server; url: string }>;};-const compare = (await import("../scripts/eval/lib/compare.mjs")) as { promote: (dir: string, opts?: object) => { results: { caseId: string; verdict: string; reasons: string[]; notes: string[] }[] } };+const compare = (await import("../scripts/eval/lib/compare.mjs")) as { promote: (dir: string, opts?: object) => { candidate: string; results: { caseId: string; verdict: string; reasons: string[]; notes: string[]; mainMetric: string }[] } };const store = (await import("../scripts/eval/lib/store.mjs")) as { latestJobs: (d: string) => Row[]; readJsonl: (f: string) => Record<string, unknown>[] };const { createClient } = (await import("../bin/lib/client.mjs")) as { createClient: (t: { url: string }) => unknown };@@ -323,13 +323,13 @@ describe("the runner on the demo provider", () => {});/** A run folder made by hand: rows and metrics as the runner and the scorer write them. */-function fakeRun(name: string, engine: string, scores: Record<string, Record<string, number>>, extra: Partial<Row> = {}) {+function fakeRun(name: string, engine: string, scores: Record<string, Record<string, number>>, extra: Partial<Row> = {}, runExtra: Record<string, unknown> = {}) {const runDir = path.join(results, name);fs.mkdirSync(path.join(runDir, "outputs"), { recursive: true });const png = Buffer.from("89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4890000000d49444154789c63f8cfc0f01f0005000201a2e2b6a40000000049454e44ae426082", "hex");const ids = Object.keys(scores);const variants = [...new Set(ids.map((id) => id.split("--").at(-1)!))];- fs.writeFileSync(path.join(runDir, "run.json"), JSON.stringify({ runId: name, suite: "soul", title: "Fuobe Soul", engine, variants, startedAt: Date.now(), server: { url: "x" } }));+ fs.writeFileSync(path.join(runDir, "run.json"), JSON.stringify({ runId: name, suite: "soul", title: "Fuobe Soul", engine, variants, startedAt: Date.now(), server: { url: "x" }, ...runExtra }));const rows = ids.map((id) => {const [caseId, promptId, seed, variant] = id.split("--");fs.writeFileSync(path.join(runDir, "outputs", `${id}.png`), png);@@ -399,21 +399,38 @@ describe("report, blind review, compare and promote", () => {expect(s.ratings).toEqual({ total: 3, pairs: [{ a: "recipe", b: "prompt-only", aWins: 3, bWins: 0, ties: 0, preferA: 1 }] });});- it("promotes a recipe only when it wins on metrics and in the blind review, and says when strengths over-cook", () => {- const runDir = path.join(results, "fake-open-1");- // 3 ratings are fewer than the rule's 6.- let doc = compare.promote(runDir);- expect(doc.results[0].verdict).toBe("hold");- expect(doc.results[0].reasons.join(" ")).toMatch(/needs a blind review: 3 ratings/);- const ratingsFile = path.join(runDir, "review", "ratings.json");- const saved = JSON.parse(fs.readFileSync(ratingsFile, "utf8"));- const key = JSON.parse(fs.readFileSync(path.join(runDir, "review", "key.json"), "utf8"));- // Six ratings: the same three pairs rated by a second reviewer (another key entry per pair).- key.pairs = [...key.pairs, ...key.pairs.map((p: { id: string }) => ({ ...p, id: `${p.id}-2` }))];- fs.writeFileSync(path.join(runDir, "review", "key.json"), JSON.stringify(key));- fs.writeFileSync(ratingsFile, JSON.stringify({ ...saved, ratings: [...saved.ratings, ...saved.ratings.map((r: { pair: string }) => ({ ...r, pair: `${r.pair}-2` }))] }));- doc = compare.promote(runDir);+ /** Rate the review's pairs (those `only` keeps, at most `limit`) for the `winner` variant, as the page saves them. */+ const rateFor = (runDir: string, winner: string, only: (caseId: string) => boolean = () => true, limit = Infinity) => {+ const key = JSON.parse(fs.readFileSync(path.join(runDir, "review", "key.json"), "utf8")) as { pairs: { id: string; caseId: string; left: "a" | "b"; a: { label: string } }[] };+ const ratings = key.pairs.filter((p) => only(p.caseId)).slice(0, limit).map((p) => ({ pair: p.id, choice: (p.a.label === winner) === (p.left === "a") ? "left" : "right" }));+ fs.writeFileSync(path.join(runDir, "review", "ratings.json"), JSON.stringify({ ratings }));+ return ratings.length;+ };+ const review3 = (runDir: string) => review.writeReview({ dir: runDir, runId: path.basename(runDir), rows: store.latestJobs(runDir) });+ type Verdicts = { candidate: string; results: { caseId: string; verdict: string; reasons: string[]; notes: string[]; mainMetric: string }[] };+ const verdicts = (d: Verdicts) => Object.fromEntries(d.results.map((r) => [r.caseId, r.verdict]));++ it("promotes a look only on its own blind ratings, and says when strengths over-cook", () => {+ // fake-open-1: one look, three pairs, all three rated for the recipe (every pair the review offered).+ let doc = compare.promote(path.join(results, "fake-open-1")) as Verdicts;expect(doc.results[0]).toMatchObject({ verdict: "promote", reasons: [] });+ // Three looks, the recipe best on style in each; six pairs per look against prompt only and half strength.+ const looks = ["look-a", "look-b", "look-c"];+ const scores: Record<string, Record<string, number>> = {};+ for (const look of looks) {+ for (const [variant, style] of [["recipe", 0.8], ["prompt-only", 0.7], ["half-strength", 0.75]] as const) {+ for (const seed of ["s1001", "s2002", "s3003"]) scores[`${look}--p1--${seed}--${variant}`] = { style, clip: 30, aesthetic: 6 };+ }+ }+ const runDir = fakeRun("fake-open-looks", "open", scores);+ expect(review3(runDir).pairs).toBe(18);+ // Only looks A and C were rated: B is held, though six ratings exist for the run.+ rateFor(runDir, "recipe", (c) => c !== "soul/look-b");+ doc = compare.promote(runDir) as Verdicts;+ expect(verdicts(doc)).toEqual({ "soul/look-a": "promote", "soul/look-b": "hold", "soul/look-c": "promote" });+ expect(doc.results[1].reasons).toEqual(["needs a blind review of this case: 0 ratings against the alternatives, the rule wants 6 (pnpm eval:review)"]);+ rateFor(runDir, "recipe", (c) => c === "soul/look-b", 3);+ expect((compare.promote(runDir) as Verdicts).results[1].reasons[0]).toMatch(/3 ratings against the alternatives, the rule wants 6/);// Half strength scoring higher on the look's main metric: lower the strengths instead.const over = fakeRun("fake-open-2", "open", { ...scored("recipe", 0.8, 30), ...scored("half-strength", 0.9, 30) });const d2 = compare.promote(over);@@ -424,6 +441,32 @@ describe("report, blind review, compare and promote", () => {expect(compare.promote(demo).results[0].reasons[0]).toBe("demo media, not model output");});+ it("judges a clip on its words and guards its flicker; a licence problem holds whatever else won", () => {+ // A DoP motion: no style or aesthetic scores, so prompt adherence decides; the suite names its candidate.+ const clipScores = (warp: number) => ({+ ...Object.fromEntries(["s1001", "s2002", "s3003"].map((s) => [`motion-a--bridge--${s}--research`, { clip: 32, warp, drift: 0.02 }])),+ ...Object.fromEntries(["s1001", "s2002", "s3003"].map((s) => [`motion-a--bridge--${s}--catalog`, { clip: 28, warp: 0.03, drift: 0.02 }])),+ });+ const good = fakeRun("fake-dop-1", "open", clipScores(0.01), {}, { candidate: "research", variants: ["catalog", "research"] });+ review3(good);+ rateFor(good, "research");+ const d = compare.promote(good) as Verdicts;+ expect(d.candidate).toBe("research");+ expect(d.results[0]).toMatchObject({ verdict: "promote", mainMetric: "clip", reasons: [] });+ // Better words but more flicker than the guard allows: held.+ const flicker = fakeRun("fake-dop-2", "open", clipScores(0.04), {}, { candidate: "research", variants: ["catalog", "research"] });+ review3(flicker);+ rateFor(flicker, "research");+ expect((compare.promote(flicker) as Verdicts).results[0].reasons).toEqual(["it gives up warp error (flicker) against catalog (0.0400 vs 0.0300, the rule allows 0.0020)"]);+ // The recipe is the candidate even when it isn't the run's first variant; a non-commercial LoRA holds it even though half strength won.+ const nc = { recipe: { kind: "soul-look", commercialOk: false, loras: [{ file: "nc.safetensors", commercial: false, hostedOk: true }], applied: [{ file: "nc.safetensors", strength: 0.7 }], complete: true, sent: { complete: true, loras: [] } } };+ const lic = fakeRun("fake-open-nc", "open", { ...scored("half-strength", 0.9, 30), ...scored("recipe", 0.8, 30) }, nc);+ const d3 = compare.promote(lic) as Verdicts;+ expect(d3.candidate).toBe("recipe");+ expect(d3.results[0].verdict).toBe("hold");+ expect(d3.results[0].reasons[0]).toBe("non-commercial LoRA: nc.safetensors");+ });+it("promote --record writes each verdict into the research entry it measured, and nothing else", async () => {const python = spawnSync("python3", ["--version"]).status === 0 ? "python3" : null;if (!python) return; // no Python 3 here: the pytest covers the writer where there is one