Download mobile/test/webllm-test.cjs from Devseis/Arx: direct link, hf CLI and curl.
- Browser
- Download file 2.72 kB
-
https://huggingface.co/spaces/Devseis/Arx/resolve/main/mobile/test/webllm-test.cjs
- Command line
-
hf download hf://spaces/Devseis/Arx/mobile/test/webllm-test.cjs
-
curl -L -o webllm-test.cjs https://huggingface.co/spaces/Devseis/Arx/resolve/main/mobile/test/webllm-test.cjs
2.72 kB
| // Run a Devseis model build in WebLLM (real GPU) on held-out test prompts and report grounding. | |
| // Usage: (serve the repo root on :8765) electron mobile/test/webllm-test.cjs <model-url-with-{quant}> <test.jsonl> <count> | |
| const { app, BrowserWindow } = require('electron'); | |
| const fs = require('node:fs'); | |
| const [modelUrl, testFile, count, useSchema] = process.argv.slice(-4); | |
| app.commandLine.appendSwitch('enable-unsafe-webgpu'); | |
| app.whenReady().then(async () => { | |
| const win = new BrowserWindow({ show: false }); | |
| win.webContents.on('console-message', e => { if (e.level === 'error') console.log('[page]', e.message); }); | |
| const js = code => win.webContents.executeJavaScript(code); | |
| try { | |
| await win.loadURL('http://127.0.0.1:8765/mobile/test/webllm-test.html' + '?' + (process.env.CTX ? `ctx=${process.env.CTX}&` : '') + (process.env.RESET ? 'reset=1' : '')); | |
| while (!(await js('window.ready === true'))) await new Promise(r => setTimeout(r, 200)); | |
| const info = await js(`loadModel(${JSON.stringify(modelUrl)})`); | |
| console.log('loaded', JSON.stringify(info)); | |
| const examples = fs.readFileSync(testFile, 'utf8').trim().split('\n').map(JSON.parse); | |
| const chats = examples.filter(e => e.meta.task === 'chat'); | |
| const nChat = chats.length ? Math.floor(count / 2) : 0; | |
| const pick = [...examples.filter(e => e.meta.task === 'finding').slice(0, count - 2 - nChat), ...examples.filter(e => e.meta.task === 'summary').slice(0, 1), ...examples.filter(e => e.meta.task === 'ai_classification').slice(0, 1), ...chats.slice(0, nChat)]; | |
| let ok = 0; | |
| for (const e of pick) { | |
| const arg = e.meta.task === 'chat' ? JSON.stringify(e.messages.slice(0, -1)) : JSON.stringify(e.messages[1].content); | |
| // One failing case (engine error, timeout) is recorded and the rest still run. | |
| const r = await Promise.race([js(`ask(${JSON.stringify(e.meta.task)}, ${arg}, ${useSchema === 'schema'})`), | |
| new Promise(res => setTimeout(() => res({ seconds: 240, problems: ['timeout after 240 s'], reply: '' }), 240000))]) | |
| .catch(error => ({ seconds: 0, problems: ['engine error: ' + error.message], reply: '' })); | |
| if (!r.problems.length) ok++; | |
| if (process.env.FULL) console.log('FULL REPLY:', r.reply.length, 'chars\n' + r.reply.slice(-700)); | |
| console.log(`${e.meta.task.padEnd(18)} ${String(r.seconds).padStart(3)}s ${r.problems.length ? 'NOT grounded: ' + r.problems.slice(0, 2).join('; ') : 'grounded'} | ${r.reply.replace(/\s+/g, ' ').slice(0, 110)}`); | |
| } | |
| console.log(`RESULT ${ok}/${pick.length} grounded`); | |
| if (ok < pick.length) process.exitCode = 1; | |
| } catch (error) { console.log('FAILED', error.message); process.exitCode = 1; } | |
| app.quit(); | |
| }); | |