|
|
<div class="throughput-drops-comparison"></div> |
|
|
<style> |
|
|
.throughput-drops-comparison { position: relative; } |
|
|
.throughput-drops-comparison .axis-label { fill: var(--text-color); font-size: 12px; font-weight: 700; } |
|
|
.throughput-drops-comparison .axes path, .throughput-drops-comparison .axes line { stroke: var(--axis-color); } |
|
|
.throughput-drops-comparison .axes text { fill: var(--tick-color); } |
|
|
.throughput-drops-comparison .grid line { stroke: var(--grid-color); } |
|
|
.throughput-drops-comparison .chart-card { background: var(--surface-bg); border: 1px solid var(--border-color); border-radius: 10px; padding: 8px; } |
|
|
.throughput-drops-comparison .chart-header { display:flex; align-items:flex-start; justify-content:flex-start; gap:12px; margin: 8px 0 0 0; flex-wrap: wrap; } |
|
|
.throughput-drops-comparison .legend-bottom { display:flex; align-items:center; justify-content:flex-start; font-size:12px; color: var(--text-color); } |
|
|
.throughput-drops-comparison .legend-bottom .items { display:flex; flex-wrap:wrap; gap:8px 14px; } |
|
|
.throughput-drops-comparison .legend-bottom .item { display:inline-flex; align-items:center; gap:6px; white-space:nowrap; } |
|
|
.throughput-drops-comparison .legend-bottom .swatch { width:14px; height:14px; border-radius:3px; border:1px solid var(--border-color); display:inline-block; } |
|
|
.throughput-drops-comparison .legend-bottom .legend-title { font-size: 12px; font-weight: 700; color: var(--text-color); } |
|
|
.throughput-drops-comparison .legend-bottom { flex-direction: column; align-items: flex-start; gap: 6px; } |
|
|
.throughput-drops-comparison .lines path.active { stroke-width: 3; } |
|
|
.throughput-drops-comparison .d3-tooltip { z-index: var(--z-elevated); backdrop-filter: saturate(1.12) blur(8px); } |
|
|
.throughput-drops-comparison .d3-tooltip__inner { display:flex; flex-direction:column; gap:6px; min-width: 220px; } |
|
|
.throughput-drops-comparison .d3-tooltip__inner > div:first-child { font-weight: 800; letter-spacing: 0.1px; margin-bottom: 0; } |
|
|
.throughput-drops-comparison .d3-tooltip__inner > div:nth-child(2) { font-size: 11px; color: var(--muted-color); display: block; margin-top: -4px; margin-bottom: 2px; letter-spacing: 0.1px; } |
|
|
.throughput-drops-comparison .d3-tooltip__color-dot { display:inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border-color); } |
|
|
|
|
|
.throughput-drops-comparison.hovering .legend-bottom .item.ghost { opacity: .35; } |
|
|
.throughput-drops-comparison.hovering .lines path.ghost { opacity: .25; } |
|
|
.throughput-drops-comparison.hovering .points circle.ghost { opacity: .25; } |
|
|
</style> |
|
|
<script> |
|
|
(() => { |
|
|
const ensureD3 = (cb) => { |
|
|
if (window.d3 && typeof window.d3.select === 'function') return cb(); |
|
|
let s = document.getElementById('d3-cdn-script'); |
|
|
if (!s) { s = document.createElement('script'); s.id = 'd3-cdn-script'; s.src = 'https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js'; document.head.appendChild(s); } |
|
|
const onReady = () => { if (window.d3 && typeof window.d3.select === 'function') cb(); }; |
|
|
s.addEventListener('load', onReady, { once: true }); if (window.d3) onReady(); |
|
|
}; |
|
|
|
|
|
const bootstrap = () => { |
|
|
const scriptEl = document.currentScript; |
|
|
let container = scriptEl ? scriptEl.previousElementSibling : null; |
|
|
if (!(container && container.classList && container.classList.contains('throughput-drops-comparison'))){ |
|
|
const cs = Array.from(document.querySelectorAll('.throughput-drops-comparison')).filter(el => !(el.dataset && el.dataset.mounted === 'true')); |
|
|
container = cs[cs.length - 1] || null; |
|
|
} |
|
|
if (!container) return; |
|
|
if (container.dataset) { if (container.dataset.mounted === 'true') return; container.dataset.mounted = 'true'; } |
|
|
|
|
|
|
|
|
container.style.position = container.style.position || 'relative'; |
|
|
let tip = container.querySelector('.d3-tooltip'); let tipInner; |
|
|
if (!tip) { |
|
|
tip = document.createElement('div'); tip.className = 'd3-tooltip'; |
|
|
Object.assign(tip.style, { |
|
|
position:'absolute', top:'0px', left:'0px', transform:'translate(-9999px, -9999px)', pointerEvents:'none', |
|
|
padding:'8px 10px', borderRadius:'8px', fontSize:'12px', lineHeight:'1.35', border:'1px solid var(--border-color)', |
|
|
background:'var(--surface-bg)', color:'var(--text-color)', boxShadow:'0 4px 24px rgba(0,0,0,.18)', opacity:'0', transition:'opacity .12s ease' |
|
|
}); |
|
|
tipInner = document.createElement('div'); tipInner.className = 'd3-tooltip__inner'; tipInner.style.textAlign='left'; tip.appendChild(tipInner); container.appendChild(tip); |
|
|
} else { tipInner = tip.querySelector('.d3-tooltip__inner') || tip; } |
|
|
|
|
|
|
|
|
const header = document.createElement('div'); header.className = 'chart-header'; |
|
|
const legendBottom = document.createElement('div'); legendBottom.className = 'legend-bottom'; header.appendChild(legendBottom); |
|
|
|
|
|
|
|
|
const card = document.createElement('div'); card.className = 'chart-card'; container.appendChild(card); |
|
|
container.appendChild(header); |
|
|
|
|
|
|
|
|
const svg = d3.select(card).append('svg').attr('width','100%').style('display','block'); |
|
|
const gRoot = svg.append('g'); |
|
|
const gGrid = gRoot.append('g').attr('class','grid'); |
|
|
const gAxes = gRoot.append('g').attr('class','axes'); |
|
|
const gLines = gRoot.append('g').attr('class','lines'); |
|
|
const gPoints = gRoot.append('g').attr('class','points'); |
|
|
const overlay = gRoot.append('rect').attr('fill','transparent').style('cursor','crosshair'); |
|
|
const hoverLine = gRoot.append('line').attr('stroke-width',1).style('display','none'); |
|
|
|
|
|
|
|
|
let width = 800, height = 480; const margin = { top: 16, right: 32, bottom: 44, left: 80 }; |
|
|
const xScale = d3.scaleLinear(); |
|
|
const yScale = d3.scaleLinear(); |
|
|
const lineGen = d3.line().x(d => xScale(d.step)).y(d => yScale(d.value)); |
|
|
let data = []; |
|
|
|
|
|
|
|
|
let currentColors = ['var(--primary-color, #4e79a7)', 'var(--primary-color, #4e79a7)']; |
|
|
|
|
|
function refreshPalette(){ |
|
|
try { |
|
|
if (window.ColorPalettes && typeof window.ColorPalettes.getColors === 'function') { |
|
|
const colors = window.ColorPalettes.getColors('categorical', 2); |
|
|
if (colors && colors.length >= 2) { |
|
|
currentColors = colors; |
|
|
|
|
|
if (data.length > 0) render(); |
|
|
return; |
|
|
} |
|
|
} |
|
|
} catch(_){} |
|
|
|
|
|
currentColors = ['var(--primary-color, #4e79a7)', '#e15759']; |
|
|
|
|
|
if (data.length > 0) render(); |
|
|
} |
|
|
|
|
|
function getColors(){ |
|
|
return currentColors; |
|
|
} |
|
|
|
|
|
|
|
|
function formatK(v){ |
|
|
const abs = Math.abs(v); |
|
|
if (abs >= 1000) { |
|
|
const n = v / 1000; |
|
|
const s = d3.format('.1f')(n); |
|
|
return (s.endsWith('.0') ? s.slice(0, -2) : s) + 'k'; |
|
|
} |
|
|
return d3.format('d')(v); |
|
|
} |
|
|
|
|
|
|
|
|
function formatThroughput(v){ |
|
|
if (v >= 1000) { |
|
|
return d3.format('.1f')(v / 1000) + 'k'; |
|
|
} |
|
|
return d3.format('.1f')(v); |
|
|
} |
|
|
|
|
|
function updateLayout(){ |
|
|
const axisColor = getComputedStyle(container).getPropertyValue('--axis-color').trim() || 'rgba(0,0,0,0.25)'; |
|
|
width = container.clientWidth || 800; |
|
|
height = Math.max(280, Math.round(width / 3)); |
|
|
svg.attr('width', width).attr('height', height); |
|
|
gRoot.attr('transform', `translate(${margin.left},${margin.top})`); |
|
|
const innerWidth = width - margin.left - margin.right; |
|
|
const innerHeight = height - margin.top - margin.bottom; |
|
|
overlay.attr('x',0).attr('y',0).attr('width', innerWidth).attr('height', innerHeight); |
|
|
hoverLine.attr('y1',0).attr('y2', innerHeight).attr('stroke', axisColor); |
|
|
return { innerWidth, innerHeight }; |
|
|
} |
|
|
|
|
|
function render(){ |
|
|
if (data.length === 0) return; |
|
|
|
|
|
const { innerWidth, innerHeight } = updateLayout(); |
|
|
|
|
|
|
|
|
const sortedData = data.slice().sort((a, b) => a.step - b.step); |
|
|
|
|
|
|
|
|
const series = [ |
|
|
{ |
|
|
name: 'Throughput (main run)', |
|
|
values: sortedData.map(d => ({ step: d.step, value: d.throughput_drops })) |
|
|
}, |
|
|
{ |
|
|
name: 'Throughput (ablations)', |
|
|
values: sortedData.map(d => ({ step: d.step, value: d.throughput_no_drops })) |
|
|
} |
|
|
]; |
|
|
|
|
|
|
|
|
const minStep = d3.min(sortedData, d => d.step); |
|
|
const maxStep = d3.max(sortedData, d => d.step); |
|
|
const minValue = d3.min(sortedData, d => Math.min(d.throughput_drops, d.throughput_no_drops)); |
|
|
const maxValue = d3.max(sortedData, d => Math.max(d.throughput_drops, d.throughput_no_drops)); |
|
|
|
|
|
xScale.domain([minStep, maxStep]).range([0, innerWidth]); |
|
|
yScale.domain([minValue, maxValue]).nice().range([innerHeight, 0]); |
|
|
|
|
|
|
|
|
gGrid.selectAll('*').remove(); |
|
|
gGrid.selectAll('line').data(yScale.ticks(6)).join('line') |
|
|
.attr('x1',0).attr('x2', innerWidth).attr('y1', d=>yScale(d)).attr('y2', d=>yScale(d)) |
|
|
.attr('stroke','var(--grid-color)').attr('stroke-width',1).attr('shape-rendering','crispEdges'); |
|
|
|
|
|
|
|
|
gAxes.selectAll('*').remove(); |
|
|
gAxes.append('g').attr('transform', `translate(0,${innerHeight})`).call(d3.axisBottom(xScale).ticks(8).tickFormat(formatK)).call(g=>{ g.selectAll('path, line').attr('stroke','var(--axis-color)'); g.selectAll('text').attr('fill','var(--tick-color)').style('font-size','12px'); }); |
|
|
gAxes.append('g').call(d3.axisLeft(yScale).ticks(6).tickFormat(formatThroughput)).call(g=>{ g.selectAll('path, line').attr('stroke','var(--axis-color)'); g.selectAll('text').attr('fill','var(--tick-color)').style('font-size','12px'); }); |
|
|
gAxes.append('text').attr('class','axis-label').attr('text-anchor','middle').attr('x', innerWidth/2).attr('y', innerHeight + 38).text('Training Step'); |
|
|
gAxes.append('text').attr('class','axis-label').attr('text-anchor','middle').attr('transform', `translate(${-60}, ${innerHeight/2}) rotate(-90)`).text('Tokens/sec/GPU'); |
|
|
|
|
|
|
|
|
const colors = getColors(); |
|
|
gLines.selectAll('*').remove(); |
|
|
series.forEach((s, i) => { |
|
|
gLines.append('path') |
|
|
.attr('class', `line line-${i}`) |
|
|
.attr('data-series', s.name) |
|
|
.attr('fill','none') |
|
|
.attr('stroke', colors[i % colors.length]) |
|
|
.attr('stroke-width', 2) |
|
|
.attr('d', lineGen(s.values)); |
|
|
}); |
|
|
|
|
|
|
|
|
gPoints.selectAll('*').remove(); |
|
|
series.forEach((s, i) => { |
|
|
gPoints.selectAll(`circle.point-${i}`).data(s.values).join('circle') |
|
|
.attr('class', `point point-${i}`) |
|
|
.attr('data-series', s.name) |
|
|
.attr('r', 2) |
|
|
.attr('fill', colors[i % colors.length]) |
|
|
.attr('fill-opacity', 0.6) |
|
|
.attr('cx', d=>xScale(d.step)) |
|
|
.attr('cy', d=>yScale(d.value)); |
|
|
}); |
|
|
|
|
|
|
|
|
legendBottom.innerHTML = `<div class="legend-title">Legend</div><div class="items">${series.map((s, i) => `<span class="item" data-series="${s.name}"><span class="swatch" style="background:${colors[i % colors.length]}"></span><span>${s.name}</span></span>`).join('')}</div>`; |
|
|
|
|
|
|
|
|
try { |
|
|
const legendNode = legendBottom; |
|
|
legendNode.querySelectorAll('.item').forEach(el => { |
|
|
el.addEventListener('mouseenter', () => { |
|
|
const seriesName = el.getAttribute('data-series'); if (!seriesName) return; |
|
|
container.classList.add('hovering'); |
|
|
gLines.selectAll('path.line').classed('ghost', s => s.getAttribute && s.getAttribute('data-series') !== seriesName); |
|
|
gPoints.selectAll('circle.point').classed('ghost', p => p.getAttribute && p.getAttribute('data-series') !== seriesName); |
|
|
legendNode.querySelectorAll('.item').forEach(it => it.classList.toggle('ghost', it.getAttribute('data-series') !== seriesName)); |
|
|
}); |
|
|
el.addEventListener('mouseleave', () => { |
|
|
container.classList.remove('hovering'); |
|
|
gLines.selectAll('path.line').classed('ghost', false); |
|
|
gPoints.selectAll('circle.point').classed('ghost', false); |
|
|
legendNode.querySelectorAll('.item').forEach(it => it.classList.remove('ghost')); |
|
|
}); |
|
|
}); |
|
|
} catch {} |
|
|
|
|
|
|
|
|
function onMove(ev){ |
|
|
const [mx, my] = d3.pointer(ev, overlay.node()); |
|
|
const sx = xScale.invert(mx); |
|
|
|
|
|
|
|
|
const steps = Array.from(new Set(sortedData.map(d => d.step))).sort((a,b) => a - b); |
|
|
const nearest = steps.reduce((best, s) => Math.abs(s - sx) < Math.abs(best - sx) ? s : best, steps[0]); |
|
|
const xpx = xScale(nearest); |
|
|
hoverLine.style('display', null).attr('x1', xpx).attr('x2', xpx); |
|
|
|
|
|
|
|
|
const dataPoint = sortedData.find(d => d.step === nearest); |
|
|
if (!dataPoint) return; |
|
|
|
|
|
|
|
|
let html = `<div style="font-weight:800;letter-spacing:.1px;">Throughput Comparison</div><div style="font-size:11px;color:var(--muted-color);margin-top:-4px;margin-bottom:2px;">Step ${formatK(nearest)}</div>`; |
|
|
|
|
|
series.forEach((s, i) => { |
|
|
const value = s.name === 'Throughput (main run)' ? dataPoint.throughput_drops : dataPoint.throughput_no_drops; |
|
|
html += `<div style="display:flex;align-items:center;gap:6px;white-space:nowrap;"><span class="d3-tooltip__color-dot" style="background:${colors[i % colors.length]}"></span><strong>${s.name}</strong><span style="margin-left:auto;">${formatThroughput(value)}</span></div>`; |
|
|
}); |
|
|
|
|
|
tipInner.innerHTML = html; |
|
|
tip.style.opacity = '1'; |
|
|
tip.style.transform = `translate(${Math.round(mx + margin.left + 12)}px, ${Math.round(my + margin.top + 12)}px)`; |
|
|
} |
|
|
|
|
|
function onLeave(){ |
|
|
tip.style.opacity='0'; |
|
|
tip.style.transform='translate(-9999px, -9999px)'; |
|
|
hoverLine.style('display','none'); |
|
|
} |
|
|
|
|
|
overlay.on('mousemove', onMove).on('mouseleave', onLeave); |
|
|
} |
|
|
|
|
|
|
|
|
(async () => { |
|
|
try { |
|
|
|
|
|
const csvPaths = [ |
|
|
'/data/throughput_drops_comparison_before_after.csv', |
|
|
'./assets/data/throughput_drops_comparison_before_after.csv', |
|
|
'../assets/data/throughput_drops_comparison_before_after.csv', |
|
|
'../../assets/data/throughput_drops_comparison_before_after.csv' |
|
|
]; |
|
|
|
|
|
let csvText = null; |
|
|
for (const path of csvPaths) { |
|
|
try { |
|
|
const response = await fetch(path, { cache: 'no-cache' }); |
|
|
if (response.ok) { |
|
|
csvText = await response.text(); |
|
|
break; |
|
|
} |
|
|
} catch(_) {} |
|
|
} |
|
|
|
|
|
if (!csvText) { |
|
|
throw new Error('CSV file not found: throughput_drops_comparison_before_after.csv'); |
|
|
} |
|
|
|
|
|
const rows = d3.csvParse(csvText); |
|
|
|
|
|
|
|
|
data = rows.map(d => ({ |
|
|
step: +d.Step, |
|
|
throughput_drops: +d.throughput_drops, |
|
|
throughput_no_drops: +d.throughput_no_drops |
|
|
})).filter(d => !isNaN(d.step) && !isNaN(d.throughput_drops) && !isNaN(d.throughput_no_drops)); |
|
|
|
|
|
|
|
|
refreshPalette(); |
|
|
document.addEventListener('palettes:updated', refreshPalette); |
|
|
|
|
|
render(); |
|
|
|
|
|
const rerender = () => render(); |
|
|
if (window.ResizeObserver) { |
|
|
const ro = new ResizeObserver(() => rerender()); |
|
|
ro.observe(container); |
|
|
} else { |
|
|
window.addEventListener('resize', rerender); |
|
|
} |
|
|
} catch (e) { |
|
|
const pre = document.createElement('pre'); |
|
|
pre.textContent = 'CSV load error: ' + (e && e.message ? e.message : e); |
|
|
pre.style.color = 'var(--danger, #b00020)'; |
|
|
pre.style.fontSize = '12px'; |
|
|
pre.style.whiteSpace = 'pre-wrap'; |
|
|
container.appendChild(pre); |
|
|
} |
|
|
})(); |
|
|
}; |
|
|
|
|
|
if (document.readyState === 'loading') { |
|
|
document.addEventListener('DOMContentLoaded', () => ensureD3(bootstrap), { once: true }); |
|
|
} else { |
|
|
ensureD3(bootstrap); |
|
|
} |
|
|
})(); |
|
|
</script> |
|
|
|