Spaces:
Running
Running
Upload fork.js with huggingface_hub
Browse files
fork.js
CHANGED
|
@@ -52,16 +52,16 @@ function rig() {
|
|
| 52 |
function query(append) {
|
| 53 |
const r = rig();
|
| 54 |
const pair = $("#kv").value;
|
| 55 |
-
// upstream kv_type only accepts f16/q8_0/q4_0 with K=V
|
| 56 |
-
//
|
| 57 |
-
//
|
| 58 |
-
//
|
| 59 |
-
|
| 60 |
-
const rescaled = kvScale(pair) < 1;
|
| 61 |
return {
|
| 62 |
hardware: { kind: r.kind, gpus: r.gpus, ram_gb: r.ram_gb,
|
| 63 |
...(r.unified_system ? { unified_system: r.unified_system } : {}) },
|
| 64 |
-
context: +$("#ctx").value, kv_type: "f16", kv_pair: pair,
|
| 65 |
min_bits: +$("#min-bits").value,
|
| 66 |
sort: $("#sort").value, family: $("#family").value || null, size: $("#size").value || null,
|
| 67 |
search: $("#search").value.trim() || null,
|
|
@@ -319,7 +319,10 @@ function kvScale(pair) {
|
|
| 319 |
// pass through untouched. Only full tiers and failing tiers are adjusted;
|
| 320 |
// partial offloads keep the estimator's f16 numbers (conservative).
|
| 321 |
function rescaleKvFits(d, pair, ctx, hw) {
|
| 322 |
-
|
|
|
|
|
|
|
|
|
|
| 323 |
if (!(ratio < 1)) return;
|
| 324 |
const kvf = d.kv_cache_gb && d.kv_cache_gb[String(ctx)];
|
| 325 |
if (!(kvf > 0)) return;
|
|
@@ -328,14 +331,20 @@ function rescaleKvFits(d, pair, ctx, hw) {
|
|
| 328 |
d.kv_cache_gb = scaled;
|
| 329 |
const delta = kvf * (1 - ratio);
|
| 330 |
const vram = hw.kind === "gpu" ? hw.gpus.reduce((a, x) => a + x, 0) : 0;
|
| 331 |
-
// per-model overhead + RAM constant
|
| 332 |
-
//
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
if (
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
}
|
| 340 |
const full = (o, tier, gpuGb, ramGb, label) => {
|
| 341 |
o.fit.tier = tier; o.fit.gpu_gb = gpuGb; o.fit.ram_gb = ramGb;
|
|
|
|
| 52 |
function query(append) {
|
| 53 |
const r = rig();
|
| 54 |
const pair = $("#kv").value;
|
| 55 |
+
// upstream kv_type only accepts f16/q8_0/q4_0 with K=V. ask q8_0 and
|
| 56 |
+
// rescale client-side (rescaleKvFits): q8_0-based scores and fits are
|
| 57 |
+
// close to every smaller pair, so the page stays nearly consistent
|
| 58 |
+
// (an f16 base would leave every score stale). f16/bf16 ask f16.
|
| 59 |
+
const q8base = pair !== "f16/f16" && pair !== "bf16/bf16";
|
| 60 |
+
const rescaled = q8base ? kvScale(pair) * 16 / 8.5 < 1 : false;
|
| 61 |
return {
|
| 62 |
hardware: { kind: r.kind, gpus: r.gpus, ram_gb: r.ram_gb,
|
| 63 |
...(r.unified_system ? { unified_system: r.unified_system } : {}) },
|
| 64 |
+
context: +$("#ctx").value, kv_type: q8base ? "q8_0" : "f16", kv_pair: pair,
|
| 65 |
min_bits: +$("#min-bits").value,
|
| 66 |
sort: $("#sort").value, family: $("#family").value || null, size: $("#size").value || null,
|
| 67 |
search: $("#search").value.trim() || null,
|
|
|
|
| 319 |
// pass through untouched. Only full tiers and failing tiers are adjusted;
|
| 320 |
// partial offloads keep the estimator's f16 numbers (conservative).
|
| 321 |
function rescaleKvFits(d, pair, ctx, hw) {
|
| 322 |
+
// ratio is against the queried base: q8_0 for everything below it,
|
| 323 |
+
// f16 for f16/bf16 (ratio 1, no-op). see query().
|
| 324 |
+
const base = pair === "f16/f16" || pair === "bf16/bf16" ? 16 : 8.5;
|
| 325 |
+
const ratio = kvScale(pair) * 16 / base;
|
| 326 |
if (!(ratio < 1)) return;
|
| 327 |
const kvf = d.kv_cache_gb && d.kv_cache_gb[String(ctx)];
|
| 328 |
if (!(kvf > 0)) return;
|
|
|
|
| 331 |
d.kv_cache_gb = scaled;
|
| 332 |
const delta = kvf * (1 - ratio);
|
| 333 |
const vram = hw.kind === "gpu" ? hw.gpus.reduce((a, x) => a + x, 0) : 0;
|
| 334 |
+
// per-model overhead + RAM constant: median over the estimator's own
|
| 335 |
+
// full-gpu options (single-option calibration flips picks on 0.2GB
|
| 336 |
+
// noise; the backend's implied overhead spans ~1.7-2.8 per model).
|
| 337 |
+
let oh = 1.75, ramConst = 1.2;
|
| 338 |
+
const gpuRefs = (d.options || []).filter((o) => o.fit && o.fit.tier === "gpu");
|
| 339 |
+
if (gpuRefs.length) {
|
| 340 |
+
const med = (xs) => { const s = xs.filter((x) => x > 0).sort((a, b) => a - b);
|
| 341 |
+
return s.length ? s[Math.floor(s.length / 2)] : null; };
|
| 342 |
+
oh = med(gpuRefs.map((o) => (o.fit.gpu_gb || 0) - o.size / 1e9 - kvf)) ?? oh;
|
| 343 |
+
ramConst = med(gpuRefs.map((o) => o.fit.ram_gb || 0)) ?? ramConst;
|
| 344 |
+
} else {
|
| 345 |
+
const ref = (d.options || []).find((o) => o.fit &&
|
| 346 |
+
(o.fit.tier === "cpu" || o.fit.tier === "ram"));
|
| 347 |
+
if (ref) oh = Math.max(0, (ref.fit.gpu_gb || ref.fit.ram_gb || 0) - ref.size / 1e9 - kvf);
|
| 348 |
}
|
| 349 |
const full = (o, tier, gpuGb, ramGb, label) => {
|
| 350 |
o.fit.tier = tier; o.fit.gpu_gb = gpuGb; o.fit.ram_gb = ramGb;
|