hiaripc commited on
Commit ·
09ce416
1
Parent(s): 5aa28ba
restrictions and validated
Browse files- app.js +155 -8
- index.html +12 -1
app.js
CHANGED
|
@@ -9,6 +9,51 @@ const THETA2 = 1.010e-9;
|
|
| 9 |
const THETA3 = 5.550e-10;
|
| 10 |
const THETA4 = 2.045e-7;
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
function computeComponents(d,L,nq,nkv,nin,nout)
|
| 14 |
{
|
|
@@ -275,6 +320,92 @@ function draw()
|
|
| 275 |
|
| 276 |
}
|
| 277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
async function loadModel()
|
| 279 |
{
|
| 280 |
|
|
@@ -282,12 +413,12 @@ async function loadModel()
|
|
| 282 |
document.getElementById("repo").value.trim();
|
| 283 |
|
| 284 |
|
| 285 |
-
|
| 286 |
-
{
|
| 287 |
-
alert("Use org/model format");
|
| 288 |
-
return;
|
| 289 |
-
}
|
| 290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
let url =
|
| 293 |
`https://huggingface.co/${repo}/resolve/main/config.json`;
|
|
@@ -301,13 +432,21 @@ async function loadModel()
|
|
| 301 |
|
| 302 |
|
| 303 |
if(!response.ok)
|
| 304 |
-
throw Error(
|
|
|
|
|
|
|
| 305 |
|
| 306 |
|
| 307 |
let cfg =
|
| 308 |
await response.json();
|
| 309 |
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
let d =
|
| 312 |
cfg.hidden_size ||
|
| 313 |
cfg.d_model ||
|
|
@@ -330,15 +469,20 @@ async function loadModel()
|
|
| 330 |
nq;
|
| 331 |
|
| 332 |
|
|
|
|
| 333 |
document.getElementById("d").value=d;
|
| 334 |
document.getElementById("L").value=L;
|
| 335 |
document.getElementById("nq").value=nq;
|
| 336 |
document.getElementById("nkv").value=nkv;
|
| 337 |
|
| 338 |
|
|
|
|
| 339 |
document.getElementById("status").innerHTML =
|
| 340 |
`
|
| 341 |
-
Loaded ${repo}<br>
|
|
|
|
|
|
|
|
|
|
| 342 |
d=${d},
|
| 343 |
L=${L},
|
| 344 |
nq=${nq},
|
|
@@ -348,11 +492,14 @@ async function loadModel()
|
|
| 348 |
|
| 349 |
draw();
|
| 350 |
|
|
|
|
| 351 |
}
|
| 352 |
catch(e)
|
| 353 |
{
|
|
|
|
| 354 |
document.getElementById("status").innerHTML =
|
| 355 |
-
"
|
|
|
|
| 356 |
}
|
| 357 |
|
| 358 |
}
|
|
|
|
| 9 |
const THETA3 = 5.550e-10;
|
| 10 |
const THETA4 = 2.045e-7;
|
| 11 |
|
| 12 |
+
const PRESET_MODELS =
|
| 13 |
+
{
|
| 14 |
+
"Falcon-RW 7B": "tiiuae/falcon-rw-7b",
|
| 15 |
+
"OPT 1.3B": "facebook/opt-1.3b",
|
| 16 |
+
"OPT 2.7B": "facebook/opt-2.7b",
|
| 17 |
+
"OPT 6.7B": "facebook/opt-6.7b",
|
| 18 |
+
"Qwen2 1.5B": "Qwen/Qwen2-1.5B",
|
| 19 |
+
"Qwen2 7B": "Qwen/Qwen2-7B"
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
window.onload = function()
|
| 23 |
+
{
|
| 24 |
+
|
| 25 |
+
let selector =
|
| 26 |
+
document.getElementById("preset");
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
for(let name in PRESET_MODELS)
|
| 30 |
+
{
|
| 31 |
+
let option =
|
| 32 |
+
document.createElement("option");
|
| 33 |
+
|
| 34 |
+
option.text=name;
|
| 35 |
+
|
| 36 |
+
option.value=
|
| 37 |
+
PRESET_MODELS[name];
|
| 38 |
+
|
| 39 |
+
selector.add(option);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
draw();
|
| 44 |
+
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
async function loadPreset()
|
| 48 |
+
{
|
| 49 |
+
|
| 50 |
+
let repo =
|
| 51 |
+
document.getElementById("preset").value;
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
await loadRepo(repo);
|
| 55 |
+
|
| 56 |
+
}
|
| 57 |
|
| 58 |
function computeComponents(d,L,nq,nkv,nin,nout)
|
| 59 |
{
|
|
|
|
| 320 |
|
| 321 |
}
|
| 322 |
|
| 323 |
+
function validateModel(cfg)
|
| 324 |
+
{
|
| 325 |
+
|
| 326 |
+
// ------------------------------
|
| 327 |
+
// Reject Mixture-of-Experts models
|
| 328 |
+
// ------------------------------
|
| 329 |
+
|
| 330 |
+
const moeKeys =
|
| 331 |
+
[
|
| 332 |
+
"num_experts",
|
| 333 |
+
"num_local_experts",
|
| 334 |
+
"num_experts_per_tok",
|
| 335 |
+
"num_sparse_layers",
|
| 336 |
+
"router_aux_loss_coef",
|
| 337 |
+
"moe_layer_freq"
|
| 338 |
+
];
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
for (let key of moeKeys)
|
| 342 |
+
{
|
| 343 |
+
if (cfg[key] !== undefined)
|
| 344 |
+
{
|
| 345 |
+
throw new Error(
|
| 346 |
+
"MoE models are not supported. "
|
| 347 |
+
+"Please select a dense Transformer model."
|
| 348 |
+
);
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
// ------------------------------
|
| 355 |
+
// Estimate parameter count
|
| 356 |
+
// ------------------------------
|
| 357 |
+
|
| 358 |
+
let d =
|
| 359 |
+
cfg.hidden_size ||
|
| 360 |
+
cfg.d_model ||
|
| 361 |
+
cfg.n_embd;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
let L =
|
| 365 |
+
cfg.num_hidden_layers ||
|
| 366 |
+
cfg.num_layers ||
|
| 367 |
+
cfg.n_layer;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
if(!d || !L)
|
| 371 |
+
{
|
| 372 |
+
throw new Error(
|
| 373 |
+
"Cannot estimate model size from config.json"
|
| 374 |
+
);
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
// Dense Transformer approximation
|
| 379 |
+
let params =
|
| 380 |
+
12 * L * d * d;
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
let paramsB =
|
| 384 |
+
params / 1e9;
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
// ------------------------------
|
| 389 |
+
// Size restriction
|
| 390 |
+
// ------------------------------
|
| 391 |
+
|
| 392 |
+
const MAX_PARAMS_B = 20;
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
if(paramsB > MAX_PARAMS_B)
|
| 396 |
+
{
|
| 397 |
+
throw new Error(
|
| 398 |
+
`Model too large (~${paramsB.toFixed(1)}B parameters). `
|
| 399 |
+
+
|
| 400 |
+
`Only dense models below ${MAX_PARAMS_B}B are allowed.`
|
| 401 |
+
);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
return paramsB;
|
| 406 |
+
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
async function loadModel()
|
| 410 |
{
|
| 411 |
|
|
|
|
| 413 |
document.getElementById("repo").value.trim();
|
| 414 |
|
| 415 |
|
| 416 |
+
await loadRepo(repo);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
async function loadRepo(repo)
|
| 421 |
+
{
|
| 422 |
|
| 423 |
let url =
|
| 424 |
`https://huggingface.co/${repo}/resolve/main/config.json`;
|
|
|
|
| 432 |
|
| 433 |
|
| 434 |
if(!response.ok)
|
| 435 |
+
throw Error(
|
| 436 |
+
"Could not load config.json"
|
| 437 |
+
);
|
| 438 |
|
| 439 |
|
| 440 |
let cfg =
|
| 441 |
await response.json();
|
| 442 |
|
| 443 |
|
| 444 |
+
|
| 445 |
+
let paramsB =
|
| 446 |
+
validateModel(cfg);
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
|
| 450 |
let d =
|
| 451 |
cfg.hidden_size ||
|
| 452 |
cfg.d_model ||
|
|
|
|
| 469 |
nq;
|
| 470 |
|
| 471 |
|
| 472 |
+
|
| 473 |
document.getElementById("d").value=d;
|
| 474 |
document.getElementById("L").value=L;
|
| 475 |
document.getElementById("nq").value=nq;
|
| 476 |
document.getElementById("nkv").value=nkv;
|
| 477 |
|
| 478 |
|
| 479 |
+
|
| 480 |
document.getElementById("status").innerHTML =
|
| 481 |
`
|
| 482 |
+
✅ Loaded <b>${repo}</b><br>
|
| 483 |
+
Estimated dense size:
|
| 484 |
+
${paramsB.toFixed(1)}B parameters
|
| 485 |
+
<br>
|
| 486 |
d=${d},
|
| 487 |
L=${L},
|
| 488 |
nq=${nq},
|
|
|
|
| 492 |
|
| 493 |
draw();
|
| 494 |
|
| 495 |
+
|
| 496 |
}
|
| 497 |
catch(e)
|
| 498 |
{
|
| 499 |
+
|
| 500 |
document.getElementById("status").innerHTML =
|
| 501 |
+
"⚠️ "+e.message;
|
| 502 |
+
|
| 503 |
}
|
| 504 |
|
| 505 |
}
|
index.html
CHANGED
|
@@ -82,9 +82,20 @@ Interactive visualization of the analytical energy model. Load any dense LLM fro
|
|
| 82 |
|
| 83 |
</div>
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
<h3>
|
| 87 |
-
|
| 88 |
</h3>
|
| 89 |
|
| 90 |
<input
|
|
|
|
| 82 |
|
| 83 |
</div>
|
| 84 |
|
| 85 |
+
<h3>
|
| 86 |
+
Validated models
|
| 87 |
+
</h3>
|
| 88 |
+
|
| 89 |
+
<select id="preset">
|
| 90 |
+
</select>
|
| 91 |
+
|
| 92 |
+
<button onclick="loadPreset()">
|
| 93 |
+
Load selected model
|
| 94 |
+
</button>
|
| 95 |
+
|
| 96 |
|
| 97 |
<h3>
|
| 98 |
+
Or load another public Hugging Face model
|
| 99 |
</h3>
|
| 100 |
|
| 101 |
<input
|