Instructions to use dizyann/crivo-web with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use dizyann/crivo-web with Transformers.js:
// ⚠️ Unknown pipeline tag
Download scripts/benchmark/playground.js from dizyann/crivo-web: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/dizyann/crivo-web/resolve/main/scripts/benchmark/playground.js
- Command line
-
hf download hf://dizyann/crivo-web/scripts/benchmark/playground.js
-
curl -L -o playground.js https://huggingface.co/dizyann/crivo-web/resolve/main/scripts/benchmark/playground.js
2.83 kB
| // Run in a fresh `bun run browser` page's DevTools console. Uses the actual UI and worker. | |
| window.crivoBenchmark = { | |
| runs: [], | |
| status: 'starting', | |
| userAgent: navigator.userAgent, | |
| threads: navigator.hardwareConcurrency, | |
| crossOriginIsolated: window.crossOriginIsolated | |
| } | |
| ;(async () => { | |
| const report = window.crivoBenchmark | |
| const adapter = await navigator.gpu?.requestAdapter() | |
| report.gpu = adapter | |
| ? { | |
| ...Object.fromEntries( | |
| ['vendor', 'architecture', 'device', 'description'].map((k) => [k, adapter.info[k]]) | |
| ) | |
| } | |
| : null | |
| const NativeWorker = window.Worker | |
| let pending | |
| let metrics | |
| window.Worker = class extends NativeWorker { | |
| constructor(...args) { | |
| super(...args) | |
| this.addEventListener('message', ({ data }) => { | |
| if (data.kind === 'metrics') metrics = data.metrics | |
| if (data.kind === 'error') pending?.reject(Error(data.message)) | |
| if (data.kind === 'result') { | |
| if (!data.result.ok) pending?.reject(Error(JSON.stringify(data.result.error))) | |
| else pending?.resolve({ ...metrics, totalMs: data.totalMs }) | |
| } | |
| }) | |
| this.addEventListener('error', () => pending?.reject(Error('Worker stopped'))) | |
| } | |
| postMessage(data, ...args) { | |
| report.input = data.input | |
| super.postMessage(data, ...args) | |
| } | |
| } | |
| const run = () => | |
| new Promise((resolve, reject) => { | |
| const timeout = setTimeout(() => reject(Error('Run timed out')), 240000) | |
| pending = { | |
| resolve: (data) => { | |
| clearTimeout(timeout) | |
| resolve(data) | |
| }, | |
| reject: (error) => { | |
| clearTimeout(timeout) | |
| reject(error) | |
| } | |
| } | |
| document.getElementById('run').click() | |
| }) | |
| for (const size of ['17m', '32m', '68m', '150m', '400m', '1b']) { | |
| for (const [device, dtype] of [ | |
| ['cpu', 'q8'], | |
| ...(size === '1b' ? [] : [['cpu', 'fp32']]), | |
| ['gpu', 'fp32'] | |
| ]) { | |
| const entry = { size, device, dtype, samples: [] } | |
| report.runs.push(entry) | |
| report.status = `${size} ${device} ${dtype}` | |
| for (const [id, value] of [ | |
| ['size', size], | |
| ['device', device], | |
| ['dtype', dtype] | |
| ]) { | |
| const select = document.getElementById(id) | |
| select.value = value | |
| select.dispatchEvent(new Event('change')) | |
| } | |
| await new Promise((resolve) => setTimeout(resolve, 50)) | |
| entry.first = await run() | |
| for (let i = 0; i < 23; i++) { | |
| await new Promise((resolve) => setTimeout(resolve, 50)) | |
| const result = await run() | |
| if (result.loadMs !== 0) throw Error('Session was not reused') | |
| if (i >= 3) entry.samples.push(result) | |
| } | |
| } | |
| } | |
| report.status = 'complete' | |
| })().catch((error) => { | |
| window.crivoBenchmark.error = String(error) | |
| }) | |