Update index.html
Browse files- index.html +17 -23
index.html
CHANGED
|
@@ -42,11 +42,10 @@
|
|
| 42 |
AutoTokenizer,
|
| 43 |
AutoModelForCausalLM
|
| 44 |
} from "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.0/dist/transformers.min.js";
|
| 45 |
-
// make available to the rest of the page
|
| 46 |
-
window.HF = { env, AutoTokenizer, AutoModelForCausalLM };
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
env.allowRemoteModels = true;
|
| 51 |
env.useBrowserCache = true;
|
| 52 |
env.backends.onnx.wasm.wasmPaths =
|
|
@@ -129,10 +128,10 @@
|
|
| 129 |
/* ---------- Backend (no cross-origin isolation) ---------- */
|
| 130 |
env.backends.onnx.webgpu = { enabled: false };
|
| 131 |
env.backends.onnx.preferredBackend = "wasm";
|
| 132 |
-
env.backends.onnx.wasm.numThreads = 1;
|
| 133 |
-
env.backends.onnx.wasm.proxy = false;
|
| 134 |
if (typeof env.backends.onnx.wasm.jsep !== "undefined") {
|
| 135 |
-
env.backends.onnx.wasm.jsep = false;
|
| 136 |
}
|
| 137 |
|
| 138 |
/* ---------- DOM helpers ---------- */
|
|
@@ -149,7 +148,7 @@
|
|
| 149 |
const PUNC_ONLY = /^[\s.,;:!?—-]+$/;
|
| 150 |
|
| 151 |
/* ---------- Progress UI ---------- */
|
| 152 |
-
const files = new Map();
|
| 153 |
let phase = ""; let lastTickBytes = 0, lastTickTime = 0;
|
| 154 |
const STALL_SECS = 20;
|
| 155 |
const humanMB = (b)=> (b/1024/1024).toFixed(1)+" MB";
|
|
@@ -212,8 +211,10 @@
|
|
| 212 |
/* ---------- Model registry ---------- */
|
| 213 |
const MODELS = {
|
| 214 |
qwen: {
|
| 215 |
-
|
| 216 |
-
local_url: new URL("assets/models/qwen/", window.location.href),
|
|
|
|
|
|
|
| 217 |
onnx_file: "onnx/model_q4f16.onnx",
|
| 218 |
emb_coords: "assets/embeddings/qwen_pca_top5k_coords.json",
|
| 219 |
emb_nbrs: "assets/embeddings/qwen_neighbors_top5k_k40.json"
|
|
@@ -225,7 +226,7 @@
|
|
| 225 |
}
|
| 226 |
};
|
| 227 |
|
| 228 |
-
/* ---------- Qwen3 config shim
|
| 229 |
const QWEN3_CONFIG_FIX = {
|
| 230 |
model_type: "qwen2",
|
| 231 |
architectures: ["Qwen2ForCausalLM"]
|
|
@@ -304,18 +305,10 @@
|
|
| 304 |
setStatus("Tokenizer: starting…");
|
| 305 |
try {
|
| 306 |
if (key === "qwen") {
|
| 307 |
-
// Use
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
});
|
| 312 |
-
} catch (e) {
|
| 313 |
-
console.warn("Local Qwen tokenizer failed; falling back to Hub:", e);
|
| 314 |
-
// Hub fallback (now safe: no '/models/' rewrite because localModelPath=null)
|
| 315 |
-
tokenizer = await AutoTokenizer.from_pretrained(MODELS.qwen.hub_tokenizer_repo, {
|
| 316 |
-
progress_callback: onProgress,
|
| 317 |
-
});
|
| 318 |
-
}
|
| 319 |
} else {
|
| 320 |
tokenizer = await AutoTokenizer.from_pretrained(MODELS.distilgpt2.remote_repo, {
|
| 321 |
progress_callback: onProgress,
|
|
@@ -421,6 +414,7 @@
|
|
| 421 |
let m = -Infinity; for (let i = 0; i < data.length; i++) if (data[i] > m) m = data[i];
|
| 422 |
const exps = new Float32Array(data.length); let Z = 0;
|
| 423 |
for (let i = 0; i < data.length; i++) { const e = Math.exp(data[i] - m); exps[i] = e; Z += e; }
|
|
|
|
| 424 |
const K = Math.min(parseInt(topkSel.value, 10) || topK, data.length);
|
| 425 |
const idx = Array.from({ length: data.length }, (_, i) => [exps[i] / Z, i])
|
| 426 |
.sort((a, b) => b[0] - a[0]).slice(0, K);
|
|
|
|
| 42 |
AutoTokenizer,
|
| 43 |
AutoModelForCausalLM
|
| 44 |
} from "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.0/dist/transformers.min.js";
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
window.HF = { env, AutoTokenizer, AutoModelForCausalLM };
|
| 47 |
+
// prevent repo IDs being rewritten to /models/, and allow Hub fetches if ever needed
|
| 48 |
+
env.localModelPath = null;
|
| 49 |
env.allowRemoteModels = true;
|
| 50 |
env.useBrowserCache = true;
|
| 51 |
env.backends.onnx.wasm.wasmPaths =
|
|
|
|
| 128 |
/* ---------- Backend (no cross-origin isolation) ---------- */
|
| 129 |
env.backends.onnx.webgpu = { enabled: false };
|
| 130 |
env.backends.onnx.preferredBackend = "wasm";
|
| 131 |
+
env.backends.onnx.wasm.numThreads = 1;
|
| 132 |
+
env.backends.onnx.wasm.proxy = false;
|
| 133 |
if (typeof env.backends.onnx.wasm.jsep !== "undefined") {
|
| 134 |
+
env.backends.onnx.wasm.jsep = false;
|
| 135 |
}
|
| 136 |
|
| 137 |
/* ---------- DOM helpers ---------- */
|
|
|
|
| 148 |
const PUNC_ONLY = /^[\s.,;:!?—-]+$/;
|
| 149 |
|
| 150 |
/* ---------- Progress UI ---------- */
|
| 151 |
+
const files = new Map();
|
| 152 |
let phase = ""; let lastTickBytes = 0, lastTickTime = 0;
|
| 153 |
const STALL_SECS = 20;
|
| 154 |
const humanMB = (b)=> (b/1024/1024).toFixed(1)+" MB";
|
|
|
|
| 211 |
/* ---------- Model registry ---------- */
|
| 212 |
const MODELS = {
|
| 213 |
qwen: {
|
| 214 |
+
// Local base as a URL object (forces local resolution in transformers.js)
|
| 215 |
+
local_url: new URL("assets/models/qwen/", window.location.href),
|
| 216 |
+
// (optional string for reference, not used to load)
|
| 217 |
+
local_dir: "assets/models/qwen/",
|
| 218 |
onnx_file: "onnx/model_q4f16.onnx",
|
| 219 |
emb_coords: "assets/embeddings/qwen_pca_top5k_coords.json",
|
| 220 |
emb_nbrs: "assets/embeddings/qwen_neighbors_top5k_k40.json"
|
|
|
|
| 226 |
}
|
| 227 |
};
|
| 228 |
|
| 229 |
+
/* ---------- Qwen3 config shim ---------- */
|
| 230 |
const QWEN3_CONFIG_FIX = {
|
| 231 |
model_type: "qwen2",
|
| 232 |
architectures: ["Qwen2ForCausalLM"]
|
|
|
|
| 305 |
setStatus("Tokenizer: starting…");
|
| 306 |
try {
|
| 307 |
if (key === "qwen") {
|
| 308 |
+
// Use the URL object to force local loading (prevents hub.js path)
|
| 309 |
+
tokenizer = await AutoTokenizer.from_pretrained(MODELS.qwen.local_url, {
|
| 310 |
+
progress_callback: onProgress,
|
| 311 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
} else {
|
| 313 |
tokenizer = await AutoTokenizer.from_pretrained(MODELS.distilgpt2.remote_repo, {
|
| 314 |
progress_callback: onProgress,
|
|
|
|
| 414 |
let m = -Infinity; for (let i = 0; i < data.length; i++) if (data[i] > m) m = data[i];
|
| 415 |
const exps = new Float32Array(data.length); let Z = 0;
|
| 416 |
for (let i = 0; i < data.length; i++) { const e = Math.exp(data[i] - m); exps[i] = e; Z += e; }
|
| 417 |
+
|
| 418 |
const K = Math.min(parseInt(topkSel.value, 10) || topK, data.length);
|
| 419 |
const idx = Array.from({ length: data.length }, (_, i) => [exps[i] / Z, i])
|
| 420 |
.sort((a, b) => b[0] - a[0]).slice(0, K);
|