bitgpu 0.13.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -4
- package/dist/chat.d.ts +11 -3
- package/dist/chat.js +9 -3
- package/dist/chat.js.map +1 -1
- package/dist/gguf.d.ts +1 -1
- package/dist/gguf.js +175 -1
- package/dist/gguf.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +524 -78
- package/dist/index.js.map +1 -1
- package/dist/{types-ByYx15Yw.d.ts → types-Wg8VrdrL.d.ts} +57 -4
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -5,7 +5,10 @@ A fast, dependency-free WebGPU runtime for **low-bit LLMs** in the browser.
|
|
|
5
5
|
Today it runs **1-bit (binary-weight)** models.
|
|
6
6
|
Reference targets are Bonsai **1.7B, 4B and 8B** (Qwen3 architecture, sign-packed binary linear
|
|
7
7
|
weights + 2/4-bit embeddings, tied or untied lm_head) - every size is gated bit-exact against the
|
|
8
|
-
reference forward on real hardware
|
|
8
|
+
reference forward on real hardware - plus **Bonsai-27B** (Qwen3.5 *hybrid* backbone: a 3:1 mix of
|
|
9
|
+
gated-DeltaNet linear attention and gated full attention), validated to matching greedy tokens and
|
|
10
|
+
logits tolerance against transformers (its linear-attention recurrence keeps no fp64 path, so the
|
|
11
|
+
bar is greedy-exact rather than bit-exact). GPU-resident decode (greedy or sampled), streaming, EOS stop,
|
|
9
12
|
`AbortSignal`, cross-turn KV-cache reuse, optional f16/q8 KV-cache compression for long
|
|
10
13
|
contexts in less VRAM, conversation snapshots (save/restore across page reloads), and an
|
|
11
14
|
optional rolling window with attention sinks for unbounded chats in fixed memory. Runs the
|
|
@@ -25,6 +28,22 @@ npm install bitgpu
|
|
|
25
28
|
|
|
26
29
|
ESM-only, zero runtime dependencies.
|
|
27
30
|
|
|
31
|
+
## Benchmark
|
|
32
|
+
|
|
33
|
+
Against the mainstream WebGPU path for the same model - transformers.js with `dtype: 'q1'` - on the
|
|
34
|
+
**identical** 1-bit Bonsai-1.7B weights, same GPU, same prompt, both in one page:
|
|
35
|
+
|
|
36
|
+
| | transformers.js 4.2.0 (`dtype: 'q1'`) | bitgpu |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| decode | 17.7 tok/s | **23.8 tok/s** (up to ~1.8x at short context) |
|
|
39
|
+
| prefill (156-token prompt) | 5.6 s | **0.9 s** (~6x) |
|
|
40
|
+
|
|
41
|
+
Point-in-time, one machine (Apple M-series, Chrome 150 / WebGPU, 2026-07) - so treat it as a
|
|
42
|
+
ballpark, not a leaderboard. Reproduce it, or run your own model / GPU, with `npm run bench`
|
|
43
|
+
([examples/benchmark.html](examples/benchmark.html) loads both engines side by side and prints the
|
|
44
|
+
numbers). Weights are bit-identical across the two containers (the GGUF sign-bit stream equals the
|
|
45
|
+
onnx-community q1 export), so this measures the runtime, not the model.
|
|
46
|
+
|
|
28
47
|
## Quickstart - no conversion, no hosting
|
|
29
48
|
|
|
30
49
|
Ready-made manifests for all three Bonsai sizes are committed under [`models/`](models/); the
|
|
@@ -34,7 +53,7 @@ weights stream straight from the Hugging Face Hub. This runs as-is:
|
|
|
34
53
|
import { createEngine } from 'bitgpu'
|
|
35
54
|
import { createChat } from 'bitgpu/chat'
|
|
36
55
|
|
|
37
|
-
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.
|
|
56
|
+
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.15.0/models/bonsai-1.7b-gguf'
|
|
38
57
|
const TOK = 'https://huggingface.co/onnx-community/Bonsai-1.7B-ONNX/resolve/main'
|
|
39
58
|
const engine = await createEngine({
|
|
40
59
|
manifestUrl: `${REPO}/manifest.json`,
|
|
@@ -339,6 +358,15 @@ const engine = await createEngine({
|
|
|
339
358
|
})
|
|
340
359
|
```
|
|
341
360
|
|
|
361
|
+
The Qwen3.5 hybrid **Bonsai-27B** loads exactly the same way - `fromGguf` is its only path (there is
|
|
362
|
+
no offline converter for the hybrid yet), so point at
|
|
363
|
+
`prism-ml/Bonsai-27B-gguf/resolve/main/Bonsai-27B-Q1_0.gguf` with `kvCache: 'q8'` and, say,
|
|
364
|
+
`maxSeqLen: 4096`. bitgpu runs its **text trunk** (the model is multimodal; the vision path is out of
|
|
365
|
+
scope, and its chat template is not wired into `bitgpu/chat` yet - drive it at the `forward` /
|
|
366
|
+
`generate` token-id level, or supply your own template). It is a ~3.8 GB download and comfortably
|
|
367
|
+
wants a 16 GB (or larger) GPU budget - on an 8 GB laptop it runs but the weights spill to swap, so
|
|
368
|
+
decode is slow.
|
|
369
|
+
|
|
342
370
|
The in-browser parse is gated: it must deep-equal the offline converter's manifest AND an
|
|
343
371
|
engine built from it must reproduce the known-good greedy ids bit-exactly on GPU. Prefer the
|
|
344
372
|
committed [`models/`](models/) manifests when one exists (a `manifest.json` is smaller than a
|
|
@@ -370,12 +398,15 @@ createEngine({
|
|
|
370
398
|
Compatibility envelope: Qwen3-family models quantized with the 1-bit recipe (silu/SwiGLU,
|
|
371
399
|
head_dim <= 128, 128-wide scale blocks, tied or untied lm_head), in either container: GGUFs
|
|
372
400
|
with PrismML's Q1_0 tensor type (the primary path), or ONNX exports with the onnx-community
|
|
373
|
-
"q1" recipe - the engine validates the manifest loudly at load. The
|
|
401
|
+
"q1" recipe - the engine validates the manifest loudly at load. The Qwen3.5 **hybrid** backbone
|
|
402
|
+
(Bonsai-27B: a 3:1 mix of gated-DeltaNet linear attention and gated full attention, head_dim 256,
|
|
403
|
+
partial RoPE) is also supported, GGUF-only, under the same 1-bit recipe. The two containers carry
|
|
374
404
|
bit-identical weights for the Bonsai releases (verified sign-bit-for-sign-bit on 8B), so pick
|
|
375
405
|
by hosting preference.
|
|
376
406
|
Reference exports: [prism-ml/Bonsai-1.7B-gguf](https://huggingface.co/prism-ml/Bonsai-1.7B-gguf) /
|
|
377
407
|
[4B](https://huggingface.co/prism-ml/Bonsai-4B-gguf) /
|
|
378
|
-
[8B](https://huggingface.co/prism-ml/Bonsai-8B-gguf)
|
|
408
|
+
[8B](https://huggingface.co/prism-ml/Bonsai-8B-gguf) /
|
|
409
|
+
[27B](https://huggingface.co/prism-ml/Bonsai-27B-gguf) (`Bonsai-*-Q1_0.gguf`; the 27B is the Qwen3.5 hybrid, GGUF-only), and
|
|
379
410
|
[onnx-community/Bonsai-1.7B-ONNX](https://huggingface.co/onnx-community/Bonsai-1.7B-ONNX) /
|
|
380
411
|
[4B](https://huggingface.co/onnx-community/Bonsai-4B-ONNX) /
|
|
381
412
|
[8B](https://huggingface.co/onnx-community/Bonsai-8B-ONNX) (`onnx/model_q1.onnx` + data file). Format spec:
|
package/dist/chat.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as KvSnapshot, m as TokenLogprobs, n as Engine, o as GenerateOptions } from "./types-
|
|
1
|
+
import { c as KvSnapshot, m as TokenLogprobs, n as Engine, o as GenerateOptions } from "./types-Wg8VrdrL.js";
|
|
2
2
|
|
|
3
3
|
//#region src/chat/tokenizer.d.ts
|
|
4
4
|
interface ChatMessage {
|
|
@@ -454,8 +454,16 @@ interface Chat {
|
|
|
454
454
|
* to another worker; restoring it into a chat on the same model and `kvCache` mode makes the
|
|
455
455
|
* next clean-append turn extend the cache exactly as if the conversation never stopped (no
|
|
456
456
|
* re-prefill). Returns null when no conversation is committed. Queues behind in-flight turns
|
|
457
|
-
* like send/stream.
|
|
458
|
-
|
|
457
|
+
* like send/stream.
|
|
458
|
+
*
|
|
459
|
+
* `{ delta: true }` makes a DELTA snapshot that excludes the shared prewarmed prefix (the system
|
|
460
|
+
* messages + tools warmed with {@link Chat.prewarm}), so a per-conversation snapshot drops the
|
|
461
|
+
* redundant system-prompt KV - tens of MB at chat scale, and a smaller structured-clone. Restore
|
|
462
|
+
* it into a chat freshly `prewarm()`ed with the SAME system + tools (restore validates and throws
|
|
463
|
+
* on a mismatch). Requires a prior prewarm(); throws otherwise. */
|
|
464
|
+
save(opts?: {
|
|
465
|
+
delta?: boolean;
|
|
466
|
+
}): Promise<ChatSnapshot | null>;
|
|
459
467
|
/** Replace the current conversation with a saved snapshot (see {@link Chat.save}). Throws when
|
|
460
468
|
* the snapshot does not match this engine's model or `kvCache` mode. */
|
|
461
469
|
restore(snapshot: ChatSnapshot): Promise<void>;
|
package/dist/chat.js
CHANGED
|
@@ -5425,10 +5425,12 @@ async function createChat(engine, options) {
|
|
|
5425
5425
|
let committed = null;
|
|
5426
5426
|
let cacheEndsAtEos = false;
|
|
5427
5427
|
let committedToolsKey = null;
|
|
5428
|
+
let prewarmLen = 0;
|
|
5428
5429
|
let resetEpoch = 0;
|
|
5429
5430
|
const dropCache = () => {
|
|
5430
5431
|
committed = null;
|
|
5431
5432
|
committedToolsKey = null;
|
|
5433
|
+
prewarmLen = 0;
|
|
5432
5434
|
engine.resetCache();
|
|
5433
5435
|
};
|
|
5434
5436
|
let templateToolsOk = null;
|
|
@@ -5636,11 +5638,13 @@ async function createChat(engine, options) {
|
|
|
5636
5638
|
enableThinking: false,
|
|
5637
5639
|
tools: prep?.tools
|
|
5638
5640
|
}).replace(/\n$/, "");
|
|
5641
|
+
const toks = tk.encode(str, false);
|
|
5639
5642
|
const epoch0 = resetEpoch;
|
|
5640
|
-
await engine.prefill(
|
|
5643
|
+
await engine.prefill(toks);
|
|
5641
5644
|
if (resetEpoch !== epoch0) return;
|
|
5642
5645
|
committed = [...messages];
|
|
5643
5646
|
committedToolsKey = prep ? JSON.stringify(prep.tools) : null;
|
|
5647
|
+
prewarmLen = toks.length;
|
|
5644
5648
|
cacheEndsAtEos = true;
|
|
5645
5649
|
}
|
|
5646
5650
|
return {
|
|
@@ -5695,9 +5699,10 @@ async function createChat(engine, options) {
|
|
|
5695
5699
|
resetEpoch++;
|
|
5696
5700
|
dropCache();
|
|
5697
5701
|
},
|
|
5698
|
-
save: serialize(async () => {
|
|
5702
|
+
save: serialize(async (opts) => {
|
|
5699
5703
|
if (committed === null) return null;
|
|
5700
|
-
|
|
5704
|
+
if (opts?.delta && prewarmLen <= 0) throw new Error("bitgpu/chat: save({ delta: true }) needs a prewarm() first (no shared prefix to exclude)");
|
|
5705
|
+
const eng = await engine.saveCache(opts?.delta ? { from: prewarmLen - 1 } : void 0);
|
|
5701
5706
|
if (!eng) return null;
|
|
5702
5707
|
return {
|
|
5703
5708
|
version: 1,
|
|
@@ -5715,6 +5720,7 @@ async function createChat(engine, options) {
|
|
|
5715
5720
|
committed = JSON.parse(JSON.stringify(snap.committed));
|
|
5716
5721
|
committedToolsKey = snap.toolsKey ?? null;
|
|
5717
5722
|
cacheEndsAtEos = !!snap.cacheEndsAtEos;
|
|
5723
|
+
if (!snap.engine.base) prewarmLen = 0;
|
|
5718
5724
|
}),
|
|
5719
5725
|
eosTokenId: tk.eosTokenId,
|
|
5720
5726
|
tokenizer: tk
|