flash-sd-kde-section5 / index.html
avengeryt22's picture
reference the complete single-script run
dfcb692 verified
Raw History Blame Contribute Delete
17 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flash-SD-KDE Β§5 β€” reproduction</title>
<style>
:root { --ink:#111827; --mut:#6b7280; --line:#e5e7eb; --acc:#c2410c; --ok:#047857; --bg:#fff; }
* { box-sizing:border-box; }
body { margin:0; padding:30px 22px 56px; font:15px/1.58 ui-sans-serif,-apple-system,Segoe UI,Roboto,sans-serif; color:var(--ink); background:var(--bg); }
.wrap { max-width:1060px; margin:0 auto; }
a { color:var(--acc); }
h1 { font-size:22px; margin:0 0 4px; letter-spacing:-.01em; }
.sub { color:var(--mut); font-size:13px; margin:0 0 20px; }
.verdict { display:flex; gap:12px; align-items:flex-start; border:1px solid #d1fae5; background:#f0fdf9; border-radius:10px; padding:13px 15px; margin:0 0 8px; }
.pill { flex:none; font-weight:700; font-size:12px; letter-spacing:.05em; text-transform:uppercase; color:#fff; background:var(--ok); border-radius:999px; padding:3px 10px; margin-top:2px; }
.verdict p { margin:0; font-size:13.5px; }
h2 { font-size:14px; margin:30px 0 8px; letter-spacing:.01em; }
h2 span { color:var(--mut); font-weight:400; }
table { border-collapse:collapse; width:100%; font-size:13px; font-variant-numeric:tabular-nums; }
th,td { text-align:right; padding:6px 8px; border-bottom:1px solid var(--line); vertical-align:top; }
th:first-child, td:first-child { text-align:left; }
thead th { font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:var(--mut); font-weight:600; }
td.l { text-align:left; }
.grid { display:grid; grid-template-columns:repeat(3,1fr); gap:14px; margin-top:6px; }
@media (max-width:820px){ .grid{ grid-template-columns:1fr; } }
.card { border:1px solid var(--line); border-radius:10px; padding:11px 11px 4px; }
.card h3 { font-size:12px; margin:0 0 1px; font-weight:650; }
.card .cap { font-size:11px; color:var(--mut); margin:0 0 6px; }
canvas { width:100%; height:200px; display:block; }
.legend { display:flex; flex-wrap:wrap; gap:12px; font-size:11.5px; color:var(--mut); padding:8px 2px 0; }
.legend span { display:inline-flex; align-items:center; gap:5px; }
.sw { width:14px; height:2px; border-radius:2px; display:inline-block; }
.hi { color:var(--acc); font-weight:650; }
code, pre { font:12.5px ui-monospace,SFMono-Regular,Menlo,monospace; }
code { background:#f9fafb; border:1px solid var(--line); border-radius:4px; padding:0 4px; }
pre { background:#f9fafb; border:1px solid var(--line); border-radius:8px; padding:11px 13px; overflow:auto; line-height:1.45; }
ul { margin:6px 0 0; padding-left:20px; }
li { margin:3px 0; }
.note { font-size:12.5px; color:var(--mut); margin-top:10px; }
.files { display:grid; grid-template-columns:1fr 1fr; gap:6px 20px; font-size:13px; }
@media (max-width:700px){ .files{ grid-template-columns:1fr; } }
</style>
</head>
<body>
<div class="wrap">
<h1>Flash-SD-KDE Β§5 β€” fused Laplace kernel: signed equivalence and cost</h1>
<p class="sub">Reproduction of <a href="https://arxiv.org/abs/2602.10378">arXiv:2602.10378v1</a> (Epstein, Dwaraknath, Winnicki) against the authors' code at commit <code>acaf8712</code>. 1D toy mixture, 2048-point grid on [βˆ’6,6], n<sub>train</sub> 128–4096, 3 data replicates.</p>
<div class="verdict">
<span class="pill">Verified</span>
<p><strong>The claim holds, within stated scope.</strong> Fusing the Laplace-corrected kernel leaves the signed estimator unchanged β€” fused and non-fused densities agree to <span class="hi">1.1e-16</span> (float64) and <span class="hi">8.9e-8</span> (float32 and Triton), with zero sign disagreements in 18 runs β€” while cutting GPU runtime by <span class="hi">1.93×–6.20Γ—</span>. The corrected estimator stays distinct from empirical SD-KDE: negative mass <span class="hi">1.69e-3</span> vs exactly <strong>0</strong> at n=4096. No fixed speedup and no nonnegative-density claim follows.</p>
</div>
<h2>Paper's number vs number obtained <span>β€” the paper tabulates nothing for 1D, so several cells are "figure only"</span></h2>
<table>
<thead><tr><th>Quantity</th><th>Paper (Sec. 5 / 6.1, Figs. 3–4)</th><th>This reproduction</th></tr></thead>
<tbody>
<tr><td class="l">Fused vs non-fused 1D error curves</td><td class="l">"the fused Flash-Laplace-KDE curve overlaps the non-fused implementation" β€” figure only, no numbers</td><td class="l">max |Ξ”density| 6.0e-8…8.9e-8 (float32, Triton); 1.1e-16 (float64); 0 sign disagreements; Ξ”MISE &lt; 1e-9</td></tr>
<tr><td class="l">1D fused speedup</td><td class="l">Fig. 4 right panel, β‰ˆ2–8Γ— band; <strong>not tabulated</strong></td><td class="l">1.93Γ— (n=128) β†’ 2.42Γ— (1024) β†’ 6.20Γ— (4096) on A10G; second run 1.99×–6.47Γ—</td></tr>
<tr><td class="l">1D MISE / MIAE</td><td class="l">Fig. 3, log-log curves only, no table</td><td class="l">table below; e.g. n=4096 LC 1.1142e-3 / 6.5009e-2 vs emp SD-KDE 2.8013e-3 / 9.7414e-2</td></tr>
<tr><td class="l">Integrated negative mass</td><td class="l">"logged as a diagnostic", no value reported</td><td class="l">1.0205e-2 (n=128) β†’ 1.6873e-3 (n=4096); empirical SD-KDE exactly 0</td></tr>
<tr><td class="l">Kernel identity</td><td class="l">K<sub>LC</sub> = K<sub>h</sub>(1 + d/2 βˆ’ β€–xβ€–Β²/2hΒ²), stated analytically</td><td class="l">equals K<sub>h</sub> βˆ’ (hΒ²/2)Ξ”K<sub>h</sub> to 4.4e-16; ∫K<sub>LC</sub> = 1, 2nd moment 0, 4th moment βˆ’3h⁴, sign flip at √3Β·h</td></tr>
<tr><td class="l">16-D numbers (Table 1: 2.11 ms, 1.57Γ—, 7.99Γ—)</td><td class="l">reported</td><td class="l">not tested β€” out of scope for the Β§5 1-D claim</td></tr>
</tbody>
</table>
<div class="grid">
<div class="card"><h3>MISE vs n<sub>train</sub></h3><p class="cap">mean of 3 per-replicate ISE, signed density</p><canvas id="c1"></canvas></div>
<div class="card"><h3>MIAE vs n<sub>train</sub></h3><p class="cap">mean of 3 per-replicate IAE, signed density</p><canvas id="c2"></canvas></div>
<div class="card"><h3>Runtime vs n<sub>train</sub></h3><p class="cap">A10G, 1 warmup + 3 CUDA-event repeats</p><canvas id="c3"></canvas></div>
</div>
<div class="legend">
<span><i class="sw" style="background:#9ca3af"></i>plain KDE</span>
<span><i class="sw" style="background:#c2410c"></i>fused Laplace (Flash-Laplace-KDE)</span>
<span><i class="sw" style="background:#1d4ed8"></i>non-fused Laplace (dashed β€” overlaps fused)</span>
<span><i class="sw" style="background:#047857"></i>empirical SD-KDE</span>
</div>
<h2>Signed error, declared config <span>β€” mean of 3 per-replicate ISE/IAE, trapezoid, no clipping</span></h2>
<table id="mt">
<thead><tr><th>n<sub>train</sub></th><th>method</th><th>MISE</th><th>MIAE</th><th>∫neg mass</th><th>min pΜ‚</th><th>∫|pΜ‚|</th></tr></thead>
<tbody></tbody>
</table>
<p class="note">Laplace-corrected estimator integrates to 1.0000 but is signed (min βˆ’0.00419, ∫|pΜ‚| 1.00337 at n=4096); empirical SD-KDE has min 0.0 and ∫|pΜ‚| 1.0. MISE/MIAE here are the <em>mean of per-replicate</em> ISE/IAE; computing ISE of the replicate-averaged density instead would give 0.710Γ— (10 replicates) / 0.799Γ— (3) the reported value.</p>
<h2>Fused vs non-fused runtime <span>β€” authors' protocol, A10G (paper: RTX A6000)</span></h2>
<table id="rt">
<thead><tr><th>n<sub>train</sub></th><th>KDE ms</th><th>fused ms</th><th>non-fused ms</th><th>non-fused / fused</th><th>max |fused βˆ’ non-fused|</th></tr></thead>
<tbody></tbody>
</table>
<p class="note">The fused kernel is flat at ~0.19 ms (launch-bound over this range) while the non-fused path pays a second pass that scales with n β€” so the ratio is a function of n, not a constant. On CPU in NumPy the fused form is <em>slower</em> (0.1137 s vs 0.1013 s at n=4096): the throughput claim is about the fused GPU kernel, not the algebra. A second complete run of <code>run.py</code> on the same flavor gave fused 0.1838–0.1857 ms and ratios 1.99×–6.47Γ— β€” run-to-run variation of a few percent, so what reproduces is the <em>shape</em> of the ratio, not its exact value.</p>
<h2>Environment</h2>
<pre>python 3.12.16
numpy 2.5.5
torch 2.15.0+cu132 (pip: torch==2.15.0, CUDA build)
triton 3.9.0
CUDA 13.2 GPU: NVIDIA A10G, 80 SMs, 23.9 GB
OS Linux (HF Jobs a10g-small sandbox)
repo github.com/Elliotepsteino/Flash-SD-KDE @ acaf8712f8c146c837e1d1dcccb56ce6322962bc</pre>
<p class="note">Pinned in <code>requirements.txt</code>. The static Space only serves this page; <code>run.py</code> is the script that executes the experiment (needs a CUDA device for stage 3, <code>--skip-gpu</code> for stages 1–2).</p>
<h2>Files</h2>
<div class="files">
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/run.py">run.py</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/requirements.txt">requirements.txt</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/logs/run_full.log">logs/run_full.log</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/results/run_full.json">results/run_full.json</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/logs/run_cpu.log">logs/run_cpu.log</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/logs/gpu_a10g.log">logs/gpu_a10g.log</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/results/run_cpu.json">results/run_cpu.json</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/results/gpu_a10g.json">results/gpu_a10g.json</a>
<a href="https://huggingface.co/spaces/avengeryt22/flash-sd-kde-section5/blob/main/logs/agent_trace.md">logs/agent_trace.md</a>
<a href="https://huggingface.co/datasets/avengeryt22/flash-sd-kde-repro">data card (dataset)</a>
</div>
<h2>Logs, including failures</h2>
<ul>
<li><code>logs/run_full.log</code> β€” complete stdout of <code>python run.py</code> on an A10G: kernel checks, CPU statistics and the GPU timing arm in one run (exit 0, 36.3 s, all 10 checks PASS).</li>
<li><code>logs/run_cpu.log</code> β€” stdout of <code>python run.py --skip-gpu</code> on cpu-basic (exit 0, 24.4 s, all 9 CPU checks PASS).</li>
<li><code>logs/gpu_a10g.log</code> β€” the earlier two-script GPU arm, kept for comparison (exit 0).</li>
<li><strong>No experiment run failed.</strong> The only failure in the session was a sandbox RPC <code>503</code> while the GPU sandbox was still booting; it was retried once after a 45 s wait and succeeded. Nothing was lost, and it is recorded in <code>logs/agent_trace.md</code>.</li>
</ul>
<h2>Verdict and scope</h2>
<p><strong>Verified.</strong> All three parts of the claim survive an independent implementation: the kernel algebra is right, fusion does not perturb the estimator beyond float32 round-off, fusion is faster on GPU, and the Laplace estimator is statistically distinct from empirical SD-KDE (and signed, with non-zero negative mass).</p>
<p class="note"><strong>What this does not establish.</strong> (1) No universal speedup: 1.93×–6.20Γ— depends on n, on this A10G (80 SMs vs the paper's A6000 at 84) and on the launch-bound 1-D regime; no CPU speedup exists. (2) No nonnegative probability density: the estimator integrates to 1 but has negative values and negative mass. (3) "Distinct" is an estimator-class statement supported by a consistent ordering at all six n, not a significance test at 3 replicates. (4) In 1-D the Laplace estimator also wins MIAE, whereas the paper's 16-D text reports Flash-SD-KDE best on MIAE β€” a dimension-dependent ordering, not a contradiction. (5) Deviations: A10G not A6000; float64 gold pass added; 10 replicates run with the first 3 being the declared config; authors' gitbud plumbing bypassed while their timing code was copied verbatim.</p>
</div>
<script>
const NS = [128,256,512,1024,2048,4096];
const MISE = {
kde: [3.443534e-2,2.716252e-2,2.104447e-2,1.481243e-2,1.031128e-2,7.210927e-3],
fused: [1.803422e-2,1.163250e-2,7.187360e-3,3.811234e-3,1.794646e-3,1.114168e-3],
nf: [1.803422e-2,1.163250e-2,7.187361e-3,3.811234e-3,1.794646e-3,1.114168e-3],
emp: [3.036494e-2,2.159214e-2,1.488441e-2,8.751903e-3,4.942580e-3,2.801282e-3]
};
const MIAE = {
kde: [4.012539e-1,3.529606e-1,3.023905e-1,2.484110e-1,2.035583e-1,1.632502e-1],
fused: [2.866447e-1,2.159322e-1,1.692483e-1,1.189223e-1,8.097652e-2,6.500865e-2],
nf: [2.866447e-1,2.159322e-1,1.692483e-1,1.189224e-1,8.097654e-2,6.500866e-2],
emp: [3.698983e-1,3.052062e-1,2.465715e-1,1.813028e-1,1.326096e-1,9.741352e-2]
};
const NEG = [1.0205e-2,8.4782e-3,5.6989e-3,4.3889e-3,2.6419e-3,1.6873e-3];
const MIN = [-0.010938,-0.009890,-0.008887,-0.007688,-0.005405,-0.004193];
const L1 = [1.020411,1.016956,1.011398,1.008778,1.005284,1.003375];
const RT = [[128,0.2025,0.2002,0.3870,1.93,5.96e-8],[256,0.1905,0.1926,0.3911,2.03,8.94e-8],
[512,0.1958,0.1964,0.4030,2.05,8.94e-8],[1024,0.1939,0.1947,0.4716,2.42,8.94e-8],
[2048,0.1943,0.1950,0.7218,3.70,8.94e-8],[4096,0.2037,0.1932,1.1986,6.20,8.94e-8]];
const mt = document.querySelector('#mt tbody');
NS.forEach((n, i) => {
const rows = [
['plain KDE', MISE.kde[i], MIAE.kde[i], '0', '0.0', '1.0', ''],
['fused Laplace', MISE.fused[i], MIAE.fused[i], NEG[i].toExponential(3), MIN[i].toFixed(5), L1[i].toFixed(5), 'hi'],
['non-fused Laplace', MISE.nf[i], MIAE.nf[i], NEG[i].toExponential(3), MIN[i].toFixed(5), L1[i].toFixed(5), ''],
['empirical SD-KDE', MISE.emp[i], MIAE.emp[i], '0', '0.0', '1.0', '']
];
rows.forEach((r, j) => {
mt.insertAdjacentHTML('beforeend',
`<tr><td>${j === 0 ? n : ''}</td><td class="l">${r[0]}</td>` +
`<td class="${r[6]}">${r[1].toExponential(4)}</td><td>${r[2].toExponential(4)}</td>` +
`<td>${r[3]}</td><td>${r[4]}</td><td>${r[5]}</td></tr>`);
});
});
const rt = document.querySelector('#rt tbody');
RT.forEach(r => {
rt.insertAdjacentHTML('beforeend',
`<tr><td>${r[0]}</td><td>${r[1].toFixed(4)}</td><td class="hi">${r[2].toFixed(4)}</td>` +
`<td>${r[3].toFixed(4)}</td><td>${r[4].toFixed(2)}Γ—</td><td>${r[5].toExponential(1)}</td></tr>`);
});
function draw(id, series, opts) {
const cv = document.getElementById(id);
const dpr = window.devicePixelRatio || 1;
const W = cv.clientWidth, H = cv.clientHeight;
cv.width = W * dpr; cv.height = H * dpr;
const g = cv.getContext('2d');
g.setTransform(dpr, 0, 0, dpr, 0, 0);
g.clearRect(0, 0, W, H);
const pad = { l: 48, r: 8, t: 8, b: 24 };
const xs = NS.map(Math.log10);
let ys = [];
series.forEach(s => ys = ys.concat(s.data.map(Math.log10)));
const x0 = Math.min(...xs), x1 = Math.max(...xs);
let y0 = Math.min(...ys), y1 = Math.max(...ys);
const padY = (y1 - y0) * 0.08; y0 -= padY; y1 += padY;
const px = v => pad.l + (Math.log10(v) - x0) / (x1 - x0) * (W - pad.l - pad.r);
const py = v => pad.t + (y1 - Math.log10(v)) / (y1 - y0) * (H - pad.t - pad.b);
g.strokeStyle = '#f3f4f6'; g.lineWidth = 1;
g.font = '10px ui-sans-serif,sans-serif'; g.fillStyle = '#9ca3af'; g.textAlign = 'right';
opts.yticks.forEach(v => {
g.beginPath(); g.moveTo(pad.l, py(v)); g.lineTo(W - pad.r, py(v)); g.stroke();
g.fillText(opts.fmt(v), pad.l - 5, py(v) + 3);
});
g.textAlign = 'center';
NS.forEach(v => g.fillText(v, px(v), H - 7));
series.forEach(s => {
g.beginPath();
s.data.forEach((v, i) => i ? g.lineTo(px(NS[i]), py(v)) : g.moveTo(px(NS[i]), py(v)));
g.strokeStyle = s.color; g.lineWidth = s.w || 1.8;
g.setLineDash(s.dash || []);
g.stroke(); g.setLineDash([]);
if (!s.dash) s.data.forEach((v, i) => {
g.beginPath(); g.arc(px(NS[i]), py(v), 2.6, 0, 7); g.fillStyle = s.color; g.fill();
});
});
g.strokeStyle = '#e5e7eb'; g.lineWidth = 1;
g.beginPath(); g.moveTo(pad.l, pad.t); g.lineTo(pad.l, H - pad.b); g.lineTo(W - pad.r, H - pad.b); g.stroke();
}
draw('c1', [
{ data: MISE.kde, color: '#9ca3af' }, { data: MISE.fused, color: '#c2410c' },
{ data: MISE.nf, color: '#1d4ed8', dash: [4, 3], w: 1.2 }, { data: MISE.emp, color: '#047857' }
], { yticks: [1e-3, 3e-3, 1e-2, 3e-2], fmt: v => v.toExponential(0) });
draw('c2', [
{ data: MIAE.kde, color: '#9ca3af' }, { data: MIAE.fused, color: '#c2410c' },
{ data: MIAE.nf, color: '#1d4ed8', dash: [4, 3], w: 1.2 }, { data: MIAE.emp, color: '#047857' }
], { yticks: [6e-2, 1e-1, 2e-1, 4e-1], fmt: v => v.toFixed(1) });
draw('c3', [
{ data: [0.2002,0.1926,0.1964,0.1947,0.1950,0.1932], color: '#c2410c' },
{ data: [0.3870,0.3911,0.4030,0.4716,0.7218,1.1986], color: '#1d4ed8' }
], { yticks: [0.2, 0.4, 0.8, 1.2], fmt: v => v.toFixed(1) });
</script>
</body>
</html>