Spaces:
Running
Running
pack precision map
Browse files- app.js +12 -3
- precision_map.js +34 -6
- progress.js +123 -0
app.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
| 7 |
* from the one that was tested.
|
| 8 |
*/
|
| 9 |
import { FORMATS, RULES_MEASURED_ON, inspect } from './precision_map.js';
|
|
|
|
| 10 |
|
| 11 |
const $ = (id) => document.getElementById(id);
|
| 12 |
const out = $('out');
|
|
@@ -130,12 +131,20 @@ function tableFamilies(r, fullTotal) {
|
|
| 130 |
async function run(repo) {
|
| 131 |
const go = $('go');
|
| 132 |
go.disabled = true;
|
| 133 |
-
|
|
|
|
|
|
|
| 134 |
try {
|
| 135 |
const r = await inspect(repo, (done, total) => {
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
});
|
|
|
|
| 139 |
out.innerHTML = render(r);
|
| 140 |
} catch (e) {
|
| 141 |
out.innerHTML = card('problem', 'Could not read the repo',
|
|
|
|
| 7 |
* from the one that was tested.
|
| 8 |
*/
|
| 9 |
import { FORMATS, RULES_MEASURED_ON, inspect } from './precision_map.js';
|
| 10 |
+
import { progress } from './progress.js';
|
| 11 |
|
| 12 |
const $ = (id) => document.getElementById(id);
|
| 13 |
const out = $('out');
|
|
|
|
| 131 |
async function run(repo) {
|
| 132 |
const go = $('go');
|
| 133 |
go.disabled = true;
|
| 134 |
+
// Indeterminate until the shard count is known — reading config.json
|
| 135 |
+
// and the shard index says nothing about how much work follows.
|
| 136 |
+
const pg = progress(out).start(`reading ${repo}`);
|
| 137 |
try {
|
| 138 |
const r = await inspect(repo, (done, total) => {
|
| 139 |
+
if (done === 0) {
|
| 140 |
+
pg.total(total).start(total === 1
|
| 141 |
+
? 'reading the safetensors header'
|
| 142 |
+
: `reading ${total} safetensors headers`);
|
| 143 |
+
} else {
|
| 144 |
+
pg.step();
|
| 145 |
+
}
|
| 146 |
});
|
| 147 |
+
pg.done();
|
| 148 |
out.innerHTML = render(r);
|
| 149 |
} catch (e) {
|
| 150 |
out.innerHTML = card('problem', 'Could not read the repo',
|
precision_map.js
CHANGED
|
@@ -241,8 +241,21 @@ export function summarize(tensors, method) {
|
|
| 241 |
}
|
| 242 |
|
| 243 |
const total = Object.values(buckets).reduce((a, b) => a + b, 0) || 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
const sortDesc = (o) => Object.fromEntries(
|
| 245 |
-
Object.entries(o).sort((a, b) => b[1] - a[1]));
|
| 246 |
|
| 247 |
return {
|
| 248 |
method,
|
|
@@ -339,12 +352,27 @@ export async function inspect(repoId, onProgress = () => {}) {
|
|
| 339 |
+ 'from metadata');
|
| 340 |
}
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
const tensors = [];
|
| 343 |
-
let
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
|
| 349 |
return {
|
| 350 |
repo: repoId,
|
|
|
|
| 241 |
}
|
| 242 |
|
| 243 |
const total = Object.values(buckets).reduce((a, b) => a + b, 0) || 1;
|
| 244 |
+
// Largest first, ties broken by name. The tie is not hypothetical: an
|
| 245 |
+
// untied model's embeddings and output head are the same tensor
|
| 246 |
+
// transposed, so their byte counts are equal exactly. Shards are read
|
| 247 |
+
// concurrently, so without the second key those two rows would swap
|
| 248 |
+
// between runs of the same pack — and a report that changes when
|
| 249 |
+
// nothing changed is a report nobody can quote.
|
| 250 |
+
//
|
| 251 |
+
// Compared by code point, not localeCompare: Python's `sorted` orders
|
| 252 |
+
// by code point, and a locale-aware comparison disagrees with it on
|
| 253 |
+
// case and punctuation. The parity gate can only catch that when a
|
| 254 |
+
// fixture happens to contain a tie, so the two are made to agree by
|
| 255 |
+
// construction instead of by luck.
|
| 256 |
+
const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
| 257 |
const sortDesc = (o) => Object.fromEntries(
|
| 258 |
+
Object.entries(o).sort((a, b) => b[1] - a[1] || byName(a[0], b[0])));
|
| 259 |
|
| 260 |
return {
|
| 261 |
method,
|
|
|
|
| 352 |
+ 'from metadata');
|
| 353 |
}
|
| 354 |
|
| 355 |
+
onProgress(0, files.length);
|
| 356 |
+
|
| 357 |
+
// Read the shards a few at a time rather than one after another. A
|
| 358 |
+
// 70B pack is nine shards and two ranged requests each; sequentially
|
| 359 |
+
// that is long enough that the page reads as broken. Four at a time
|
| 360 |
+
// is enough to hide most of the latency without opening a burst of
|
| 361 |
+
// connections against the Hub for a page that is only reading
|
| 362 |
+
// metadata.
|
| 363 |
const tensors = [];
|
| 364 |
+
let next = 0;
|
| 365 |
+
let finished = 0;
|
| 366 |
+
const worker = async () => {
|
| 367 |
+
while (next < files.length) {
|
| 368 |
+
const mine = files[next++];
|
| 369 |
+
const got = await readHeader(repoId, mine);
|
| 370 |
+
tensors.push(...got);
|
| 371 |
+
onProgress(++finished, files.length);
|
| 372 |
+
}
|
| 373 |
+
};
|
| 374 |
+
await Promise.all(
|
| 375 |
+
Array.from({ length: Math.min(4, files.length) }, worker));
|
| 376 |
|
| 377 |
return {
|
| 378 |
repo: repoId,
|
progress.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* The progress bar the three Spaces share.
|
| 3 |
+
*
|
| 4 |
+
* Every one of them reads safetensors headers over ranged requests — two
|
| 5 |
+
* per shard, and a large model has a dozen shards. That is seconds of
|
| 6 |
+
* silence behind a line of static text, which reads as a page that does
|
| 7 |
+
* not work. The bar exists so waiting looks like waiting.
|
| 8 |
+
*
|
| 9 |
+
* One file, copied into each Space at deploy time rather than written
|
| 10 |
+
* three times: three copies of a progress bar drift into three different
|
| 11 |
+
* behaviours, and the one that matters here is subtle — a bar that goes
|
| 12 |
+
* backwards, or sits at 100% while work continues, is worse than no bar,
|
| 13 |
+
* because it is believed.
|
| 14 |
+
*
|
| 15 |
+
* Two modes, and which one is honest depends on what is known:
|
| 16 |
+
*
|
| 17 |
+
* start(label) indeterminate — something is happening, and
|
| 18 |
+
* nobody knows how much of it there is yet
|
| 19 |
+
* total(n) switches to determinate once the shard count
|
| 20 |
+
* is known
|
| 21 |
+
* step(label) one unit done
|
| 22 |
+
* done() / fail() release it
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
const BAR_CSS = `
|
| 26 |
+
.pg { margin: 1.25rem 0 .5rem; }
|
| 27 |
+
.pg-label { font-size: .88rem; color: var(--muted); margin-bottom: .45rem;
|
| 28 |
+
display: flex; justify-content: space-between; gap: 1rem; }
|
| 29 |
+
.pg-count { font-family: var(--mono); font-size: .82rem; white-space: nowrap; }
|
| 30 |
+
.pg-track { height: .4rem; border-radius: .2rem; background: var(--line);
|
| 31 |
+
overflow: hidden; position: relative; }
|
| 32 |
+
.pg-fill { height: 100%; background: var(--accent); border-radius: .2rem;
|
| 33 |
+
width: 0; transition: width .18s ease-out; }
|
| 34 |
+
.pg-track.indeterminate .pg-fill {
|
| 35 |
+
width: 35%; animation: pg-slide 1.1s ease-in-out infinite;
|
| 36 |
+
}
|
| 37 |
+
@keyframes pg-slide {
|
| 38 |
+
0% { transform: translateX(-100%); }
|
| 39 |
+
100% { transform: translateX(300%); }
|
| 40 |
+
}
|
| 41 |
+
@media (prefers-reduced-motion: reduce) {
|
| 42 |
+
.pg-track.indeterminate .pg-fill { animation: none; width: 100%; opacity: .45; }
|
| 43 |
+
.pg-fill { transition: none; }
|
| 44 |
+
}`;
|
| 45 |
+
|
| 46 |
+
let styled = false;
|
| 47 |
+
|
| 48 |
+
function ensureStyle() {
|
| 49 |
+
if (styled) return;
|
| 50 |
+
const el = document.createElement('style');
|
| 51 |
+
el.textContent = BAR_CSS;
|
| 52 |
+
document.head.appendChild(el);
|
| 53 |
+
styled = true;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* A progress bar mounted in `host`.
|
| 58 |
+
*
|
| 59 |
+
* It replaces the host's contents, so the caller renders the result into
|
| 60 |
+
* the same element when it finishes and the bar disappears with it.
|
| 61 |
+
*/
|
| 62 |
+
export function progress(host) {
|
| 63 |
+
ensureStyle();
|
| 64 |
+
let done = 0;
|
| 65 |
+
let total = 0;
|
| 66 |
+
|
| 67 |
+
host.innerHTML = `<div class="pg">
|
| 68 |
+
<div class="pg-label"><span class="pg-text"></span><span class="pg-count"></span></div>
|
| 69 |
+
<div class="pg-track indeterminate"><div class="pg-fill"></div></div>
|
| 70 |
+
</div>`;
|
| 71 |
+
|
| 72 |
+
const text = host.querySelector('.pg-text');
|
| 73 |
+
const count = host.querySelector('.pg-count');
|
| 74 |
+
const track = host.querySelector('.pg-track');
|
| 75 |
+
const fill = host.querySelector('.pg-fill');
|
| 76 |
+
|
| 77 |
+
const paint = () => {
|
| 78 |
+
if (!total) return;
|
| 79 |
+
// Never let the bar reach the end before the work does: a full bar
|
| 80 |
+
// with the page still frozen is exactly the impression this is here
|
| 81 |
+
// to remove. It closes only in done().
|
| 82 |
+
const pctDone = Math.min(99, Math.round((done / total) * 100));
|
| 83 |
+
fill.style.width = `${pctDone}%`;
|
| 84 |
+
count.textContent = `${done} / ${total}`;
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
return {
|
| 88 |
+
/** Say what is happening now, without claiming to know how long. */
|
| 89 |
+
start(label) {
|
| 90 |
+
text.textContent = label;
|
| 91 |
+
return this;
|
| 92 |
+
},
|
| 93 |
+
/**
|
| 94 |
+
* Begin a determinate phase of `n` units.
|
| 95 |
+
*
|
| 96 |
+
* Resets the count, because a second call means a second phase — the
|
| 97 |
+
* integrity checker reads the pack and then the source model, and
|
| 98 |
+
* without the reset the bar would show "12 / 5" and run past its own
|
| 99 |
+
* end.
|
| 100 |
+
*/
|
| 101 |
+
total(n) {
|
| 102 |
+
total = n;
|
| 103 |
+
done = 0;
|
| 104 |
+
track.classList.remove('indeterminate');
|
| 105 |
+
paint();
|
| 106 |
+
return this;
|
| 107 |
+
},
|
| 108 |
+
/** One unit finished. Safe to call before total() — it just counts. */
|
| 109 |
+
step(label) {
|
| 110 |
+
done += 1;
|
| 111 |
+
if (label) text.textContent = label;
|
| 112 |
+
paint();
|
| 113 |
+
return this;
|
| 114 |
+
},
|
| 115 |
+
/** Fill it before the caller replaces the host with the result. */
|
| 116 |
+
done() {
|
| 117 |
+
track.classList.remove('indeterminate');
|
| 118 |
+
fill.style.width = '100%';
|
| 119 |
+
if (total) count.textContent = `${total} / ${total}`;
|
| 120 |
+
return this;
|
| 121 |
+
},
|
| 122 |
+
};
|
| 123 |
+
}
|