/** * The page: one repo id in, one honest breakdown out. * * Every rule lives in precision_map.js, which the parity gate holds to * the Python implementation. Nothing here decides anything — it fetches, * calls, and renders, so a rule can never be quietly different in the UI * from the one that was tested. */ import { FORMATS, RULES_MEASURED_ON, inspect } from './precision_map.js'; import { progress } from './progress.js'; import { ensureNextStepStyles, nextSteps, repoFromUrl } from './tools.js'; const $ = (id) => document.getElementById(id); // A link from another tool carries the model over; arriving at an empty // form is what makes five tools feel like five tools instead of one. ensureNextStepStyles(); const carried = repoFromUrl(); if (carried) { $('repo').value = carried; } const out = $('out'); const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); const GIB = 1024 ** 3; const gib = (b) => (b / GIB >= 0.01 ? `${(b / GIB).toFixed(2)} GiB` : `${(b / (1024 ** 2)).toFixed(0)} MiB`); const pct = (part, whole) => `${((part / whole) * 100).toFixed(1)}%`; function renderFormats() { $('formats').innerHTML = Object.entries(FORMATS).map(([method, f]) => ` ${esc(method)} ${esc(f.tool)} ${f.producer ? `${esc(f.producer.join('.').replace('config.', ''))}` : 'records none'} ${esc(f.verifiedOn)} `).join(''); } function card(cls, title, body) { return `

${title}

${body}
`; } /** The stacked bar. Three categories, in the order they are explained. */ function bar(b, total) { const seg = (k, cls) => (b[k] > 0 ? `` : ''); return `
${seg('quantized', 'q')}${seg('metadata', 'm')}${seg('full', 'f')}${seg('buffer', 'b')}
`; } function render(r) { const b = r.buckets; const t = r.totalBytes; const version = r.producerVersion ? `${esc(r.producerVersion)}` : 'no version recorded in the pack'; const meta = `
repo ${esc(r.repo)} declared ${esc(r.method)} ${r.shards} shard${r.shards === 1 ? '' : 's'}, ${r.tensorCount} tensors
`; if (!r.knownFormat && r.method !== 'none') { return meta + card('check', `No convention on file for ${esc(r.method)}`, `

This reader has never been verified against a ${esc(r.method)} pack, so the split below rests on dtypes alone and the metadata line may be undercounted. Treat it as an estimate, not a reading.

` + bar(b, t) + table(r)); } if (!r.recognised) { return meta + card('problem', 'This layout is not understood', `

The pack declares ${esc(r.method)}, which quantizes something — but no tensor here is in a packed dtype or under a packed name. Either the convention moved since ${esc(RULES_MEASURED_ON)}, or this pack stores its weights somewhere this cannot see.

No breakdown is shown, on purpose. A number here would look like a measurement and be a guess.

`); } if (r.method === 'none') { return meta + card('clear', 'Not quantized', `

Every tensor is at full precision — ${esc(gib(b.full))} of it. No quantization method is declared and none is detectable from the dtypes.

` + tableFamilies(r, b.full)); } const headline = `${pct(b.full, t)} of this pack is still full precision`; return meta + card('check', headline, `

Written by ${esc(r.tool)}, ${version}.

` + bar(b, t) + table(r) + `

What stayed whole

` + tableFamilies(r, b.full) + (r.headQuantized ? `

The output head is quantized. That is a real choice with a real cost: measured on this repo's own weights, quantizing lm_head flips the model's chosen token on about a fifth of positions. It buys size; it is worth knowing you bought it.

` : `

The output head was left at full precision — the usual choice, and the reason a "4-bit" pack is never 4-bit throughout.

`) + (r.unknownDtypes.length ? `

Unknown dtypes counted at 2 bytes: ${r.unknownDtypes.map(esc).join(', ')}.

` : '')); } function table(r) { const b = r.buckets; const t = r.totalBytes; const row = (label, key, why) => (b[key] > 0 ? `${label}${gib(b[key])} ${pct(b[key], t)}${why}` : ''); return `
${row('Quantized payload', 'quantized', 'the weights that were compressed')} ${row('Quantization data', 'metadata', 'scales, zero points, group indices')} ${row('Full precision', 'full', 'never quantized, at source precision')} ${row('Index buffers', 'buffer', 'positions, masks, stored shapes')}
`; } function tableFamilies(r, fullTotal) { const rows = Object.entries(r.fullByFamily); if (!rows.length) return ''; return `
${rows.map(([fam, size]) => ``).join('')}
${esc(fam)}${gib(size)} ${pct(size, fullTotal)}
`; } async function run(repo) { const go = $('go'); go.disabled = true; // Indeterminate until the shard count is known — reading config.json // and the shard index says nothing about how much work follows. const pg = progress(out).start(`reading ${repo}`); try { const r = await inspect(repo, (done, total) => { if (done === 0) { pg.total(total).start(total === 1 ? 'reading the safetensors header' : `reading ${total} safetensors headers`); } else { pg.step(); } }); pg.done(); out.innerHTML = render(r) + nextSteps('precision', repo); } catch (e) { out.innerHTML = card('problem', 'Could not read the repo', `

${esc(e.message || e)}

Gated and private repos cannot be read from the browser.

`); } finally { go.disabled = false; } } $('form').addEventListener('submit', (e) => { e.preventDefault(); const v = $('repo').value.trim(); if (v) run(v); }); document.querySelectorAll('[data-ex]').forEach((btn) => btn.addEventListener('click', () => { $('repo').value = btn.dataset.ex; run(btn.dataset.ex); })); $('measured').textContent = RULES_MEASURED_ON; renderFormats();