Chat: use the 16-bit v0.5 build (4-bit rounding breaks v0.5); knowledge base on chips without 16-bit
Browse files- app/model-version.json +2 -1
- chat/chat.js +20 -7
app/model-version.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
"chat": {
|
| 5 |
"version": "v0.5",
|
| 6 |
"size": "0.5B",
|
| 7 |
-
"note": "Chat model: Devseis/endpoint-auditor-<size>-
|
|
|
|
| 8 |
}
|
| 9 |
}
|
|
|
|
| 4 |
"chat": {
|
| 5 |
"version": "v0.5",
|
| 6 |
"size": "0.5B",
|
| 7 |
+
"note": "Chat model: Devseis/endpoint-auditor-<size>-<quant>-MLC tag. quant q0f16 = unrounded build (v0.5 breaks in 4-bit); omit to pick q4f16_1/q4f32_1 by GPU. null version = base Qwen2.5 Instruct.",
|
| 8 |
+
"quant": "q0f16"
|
| 9 |
}
|
| 10 |
}
|
chat/chat.js
CHANGED
|
@@ -34,15 +34,28 @@ const loadWebllm = () => (webllmPromise ||= import(WEBLLM_URL));
|
|
| 34 |
|
| 35 |
// Chat model size from app/model-version.json (chat.size): 0.5B for phones and weak graphics chips, 1.5B before v0.5.
|
| 36 |
const CHAT_MODELS = { '0.5B': { repo: '0.5b', download: 'about 300 MB', mb: 280 }, '1.5B': { repo: '1.5b', download: 'about 850 MB', mb: 840 } };
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
async function modelChoice() {
|
| 40 |
if (!('gpu' in navigator)) throw new Error('This browser has no WebGPU');
|
| 41 |
const adapter = await navigator.gpu.requestAdapter();
|
| 42 |
if (!adapter) throw new Error('No WebGPU graphics adapter');
|
| 43 |
-
const
|
|
|
|
|
|
|
| 44 |
const webllm = await loadWebllm();
|
| 45 |
-
const { size, repo } = chatModel();
|
| 46 |
const base = webllm.prebuiltAppConfig.model_list.find(m => m.model_id === `Qwen2.5-${size}-Instruct-${quant}-MLC`);
|
| 47 |
const v = state.config?.chat?.version;
|
| 48 |
const custom = v ? { ...base, model: `https://huggingface.co/Devseis/endpoint-auditor-${repo}-${quant}-MLC/resolve/${v}/`, model_id: `devseis-assistant-${repo}-${v}-${quant}` } : null;
|
|
@@ -286,7 +299,7 @@ function turnOffBrokenAi() {
|
|
| 286 |
const engine = state.engine;
|
| 287 |
state.engine = null; state.enginePromise = null; state.loading = false; state.kbOnly = true; state.aiFault = true;
|
| 288 |
state.modelLabel = 'Turned off: it wrote unreadable text on this device'; $('modelName').textContent = 'Knowledge base only';
|
| 289 |
-
try { localStorage.setItem(AI_FAULT,
|
| 290 |
if (engine && engine.unload) engine.unload().catch(() => {});
|
| 291 |
aiChip();
|
| 292 |
}
|
|
@@ -548,8 +561,8 @@ async function init() {
|
|
| 548 |
if ('gpu' in navigator) {
|
| 549 |
let consent = null; try { consent = localStorage.getItem(AI_CONSENT); } catch { /* ignore */ }
|
| 550 |
let fault = null; try { fault = localStorage.getItem(AI_FAULT); } catch { /* ignore */ }
|
| 551 |
-
if (fault && fault === (
|
| 552 |
-
else modelCached().then(cached => {
|
| 553 |
if (cached || consent === 'yes') { state.cachedStart = cached; getEngine(); }
|
| 554 |
else if (consent === 'later') { state.kbOnly = true; aiChip(); }
|
| 555 |
else {
|
|
@@ -557,7 +570,7 @@ async function init() {
|
|
| 557 |
if (navigator.connection && navigator.connection.type === 'cellular') $('aiCardText').textContent += ' You seem to be on mobile data: Wi-Fi is recommended.';
|
| 558 |
render(); aiChip();
|
| 559 |
}
|
| 560 |
-
});
|
| 561 |
} else { state.engine = false; state.modelLabel = 'Not available: this browser has no WebGPU'; $('modelName').textContent = 'Knowledge base only'; aiChip(); }
|
| 562 |
if (new URLSearchParams(location.search).has('test')) Object.assign(window, { __chat: state, __ask: ask, __enable: enableAi, __rewrite: rewriteWithAi });
|
| 563 |
}
|
|
|
|
| 34 |
|
| 35 |
// Chat model size from app/model-version.json (chat.size): 0.5B for phones and weak graphics chips, 1.5B before v0.5.
|
| 36 |
const CHAT_MODELS = { '0.5B': { repo: '0.5b', download: 'about 300 MB', mb: 280 }, '1.5B': { repo: '1.5b', download: 'about 850 MB', mb: 840 } };
|
| 37 |
+
// chat.quant "q0f16" = the unrounded build (v0.5 loses its training when rounded to 4 bits): about 3x the download,
|
| 38 |
+
// and only on graphics chips with 16-bit support. Without it, the 4-bit build that suits this chip.
|
| 39 |
+
function chatModel() {
|
| 40 |
+
const size = CHAT_MODELS[state.config?.chat?.size] ? state.config.chat.size : '1.5B', quant = state.config?.chat?.quant || null;
|
| 41 |
+
const m = { size, quant, ...CHAT_MODELS[size] };
|
| 42 |
+
return quant === 'q0f16' ? { ...m, download: `about ${Math.round(m.mb * 3.4 / 50) * 50} MB`, mb: Math.round(m.mb * 3.4) } : m;
|
| 43 |
+
}
|
| 44 |
+
// A broken-AI flag is kept per model build, so a new build gets a fresh try.
|
| 45 |
+
function faultKey() { const c = state.config?.chat || {}; return [c.version || 'base', c.quant].filter(Boolean).join('-'); }
|
| 46 |
+
async function needs16Bit() {
|
| 47 |
+
if (chatModel().quant !== 'q0f16') return false;
|
| 48 |
+
try { const a = await navigator.gpu.requestAdapter(); return !a || !a.features.has('shader-f16'); } catch { return true; }
|
| 49 |
+
}
|
| 50 |
|
| 51 |
async function modelChoice() {
|
| 52 |
if (!('gpu' in navigator)) throw new Error('This browser has no WebGPU');
|
| 53 |
const adapter = await navigator.gpu.requestAdapter();
|
| 54 |
if (!adapter) throw new Error('No WebGPU graphics adapter');
|
| 55 |
+
const { size, repo, quant: fixed } = chatModel();
|
| 56 |
+
if (fixed === 'q0f16' && !adapter.features.has('shader-f16')) throw new Error('This graphics chip has no 16-bit support');
|
| 57 |
+
const quant = fixed || (adapter.features.has('shader-f16') ? 'q4f16_1' : 'q4f32_1');
|
| 58 |
const webllm = await loadWebllm();
|
|
|
|
| 59 |
const base = webllm.prebuiltAppConfig.model_list.find(m => m.model_id === `Qwen2.5-${size}-Instruct-${quant}-MLC`);
|
| 60 |
const v = state.config?.chat?.version;
|
| 61 |
const custom = v ? { ...base, model: `https://huggingface.co/Devseis/endpoint-auditor-${repo}-${quant}-MLC/resolve/${v}/`, model_id: `devseis-assistant-${repo}-${v}-${quant}` } : null;
|
|
|
|
| 299 |
const engine = state.engine;
|
| 300 |
state.engine = null; state.enginePromise = null; state.loading = false; state.kbOnly = true; state.aiFault = true;
|
| 301 |
state.modelLabel = 'Turned off: it wrote unreadable text on this device'; $('modelName').textContent = 'Knowledge base only';
|
| 302 |
+
try { localStorage.setItem(AI_FAULT, faultKey()); } catch { /* ignore */ }
|
| 303 |
if (engine && engine.unload) engine.unload().catch(() => {});
|
| 304 |
aiChip();
|
| 305 |
}
|
|
|
|
| 561 |
if ('gpu' in navigator) {
|
| 562 |
let consent = null; try { consent = localStorage.getItem(AI_CONSENT); } catch { /* ignore */ }
|
| 563 |
let fault = null; try { fault = localStorage.getItem(AI_FAULT); } catch { /* ignore */ }
|
| 564 |
+
if (fault && fault === faultKey()) { state.kbOnly = true; state.aiFault = true; state.modelLabel = 'Turned off: it wrote unreadable text on this device'; $('modelName').textContent = 'Knowledge base only'; aiChip(); }
|
| 565 |
+
else needs16Bit().then(no => no ? (() => { state.engine = false; state.modelLabel = 'Not available: this graphics chip has no 16-bit support'; $('modelName').textContent = 'Knowledge base only'; aiChip(); render(); updateSend(); })() : modelCached().then(cached => {
|
| 566 |
if (cached || consent === 'yes') { state.cachedStart = cached; getEngine(); }
|
| 567 |
else if (consent === 'later') { state.kbOnly = true; aiChip(); }
|
| 568 |
else {
|
|
|
|
| 570 |
if (navigator.connection && navigator.connection.type === 'cellular') $('aiCardText').textContent += ' You seem to be on mobile data: Wi-Fi is recommended.';
|
| 571 |
render(); aiChip();
|
| 572 |
}
|
| 573 |
+
}));
|
| 574 |
} else { state.engine = false; state.modelLabel = 'Not available: this browser has no WebGPU'; $('modelName').textContent = 'Knowledge base only'; aiChip(); }
|
| 575 |
if (new URLSearchParams(location.search).has('test')) Object.assign(window, { __chat: state, __ask: ask, __enable: enableAi, __rewrite: rewriteWithAi });
|
| 576 |
}
|