| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| function initSpeedup(deps) { |
|
|
| const { |
| config, MODEL_COL, FAMILY_COL, isExternalModel, |
| } = deps; |
|
|
| const ENABLED = config.speedup_column !== false; |
| const LABEL = config.speedup_label || "VS BASE"; |
|
|
| |
| |
| |
| |
| const KEY_COLS = [ |
| FAMILY_COL, |
| ...config.filters.map(f => f.column), |
| ...(config.display_columns || []).map(d => d.column), |
| ].filter(Boolean); |
|
|
| function pairKey(row, cols) { |
| return cols.map(c => String(row[c] ?? "")).join("\0"); |
| } |
|
|
| |
| function usable(val) { |
| return typeof val === "number" && isFinite(val) && val > 0 ? val : undefined; |
| } |
|
|
| function formatRatio(ratio) { |
| return ratio.toFixed(2) + "Γ"; |
| } |
|
|
| |
| let state = null; |
|
|
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function bestMetric(rows, metrics) { |
| if (!ENABLED || !rows || !rows.length) return null; |
|
|
| const baselines = {}; |
| rows.forEach(r => { |
| if (!isExternalModel(r[MODEL_COL])) return; |
| const k = pairKey(r, KEY_COLS); |
| (baselines[k] = baselines[k] || []).push(r); |
| }); |
|
|
| let best = null; |
| (metrics || []).forEach(m => { |
| const hib = m.higher_is_better !== false; |
| let top; |
| rows.forEach(r => { |
| if (isExternalModel(r[MODEL_COL])) return; |
| const cands = baselines[pairKey(r, KEY_COLS)]; |
| if (!cands || !cands.length) return; |
| if (new Set(cands.map(c => c[MODEL_COL])).size > 1) return; |
| const b = usable(cands[0][m.column]); |
| const o = usable(r[m.column]); |
| if (b === undefined || o === undefined) return; |
| const ratio = hib ? o / b : b / o; |
| if (!isFinite(ratio) || ratio <= 0) return; |
| if (top === undefined || ratio > top) top = ratio; |
| }); |
| if (top !== undefined && (!best || top > best.ratio)) { |
| best = { column: m.column, ratio: top }; |
| } |
| }); |
| return best ? best.column : null; |
| } |
|
|
| |
|
|
| |
| |
| |
| |
| |
| function prepare(rows, opts) { |
| state = null; |
| if (!ENABLED || !rows || !rows.length) return; |
|
|
| const visibleMetrics = opts.visibleMetrics || []; |
| const metricCfg = visibleMetrics.find(m => m.column === opts.activeMetricCol) |
| || visibleMetrics[0]; |
| if (!metricCfg) return; |
|
|
| const metricCol = metricCfg.column; |
| const hib = metricCfg.higher_is_better !== false; |
| const cols = [...new Set(KEY_COLS.concat(opts.tableGroupCols || []))]; |
|
|
| |
| const baselines = {}; |
| rows.forEach(r => { |
| if (!isExternalModel(r[MODEL_COL])) return; |
| const k = pairKey(r, cols); |
| (baselines[k] = baselines[k] || []).push(r); |
| }); |
|
|
| const ratios = new Map(); |
| const isBase = new Set(); |
|
|
| rows.forEach(r => { |
| if (isExternalModel(r[MODEL_COL])) return; |
| const cands = baselines[pairKey(r, cols)]; |
| if (!cands || !cands.length) return; |
| |
| |
| if (new Set(cands.map(c => c[MODEL_COL])).size > 1) return; |
| const base = cands[0]; |
| const b = usable(base[metricCol]); |
| const o = usable(r[metricCol]); |
| if (b === undefined || o === undefined) return; |
| const ratio = hib ? o / b : b / o; |
| if (!isFinite(ratio) || ratio <= 0) return; |
| ratios.set(r, ratio); |
| isBase.add(base); |
| }); |
|
|
| if (!ratios.size) return; |
| state = { ratios, isBase, metricCfg }; |
| } |
|
|
| |
|
|
| |
| |
| function metricCol() { |
| return state ? state.metricCfg.column : null; |
| } |
|
|
| function headerHtml() { |
| if (!state) return ""; |
| const m = state.metricCfg; |
| const tip = `Ratio of this model's ${m.label || m.column} against the original ` |
| + `(non-${config.optimized_org || "embedl"}) model measured under identical conditions. ` |
| + `Always oriented so that higher is better: 1.26Γ means 26% better than the baseline.`; |
| return `<th class="metric-cell speedup-cell" data-tip="${tip.replace(/"/g, """)}">${LABEL}</th>`; |
| } |
| |
| function cellHtml(row) { |
| if (!state) return ""; |
| if (state.isBase.has(row)) { |
| // The baseline is the reference point, so it is 1.00x by definition. |
| // Spelling it out keeps "β" unambiguously meaning "no comparison". |
| return `<td class="metric-cell speedup-cell"><span class="speedup-ref">1.00Γ</span></td>`; |
| } |
| const ratio = state.ratios.get(row); |
| if (ratio === undefined) return `<td class="metric-cell speedup-cell">β</td>`; |
| const down = ratio < 0.995 ? " is-down" : ""; |
| return `<td class="metric-cell speedup-cell">` |
| + `<span class="speedup-val${down}">${formatRatio(ratio)}</span></td>`; |
| } |
| |
| return { prepare, headerHtml, cellHtml, metricCol, bestMetric }; |
| |
| } |
| |