ablation-lab / frontend /src /lib /format.ts
philippyt's picture
MVP1: working prototype of transformer ablation playground. web app for composing tiny transformer architectures, running real inference, and seeing how each architectural switch affects cost and quality. Hash-stable arch_config shared between Python and TS; closed-form cost formulas parity-tested against actual sum(p.numel())
84702bc
Raw History Blame Contribute Delete
802 Bytes
export function fmtBytes(n: number): string {
if (n < 1024) return `${n} B`;
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(2)} MB`;
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
}
export function fmtParams(n: number): string {
if (n < 1000) return `${n}`;
if (n < 1_000_000) return `${(n / 1000).toFixed(1)}K`;
if (n < 1_000_000_000) return `${(n / 1_000_000).toFixed(2)}M`;
return `${(n / 1_000_000_000).toFixed(2)}B`;
}
export function fmtPercent(x: number): string {
const sign = x > 0 ? "+" : "";
return `${sign}${(x * 100).toFixed(0)}%`;
}
export function relativeChange(oldV: number, newV: number): number {
if (oldV === 0) return newV === 0 ? 0 : 1;
return (newV - oldV) / oldV;
}