Spaces:
Running
Running
cfahlgren1 HF Staff
switch to int8 weights that stay int8 in memory, add a pixel loader with load stages, and stop the reload loop after an out-of-memory crash
8e8aecc Download src/lib/worker.js from cfahlgren1/slack-moji: direct link, hf CLI and curl.
- Browser
- Download file 986 Bytes
-
https://huggingface.co/spaces/cfahlgren1/slack-moji/resolve/main/src/lib/worker.js
- Command line
-
hf download hf://spaces/cfahlgren1/slack-moji/src/lib/worker.js
-
curl -L -o worker.js https://huggingface.co/spaces/cfahlgren1/slack-moji/resolve/main/src/lib/worker.js
986 Bytes
| // Runs the model off the main thread so the page never freezes, on GPU or CPU. | |
| import { createEngine } from "./engine.js"; | |
| let engine = null; | |
| self.onmessage = async (e) => { | |
| const m = e.data; | |
| try { | |
| if (m.type === "init") { | |
| engine = await createEngine(m.bytes, m.tokJson, m.palette, m.selfTest, { | |
| forceCpu: m.forceCpu, | |
| onStage: (stage) => self.postMessage({ type: "stage", stage }), | |
| }); | |
| self.postMessage({ type: "ready", device: engine.device, fallbackReason: engine.fallbackReason }); | |
| return; | |
| } | |
| if (m.type === "generate") { | |
| const x = await engine.generate(m.prompt, { | |
| n: m.n, | |
| seed: m.seed, | |
| onStep: (_k, x, masked) => self.postMessage({ type: "step", id: m.id, x: x.slice(), masked: masked.slice() }), | |
| }); | |
| self.postMessage({ type: "done", id: m.id, x: x.slice() }); | |
| } | |
| } catch (err) { | |
| self.postMessage({ type: "error", id: m.id, message: String(err?.message ?? err) }); | |
| } | |
| }; | |