Spaces:
Running
Running
Count every model load, like from_pretrained
Browse files- js/agate.js +4 -9
js/agate.js
CHANGED
|
@@ -63,14 +63,9 @@ export async function hasCachedModel() {
|
|
| 63 |
export async function clearCache() { try { return await caches.delete(CACHE_NAME); } catch { return false; } }
|
| 64 |
|
| 65 |
// The Hub counts a model download only on a request for the model repo's root config.json; the ONNX files
|
| 66 |
-
// come from this Space, so
|
| 67 |
-
|
| 68 |
-
function
|
| 69 |
-
try { if (localStorage.getItem(COUNT_KEY)) return; } catch { /* storage blocked: still count this load */ }
|
| 70 |
-
fetch(COUNT_URL, { cache: "no-store" })
|
| 71 |
-
.then((r) => { if (r.ok) { try { localStorage.setItem(COUNT_KEY, String(Date.now())); } catch { /* ignore */ } } })
|
| 72 |
-
.catch(() => {});
|
| 73 |
-
}
|
| 74 |
|
| 75 |
// ---- the model ---------------------------------------------------------------------------------
|
| 76 |
export class Agate {
|
|
@@ -100,7 +95,7 @@ export class Agate {
|
|
| 100 |
bufs[f] = buf;
|
| 101 |
}
|
| 102 |
this.stats = { downloadMB: total / 1e6, fromCacheMB: fromCache / 1e6, downloadMs: performance.now() - t0 };
|
| 103 |
-
|
| 104 |
// drop cached files of older model versions (keys carry the sha256)
|
| 105 |
try {
|
| 106 |
const cache = await openCache(), keep = new Set(MODEL_FILES.map((f) => new URL(`${this.base}${real(f)}?sha256=${manifest.files[real(f)].sha256}`, location.href).href));
|
|
|
|
| 63 |
export async function clearCache() { try { return await caches.delete(CACHE_NAME); } catch { return false; } }
|
| 64 |
|
| 65 |
// The Hub counts a model download only on a request for the model repo's root config.json; the ONNX files
|
| 66 |
+
// come from this Space, so every model load reads it once -- the same per-load count a Python
|
| 67 |
+
// from_pretrained() produces, cached weights or not.
|
| 68 |
+
function countLoad() { fetch(COUNT_URL, { cache: "no-store" }).catch(() => {}); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
// ---- the model ---------------------------------------------------------------------------------
|
| 71 |
export class Agate {
|
|
|
|
| 95 |
bufs[f] = buf;
|
| 96 |
}
|
| 97 |
this.stats = { downloadMB: total / 1e6, fromCacheMB: fromCache / 1e6, downloadMs: performance.now() - t0 };
|
| 98 |
+
countLoad();
|
| 99 |
// drop cached files of older model versions (keys carry the sha256)
|
| 100 |
try {
|
| 101 |
const cache = await openCache(), keep = new Set(MODEL_FILES.map((f) => new URL(`${this.base}${real(f)}?sha256=${manifest.files[real(f)].sha256}`, location.href).href));
|