bitgpu 0.10.0 → 0.12.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 +90 -34
- package/dist/chat.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +293 -55
- package/dist/index.js.map +1 -1
- package/dist/{types-CcgsXirU.d.ts → types-Bl0FS_nX.d.ts} +31 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ Reference targets are Bonsai **1.7B, 4B and 8B** (Qwen3 architecture, sign-packe
|
|
|
7
7
|
weights + 2/4-bit embeddings, tied or untied lm_head) - every size is gated bit-exact against the
|
|
8
8
|
reference forward on real hardware. GPU-resident decode (greedy or sampled), streaming, EOS stop,
|
|
9
9
|
`AbortSignal`, cross-turn KV-cache reuse, optional f16/q8 KV-cache compression for long
|
|
10
|
-
contexts in less VRAM,
|
|
10
|
+
contexts in less VRAM, conversation snapshots (save/restore across page reloads), and an
|
|
11
|
+
optional rolling window with attention sinks for unbounded chats in fixed memory. Runs the
|
|
11
12
|
fast subgroup path on Apple / NVIDIA /
|
|
12
13
|
recent AMD and falls back to a workgroup-reduction path everywhere else WebGPU is available.
|
|
13
14
|
Device limits are negotiated from the manifest, so the 8B's ~148 MiB lm_head binding is requested
|
|
@@ -33,23 +34,24 @@ weights stream straight from the Hugging Face Hub. This runs as-is:
|
|
|
33
34
|
import { createEngine } from 'bitgpu'
|
|
34
35
|
import { createChat } from 'bitgpu/chat'
|
|
35
36
|
|
|
36
|
-
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.
|
|
37
|
-
const
|
|
37
|
+
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.12.0/models/bonsai-1.7b-gguf'
|
|
38
|
+
const TOK = 'https://huggingface.co/onnx-community/Bonsai-1.7B-ONNX/resolve/main'
|
|
38
39
|
const engine = await createEngine({
|
|
39
40
|
manifestUrl: `${REPO}/manifest.json`,
|
|
40
|
-
auxUrl: `${REPO}/
|
|
41
|
-
dataUrl:
|
|
41
|
+
auxUrl: `${REPO}/Bonsai-1.7B-Q1_0.aux.bin`,
|
|
42
|
+
dataUrl: 'https://huggingface.co/prism-ml/Bonsai-1.7B-gguf/resolve/main/Bonsai-1.7B-Q1_0.gguf',
|
|
42
43
|
})
|
|
43
44
|
const chat = await createChat(engine, {
|
|
44
|
-
tokenizerJsonUrl: `${
|
|
45
|
-
tokenizerConfigUrl: `${
|
|
45
|
+
tokenizerJsonUrl: `${TOK}/tokenizer.json`, // tokenizer from the ONNX repo (same base model)
|
|
46
|
+
tokenizerConfigUrl: `${TOK}/tokenizer_config.json`,
|
|
46
47
|
})
|
|
47
48
|
await chat.send([{ role: 'user', content: 'Hi!' }], { onText: (t) => process.stdout.write(t) })
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
The [demo](https://stfurkan.github.io/bitgpu/examples/chat.html) ([source](examples/chat.html))
|
|
51
52
|
is this quickstart as a single HTML file: model picker, streaming chat, JSON mode with a schema
|
|
52
|
-
editor,
|
|
53
|
+
editor, tool calling, cached downloads, and sessions that survive reloads (the KV cache is
|
|
54
|
+
snapshot into IndexedDB and restored - the conversation continues with no re-prefill).
|
|
53
55
|
|
|
54
56
|
## Usage
|
|
55
57
|
|
|
@@ -115,6 +117,49 @@ Reach for `'q8'` to run a 4x longer window in the same VRAM (or the same window
|
|
|
115
117
|
GPUs); keep the default `'f32'` when bit-exact reproducibility is the point.
|
|
116
118
|
`engine.capabilities.kvCache` reports what is actually active.
|
|
117
119
|
|
|
120
|
+
### Unbounded conversations (`overflow: 'sinks'`)
|
|
121
|
+
|
|
122
|
+
By default a conversation that outgrows `maxSeqLen` throws. `overflow: 'sinks'` switches to a
|
|
123
|
+
StreamingLLM-style rolling window instead: the first `sinkTokens` positions (default 4, the
|
|
124
|
+
"attention sinks" that anchor the model's attention) plus the most recent window are kept, the
|
|
125
|
+
middle is evicted in batches, and generation or multi-turn chat continues indefinitely in fixed
|
|
126
|
+
memory - `maxTokens` is no longer clamped to the window:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const engine = await createEngine({ modelUrl, kvCache: 'q8', overflow: 'sinks', maxSeqLen: 4096 })
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Implementation detail that matters: keys are cached **unroped** and rotated at read time by
|
|
133
|
+
their cache-relative position (the StreamingLLM reference scheme), so eviction is a plain
|
|
134
|
+
byte-exact compaction - nothing is ever re-rotated or, under q8, requantized. This is the
|
|
135
|
+
combination llama.cpp cannot offer (its context shift rewrites roped K in place and is
|
|
136
|
+
disabled for quantized K caches); here `q8 + sinks` is the flagship pairing: unbounded chat in
|
|
137
|
+
a quarter of the memory. The guarantees follow the mode philosophy: within-mode decoding is
|
|
138
|
+
exact and deterministic (same seed -> same tokens, across evictions; gated on real hardware),
|
|
139
|
+
and **before the first eviction f32+sinks is bit-identical to default f32** (gated against the
|
|
140
|
+
known-good ids). After an eviction the model genuinely forgets the evicted middle - that is
|
|
141
|
+
the trade, by design: prefer it over hard failure for open-ended chat; prefer `'error'` plus
|
|
142
|
+
prompt-side trimming when every token of context must count. Prompts longer than the window
|
|
143
|
+
still throw (`bitgpu/chat`'s `onOverflow` handles that side). Snapshots keep working - sink
|
|
144
|
+
mode saves version-2 snapshots (restore requires sink mode with the same `sinkTokens`).
|
|
145
|
+
|
|
146
|
+
### Speculative decoding: why only `promptLookup`
|
|
147
|
+
|
|
148
|
+
The engine speculates out of the box where it pays: `promptLookup` drafts from n-gram matches
|
|
149
|
+
in the prompt and verifies them in one batched pass, with auto-probation that measures the
|
|
150
|
+
break-even and bails when speculation does not help (output is bit-identical either way).
|
|
151
|
+
|
|
152
|
+
There is deliberately no draft-model / two-model mode, and the reason is measured, not
|
|
153
|
+
guessed: speculative decoding pays only when verifying k tokens in one batched pass costs
|
|
154
|
+
about one token's time - true for f16 models, whose decode is weight-bandwidth-bound, but not
|
|
155
|
+
for 1-bit models. The weight stream here is so small that batch-1 decode already saturates GPU
|
|
156
|
+
compute, so a k-row verify costs ~k single steps (measured: S=9 verify ~= 9.8x one step, and
|
|
157
|
+
even a perfect zero-cost drafter decoded slower than plain on the subgroup path). A full
|
|
158
|
+
in-engine two-model orchestration was built, gate-proven bit-exact, measured slower, and
|
|
159
|
+
removed - fast single-stream 1-bit decode and profitable speculation are the same budget,
|
|
160
|
+
already spent on the former. Where batching still wins (dispatch-latency-bound setups like the
|
|
161
|
+
no-subgroup fallback path) is exactly where `promptLookup`'s probation keeps it on.
|
|
162
|
+
|
|
118
163
|
## Chat (`bitgpu/chat`)
|
|
119
164
|
|
|
120
165
|
The engine is deliberately ids-in/ids-out; `bitgpu/chat` is the batteries-included text layer on
|
|
@@ -273,14 +318,15 @@ GPU gate proves the reuse paths bit-exact on real hardware. Prefer your own toke
|
|
|
273
318
|
|
|
274
319
|
## Bring your own model
|
|
275
320
|
|
|
276
|
-
bitgpu loads its own small format instead of parsing ONNX at runtime: a
|
|
277
|
-
architecture contract + every tensor mapped to a byte range) and a
|
|
278
|
-
produced ONCE, offline, from a standard export - while the big weights file is
|
|
279
|
-
byte-for-byte unchanged, so it can keep streaming from wherever it already lives (e.g.
|
|
280
|
-
Hugging Face Hub). Same one-time-conversion model as
|
|
321
|
+
bitgpu loads its own small format instead of parsing ONNX or GGUF at runtime: a
|
|
322
|
+
`manifest.json` (the architecture contract + every tensor mapped to a byte range) and a small
|
|
323
|
+
aux file, both produced ONCE, offline, from a standard export - while the big weights file is
|
|
324
|
+
used byte-for-byte unchanged, so it can keep streaming from wherever it already lives (e.g.
|
|
325
|
+
the Hugging Face Hub). Same one-time-conversion model as llama.cpp or MLX. Two converters:
|
|
281
326
|
|
|
282
327
|
```sh
|
|
283
|
-
python tools/convert.py --
|
|
328
|
+
python tools/convert-gguf.py --gguf <a 1-bit Q1_0 .gguf> # the .gguf itself stays the data file
|
|
329
|
+
python tools/convert-onnx.py --model <dir with config.json + the q1 .onnx + its data file>
|
|
284
330
|
```
|
|
285
331
|
|
|
286
332
|
Host the two small files anywhere (they're static), point `createEngine` at them, done:
|
|
@@ -289,18 +335,24 @@ Host the two small files anywhere (they're static), point `createEngine` at them
|
|
|
289
335
|
createEngine({
|
|
290
336
|
manifestUrl: 'https://your-site.example/model/manifest.json',
|
|
291
337
|
auxUrl: 'https://your-site.example/model/model_q1.aux.bin',
|
|
292
|
-
dataUrl: 'https://huggingface.co/<repo>/resolve/main
|
|
338
|
+
dataUrl: 'https://huggingface.co/<repo>/resolve/main/<model>.gguf', // or .../onnx/model_q1.onnx_data
|
|
293
339
|
})
|
|
294
340
|
```
|
|
295
341
|
|
|
296
|
-
Compatibility envelope: Qwen3-family models quantized with the
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
342
|
+
Compatibility envelope: Qwen3-family models quantized with the 1-bit recipe (silu/SwiGLU,
|
|
343
|
+
head_dim <= 128, 128-wide scale blocks, tied or untied lm_head), in either container: GGUFs
|
|
344
|
+
with PrismML's Q1_0 tensor type (the primary path), or ONNX exports with the onnx-community
|
|
345
|
+
"q1" recipe - the engine validates the manifest loudly at load. The two containers carry
|
|
346
|
+
bit-identical weights for the Bonsai releases (verified sign-bit-for-sign-bit on 8B), so pick
|
|
347
|
+
by hosting preference.
|
|
348
|
+
Reference exports: [prism-ml/Bonsai-1.7B-gguf](https://huggingface.co/prism-ml/Bonsai-1.7B-gguf) /
|
|
349
|
+
[4B](https://huggingface.co/prism-ml/Bonsai-4B-gguf) /
|
|
350
|
+
[8B](https://huggingface.co/prism-ml/Bonsai-8B-gguf) (`Bonsai-*-Q1_0.gguf`), and
|
|
351
|
+
[onnx-community/Bonsai-1.7B-ONNX](https://huggingface.co/onnx-community/Bonsai-1.7B-ONNX) /
|
|
352
|
+
[4B](https://huggingface.co/onnx-community/Bonsai-4B-ONNX) /
|
|
353
|
+
[8B](https://huggingface.co/onnx-community/Bonsai-8B-ONNX) (`onnx/model_q1.onnx` + data file). Format spec:
|
|
354
|
+
[docs/FORMAT.md](docs/FORMAT.md); the full pipeline including regenerating the verification
|
|
355
|
+
fixtures for a new model: [tools/README.md](tools/README.md).
|
|
304
356
|
|
|
305
357
|
## API
|
|
306
358
|
|
|
@@ -366,19 +418,22 @@ npm run check:publish # publint + are-the-types-wrong
|
|
|
366
418
|
### GPU verification gate
|
|
367
419
|
|
|
368
420
|
`examples/verify.html` re-runs the full bit-exactness + throughput suite (forward cosines vs the
|
|
369
|
-
committed reference fixtures in `test-fixtures/forward
|
|
421
|
+
committed reference fixtures in `test-fixtures/forward-<tag>/`, known-good greedy ids, sampler kernel
|
|
370
422
|
parity, determinism, KV reuse/growth, prompt-lookup identity, KV snapshot save/restore round
|
|
371
|
-
trips - including into a fresh engine -
|
|
372
|
-
plus greedy agreement vs f32 out to a 1500-token prompt
|
|
373
|
-
|
|
423
|
+
trips - including into a fresh engine - the f16/q8 KV-mode sections: within-mode exactness
|
|
424
|
+
plus greedy agreement vs f32 out to a 1500-token prompt, the rolling-window section:
|
|
425
|
+
pre-eviction bit-exactness, 600 tokens through a 192-token window, determinism across
|
|
426
|
+
evictions) against the **built package** and prints `PACKAGE OK` or `REGRESSION`.
|
|
374
427
|
|
|
375
|
-
It needs model weights, which are not committed. Point `examples/model` at a directory
|
|
376
|
-
model's `manifest.json` + data/aux files (the reference target is Bonsai-1.7B,
|
|
428
|
+
It needs model weights, which are not committed. Point `examples/model-1.7b` at a directory
|
|
429
|
+
holding the model's `manifest.json` + data/aux files (the reference target is Bonsai-1.7B,
|
|
430
|
+
~290 MB):
|
|
377
431
|
|
|
378
432
|
```sh
|
|
379
|
-
ln -s /path/to/bonsai-model examples/model # or copy the files in
|
|
433
|
+
ln -s /path/to/bonsai-model examples/model-1.7b # or copy the files in
|
|
380
434
|
npm run build
|
|
381
435
|
npm run verify:headless # serves the repo itself + drives system Chrome headlessly
|
|
436
|
+
FAST=1 npm run verify:headless # dev iteration: baseline model, core sections only (~3 min; NOT a release gate)
|
|
382
437
|
```
|
|
383
438
|
|
|
384
439
|
Or serve the repo root (`python3 -m http.server 8000`) and open
|
|
@@ -391,10 +446,11 @@ known-good ids.
|
|
|
391
446
|
|
|
392
447
|
The gate is model-parametric: `verify.html?model=<tag>` loads `examples/model-<tag>` against
|
|
393
448
|
`test-fixtures/forward-<tag>`, and the headless driver automatically runs every staged variant.
|
|
394
|
-
|
|
395
|
-
`forward-
|
|
396
|
-
|
|
397
|
-
|
|
449
|
+
Committed fixture sets: `forward-1.7b` (1.7B, hidden 2048), `forward-4b` (4B, hidden 2560),
|
|
450
|
+
`forward-8b` (8B, hidden 4096, untied lm_head, raised device limits), plus the GGUF-container
|
|
451
|
+
twins `forward-{1.7b,4b,8b}-gguf` (q1_0 de-interleave, tied and untied, three synthesized-rope
|
|
452
|
+
configurations) - so engine changes are checked against three geometries and both containers; stage
|
|
453
|
+
the extra weights with `ln -s /path/to/bonsai-<size> examples/model-<size>`. The chat-layer checks need
|
|
398
454
|
`tokenizer.json` + `tokenizer_config.json` in the staged model dir and skip loudly when absent.
|
|
399
455
|
To add fixtures for another model, run `tools/golden.py` then
|
|
400
456
|
`tools/reference.py --dump test-fixtures/forward-<tag>` on the converted work dir and record the
|
package/dist/chat.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as KvSnapshot, n as Engine, o as GenerateOptions, u as TokenLogprobs } from "./types-
|
|
1
|
+
import { c as KvSnapshot, n as Engine, o as GenerateOptions, u as TokenLogprobs } from "./types-Bl0FS_nX.js";
|
|
2
2
|
|
|
3
3
|
//#region src/chat/tokenizer.d.ts
|
|
4
4
|
interface ChatMessage {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ForwardResult, c as KvSnapshot, i as EngineOptions, l as LoadProgress, n as Engine, o as GenerateOptions, r as EngineCapabilities, s as GenerateResult, t as DeviceLostInfo, u as TokenLogprobs } from "./types-
|
|
1
|
+
import { a as ForwardResult, c as KvSnapshot, i as EngineOptions, l as LoadProgress, n as Engine, o as GenerateOptions, r as EngineCapabilities, s as GenerateResult, t as DeviceLostInfo, u as TokenLogprobs } from "./types-Bl0FS_nX.js";
|
|
2
2
|
|
|
3
3
|
//#region src/engine.d.ts
|
|
4
4
|
/** Load a 1-bit model and return an {@link Engine}. Pass a model URL string for defaults. */
|