Update verolm-runner.js
Browse files- verolm-runner.js +19 -11
verolm-runner.js
CHANGED
|
@@ -16,18 +16,26 @@ export async function load({ baseUrl, tensors, tools, manifest, onProgress }) {
|
|
| 16 |
const names = [...tensors.keys()];
|
| 17 |
const nameSample = () => names.slice(0, 14).join(", ") + (names.length > 14 ? ", ... (" + names.length + " tensors in total)" : "");
|
| 18 |
|
| 19 |
-
//
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
-
if (
|
| 30 |
-
if (pre === null) pre = embKey.endsWith("emb.weight") ? embKey.slice(0, embKey.length - "emb.weight".length) : "";
|
| 31 |
|
| 32 |
const T = n => { const t = tensors.get(pre + n); if (!t) throw new Error("Missing tensor '" + pre + n + "'. Tensor names in file: " + nameSample()); return t; };
|
| 33 |
const W = n => tools.toFloat32(T(n));
|
|
|
|
| 16 |
const names = [...tensors.keys()];
|
| 17 |
const nameSample = () => names.slice(0, 14).join(", ") + (names.length > 14 ? ", ... (" + names.length + " tensors in total)" : "");
|
| 18 |
|
| 19 |
+
// Find the prefix ("", "model.", "_orig_mod.", ...) and the byte embedding.
|
| 20 |
+
// A candidate only counts if the same prefix also has the model's other tensors,
|
| 21 |
+
// so extra tensors such as "pos_emb.weight" can't be mistaken for the main embedding.
|
| 22 |
+
let pre = null, embKey = null;
|
| 23 |
+
for (const k of names) {
|
| 24 |
+
if (!k.endsWith("emb.weight")) continue;
|
| 25 |
+
const p = k.slice(0, k.length - "emb.weight".length);
|
| 26 |
+
if (tensors.has(p + "conv.w") || tensors.has(p + "blocks.0.n1.w")) { pre = p; embKey = k; break; }
|
| 27 |
+
}
|
| 28 |
+
if (embKey === null) {
|
| 29 |
+
for (const k of names) { const m = k.match(/^(.*)blocks\.0\.n1\.w$/); if (m) { pre = m[1]; break; } }
|
| 30 |
+
if (pre !== null) {
|
| 31 |
+
embKey = tensors.has(pre + "emb.weight") ? pre + "emb.weight" : null;
|
| 32 |
+
if (!embKey) { // otherwise: the only 2-D tensor with 256 rows (byte vocabulary)
|
| 33 |
+
const cand = names.filter(k => { const t = tensors.get(k); return t.shape.length === 2 && t.shape[0] === 256; });
|
| 34 |
+
embKey = cand.find(k => /emb|wte|tok|embed/i.test(k)) || (cand.length === 1 ? cand[0] : null);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
}
|
| 38 |
+
if (embKey === null) throw new Error("Couldn’t match this file to the NoTokenLM layout (expected emb.weight, conv.w, blocks.N.*). Tensor names in file: " + nameSample());
|
|
|
|
| 39 |
|
| 40 |
const T = n => { const t = tensors.get(pre + n); if (!t) throw new Error("Missing tensor '" + pre + n + "'. Tensor names in file: " + nameSample()); return t; };
|
| 41 |
const W = n => tools.toFloat32(T(n));
|