Spaces:
Sleeping
Sleeping
feat: reasoning-token volume (per-trace), surfaced in stats/compare/replay
Browse files- __pycache__/app.cpython-313.pyc +0 -0
- app.py +9 -2
- static/app.js +4 -3
__pycache__/app.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
|
|
|
app.py
CHANGED
|
@@ -122,6 +122,7 @@ class CachedTrace:
|
|
| 122 |
spine: str # " ".join(atoms) + " ", so `(edit ){5,}` style regexes match
|
| 123 |
task: str = "" # the task/instance the trajectory solved (trace.group), if known
|
| 124 |
outcome: str = "" # "resolved"/"unresolved"/"" from a genuine resolution label, when present
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
# dataset id -> traces. OrderedDict gives us LRU order cheaply.
|
|
@@ -157,10 +158,11 @@ def _load_store() -> dict[str, list[CachedTrace]]:
|
|
| 157 |
for row in df.itertuples(index=False):
|
| 158 |
spine = str(row.spine)
|
| 159 |
atoms = tuple(spine.split())
|
| 160 |
-
# outcome
|
| 161 |
outcome = str(getattr(row, "outcome", "") or "")
|
|
|
|
| 162 |
store.setdefault(str(row.dataset), []).append(
|
| 163 |
-
CachedTrace(str(row.trace_id), str(row.agent), atoms, spine, str(row.task), outcome)
|
| 164 |
)
|
| 165 |
_STORE = store
|
| 166 |
except Exception:
|
|
@@ -235,6 +237,7 @@ def _stats(traces: list[CachedTrace]) -> dict[str, float | int]:
|
|
| 235 |
"diversity_bits": round(sum(ents) / len(ents), 2),
|
| 236 |
"median_len": int(median(lens)),
|
| 237 |
"median_cot": int(median(thinks)),
|
|
|
|
| 238 |
"exact_dup_rate": round(1 - uniq / len(traces), 3),
|
| 239 |
"n_models": len({t.agent for t in traces}),
|
| 240 |
}
|
|
@@ -329,6 +332,7 @@ def query(req: QueryRequest) -> JSONResponse:
|
|
| 329 |
"diversity_bits",
|
| 330 |
"median_len",
|
| 331 |
"median_cot",
|
|
|
|
| 332 |
"exact_dup_rate",
|
| 333 |
"n_models",
|
| 334 |
)
|
|
@@ -344,6 +348,7 @@ def query(req: QueryRequest) -> JSONResponse:
|
|
| 344 |
"model": t.agent,
|
| 345 |
"task": t.task,
|
| 346 |
"outcome": t.outcome,
|
|
|
|
| 347 |
"steps": len(t.atoms),
|
| 348 |
"atoms": list(t.atoms[:200]),
|
| 349 |
}
|
|
@@ -415,6 +420,8 @@ def _side_summary(traces: list[CachedTrace], label: str) -> dict:
|
|
| 415 |
"trace_id": t.trace_id,
|
| 416 |
"model": t.agent,
|
| 417 |
"task": t.task,
|
|
|
|
|
|
|
| 418 |
"steps": len(t.atoms), # true length; atoms below are capped for rendering
|
| 419 |
"atoms": list(t.atoms[:CMP_TRAIL_CAP]),
|
| 420 |
}
|
|
|
|
| 122 |
spine: str # " ".join(atoms) + " ", so `(edit ){5,}` style regexes match
|
| 123 |
task: str = "" # the task/instance the trajectory solved (trace.group), if known
|
| 124 |
outcome: str = "" # "resolved"/"unresolved"/"" from a genuine resolution label, when present
|
| 125 |
+
cot_tokens: int = 0 # approx tokens the model generated (reasoning volume), chars/4
|
| 126 |
|
| 127 |
|
| 128 |
# dataset id -> traces. OrderedDict gives us LRU order cheaply.
|
|
|
|
| 158 |
for row in df.itertuples(index=False):
|
| 159 |
spine = str(row.spine)
|
| 160 |
atoms = tuple(spine.split())
|
| 161 |
+
# outcome + cot_tokens are optional: older stores lack them, read defensively.
|
| 162 |
outcome = str(getattr(row, "outcome", "") or "")
|
| 163 |
+
cot = int(getattr(row, "cot_tokens", 0) or 0)
|
| 164 |
store.setdefault(str(row.dataset), []).append(
|
| 165 |
+
CachedTrace(str(row.trace_id), str(row.agent), atoms, spine, str(row.task), outcome, cot)
|
| 166 |
)
|
| 167 |
_STORE = store
|
| 168 |
except Exception:
|
|
|
|
| 237 |
"diversity_bits": round(sum(ents) / len(ents), 2),
|
| 238 |
"median_len": int(median(lens)),
|
| 239 |
"median_cot": int(median(thinks)),
|
| 240 |
+
"median_cot_tokens": int(median([t.cot_tokens for t in traces])),
|
| 241 |
"exact_dup_rate": round(1 - uniq / len(traces), 3),
|
| 242 |
"n_models": len({t.agent for t in traces}),
|
| 243 |
}
|
|
|
|
| 332 |
"diversity_bits",
|
| 333 |
"median_len",
|
| 334 |
"median_cot",
|
| 335 |
+
"median_cot_tokens",
|
| 336 |
"exact_dup_rate",
|
| 337 |
"n_models",
|
| 338 |
)
|
|
|
|
| 348 |
"model": t.agent,
|
| 349 |
"task": t.task,
|
| 350 |
"outcome": t.outcome,
|
| 351 |
+
"cot_tokens": t.cot_tokens,
|
| 352 |
"steps": len(t.atoms),
|
| 353 |
"atoms": list(t.atoms[:200]),
|
| 354 |
}
|
|
|
|
| 420 |
"trace_id": t.trace_id,
|
| 421 |
"model": t.agent,
|
| 422 |
"task": t.task,
|
| 423 |
+
"outcome": t.outcome,
|
| 424 |
+
"cot_tokens": t.cot_tokens,
|
| 425 |
"steps": len(t.atoms), # true length; atoms below are capped for rendering
|
| 426 |
"atoms": list(t.atoms[:CMP_TRAIL_CAP]),
|
| 427 |
}
|
static/app.js
CHANGED
|
@@ -18,6 +18,7 @@ function prettyModel(a){let m=String(a).replace(/^(swe-agent|agentless|moatless|
|
|
| 18 |
return (m.replace(/-/g,' ').trim())||String(a);}
|
| 19 |
function prettyTask(t){if(!t)return '';const m=String(t).match(/^(.+?)__(.+?)-(\d+)$/);return m?`${m[1]}/${m[2]} #${m[3]}`:String(t);}
|
| 20 |
let HIDE_NOISE = false;
|
|
|
|
| 21 |
let DSETS = []; // store-backed dataset ids (shared by query + compare)
|
| 22 |
let OUTCOME_DS = []; // datasets that carry a genuine resolution label
|
| 23 |
let QTIMER; // debounce handle for live-as-you-type
|
|
@@ -102,7 +103,7 @@ async function run(pattern) {
|
|
| 102 |
const top = r.by_model[0];
|
| 103 |
const s = r.stats || {};
|
| 104 |
const statline = s.n_models
|
| 105 |
-
? `<div class="dim" style="margin-bottom:14px">diversity ${s.diversity_bits} bits · median ${s.median_len} steps · CoT ${s.median_cot}
|
| 106 |
: "";
|
| 107 |
$("res").innerHTML =
|
| 108 |
`<div style="font-size:15px;margin:4px 0"><b>${r.n_hits}</b> / ${r.n_traces} traces match <b>/${r.pattern}/</b></div>
|
|
@@ -274,7 +275,7 @@ function openTraceData(t, ds, color) {
|
|
| 274 |
sheet.innerHTML =
|
| 275 |
`<div class="card"><span class="x" onclick="rpClose()">close ✕</span>
|
| 276 |
<div style="font-size:15px"><b>${prettyModel(t.model)}</b>${prob ? ` · ${prettyTask(prob)}` : ""}${oc}</div>
|
| 277 |
-
<div class="dim" style="margin:2px 0 6px">${t.steps ?? t.atoms.length} steps · structural trail, no raw text stored · press play to replay</div>
|
| 278 |
<div id="rp-mini" style="margin:2px 0 8px"></div>
|
| 279 |
<div class="rpbar">
|
| 280 |
<span class="rpbtn" id="rp-play" onclick="rpToggle()">▶ play</span>
|
|
@@ -339,7 +340,7 @@ function trailStack(side) {
|
|
| 339 |
const ds = CMP.axis === "eval" ? (side === "left" ? CMP.left : CMP.right) : CMP.ds;
|
| 340 |
return `<div class="cmpcol">
|
| 341 |
<div class="cmphead">${prettyModel(col.label)} <a class="dim src" href="https://huggingface.co/datasets/${ds}" target="_blank" rel="noopener">source ↗</a></div>
|
| 342 |
-
<div class="cmpstat">${col.n.toLocaleString()} traces · median ${s.median_len} steps · ${s.median_cot} reasoning · diversity ${s.diversity_bits} bits</div>
|
| 343 |
${col.trails.map((t, i) => { const prob = t.task || t.trace_id || ""; return `<div class="trow" onclick="openTrace('${side}',${i})"><span class="tlen">${t.steps} st</span><span class="tname dim" title="${prob}">${prettyTask(prob)}</span>${barcode(t.atoms, c)}</div>`; }).join("")}</div>`;
|
| 344 |
}
|
| 345 |
|
|
|
|
| 18 |
return (m.replace(/-/g,' ').trim())||String(a);}
|
| 19 |
function prettyTask(t){if(!t)return '';const m=String(t).match(/^(.+?)__(.+?)-(\d+)$/);return m?`${m[1]}/${m[2]} #${m[3]}`:String(t);}
|
| 20 |
let HIDE_NOISE = false;
|
| 21 |
+
const fmtTok = (n) => (n >= 1000 ? (n / 1000).toFixed(1) + "k" : String(n || 0));
|
| 22 |
let DSETS = []; // store-backed dataset ids (shared by query + compare)
|
| 23 |
let OUTCOME_DS = []; // datasets that carry a genuine resolution label
|
| 24 |
let QTIMER; // debounce handle for live-as-you-type
|
|
|
|
| 103 |
const top = r.by_model[0];
|
| 104 |
const s = r.stats || {};
|
| 105 |
const statline = s.n_models
|
| 106 |
+
? `<div class="dim" style="margin-bottom:14px">diversity ${s.diversity_bits} bits · median ${s.median_len} steps · CoT ${s.median_cot} steps${s.median_cot_tokens ? `, ~${fmtTok(s.median_cot_tokens)} tokens` : ""} · ${(s.exact_dup_rate * 100).toFixed(0)}% exact-duplicate · ${s.n_models} models</div>`
|
| 107 |
: "";
|
| 108 |
$("res").innerHTML =
|
| 109 |
`<div style="font-size:15px;margin:4px 0"><b>${r.n_hits}</b> / ${r.n_traces} traces match <b>/${r.pattern}/</b></div>
|
|
|
|
| 275 |
sheet.innerHTML =
|
| 276 |
`<div class="card"><span class="x" onclick="rpClose()">close ✕</span>
|
| 277 |
<div style="font-size:15px"><b>${prettyModel(t.model)}</b>${prob ? ` · ${prettyTask(prob)}` : ""}${oc}</div>
|
| 278 |
+
<div class="dim" style="margin:2px 0 6px">${t.steps ?? t.atoms.length} steps${t.cot_tokens ? ` · ~${fmtTok(t.cot_tokens)} reasoning tokens` : ""} · structural trail, no raw text stored · press play to replay</div>
|
| 279 |
<div id="rp-mini" style="margin:2px 0 8px"></div>
|
| 280 |
<div class="rpbar">
|
| 281 |
<span class="rpbtn" id="rp-play" onclick="rpToggle()">▶ play</span>
|
|
|
|
| 340 |
const ds = CMP.axis === "eval" ? (side === "left" ? CMP.left : CMP.right) : CMP.ds;
|
| 341 |
return `<div class="cmpcol">
|
| 342 |
<div class="cmphead">${prettyModel(col.label)} <a class="dim src" href="https://huggingface.co/datasets/${ds}" target="_blank" rel="noopener">source ↗</a></div>
|
| 343 |
+
<div class="cmpstat">${col.n.toLocaleString()} traces · median ${s.median_len} steps · ${s.median_cot} reasoning${s.median_cot_tokens ? `, ~${fmtTok(s.median_cot_tokens)} tok` : ""} · diversity ${s.diversity_bits} bits</div>
|
| 344 |
${col.trails.map((t, i) => { const prob = t.task || t.trace_id || ""; return `<div class="trow" onclick="openTrace('${side}',${i})"><span class="tlen">${t.steps} st</span><span class="tname dim" title="${prob}">${prettyTask(prob)}</span>${barcode(t.atoms, c)}</div>`; }).join("")}</div>`;
|
| 345 |
}
|
| 346 |
|