bitgpu 0.13.1 → 0.14.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 +17 -1
- 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/index.d.ts +1 -1
- package/dist/index.js +134 -40
- package/dist/index.js.map +1 -1
- package/dist/{types-ByYx15Yw.d.ts → types-iFADjEuf.d.ts} +34 -4
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -25,6 +25,22 @@ npm install bitgpu
|
|
|
25
25
|
|
|
26
26
|
ESM-only, zero runtime dependencies.
|
|
27
27
|
|
|
28
|
+
## Benchmark
|
|
29
|
+
|
|
30
|
+
Against the mainstream WebGPU path for the same model - transformers.js with `dtype: 'q1'` - on the
|
|
31
|
+
**identical** 1-bit Bonsai-1.7B weights, same GPU, same prompt, both in one page:
|
|
32
|
+
|
|
33
|
+
| | transformers.js 4.2.0 (`dtype: 'q1'`) | bitgpu |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| decode | 17.7 tok/s | **23.8 tok/s** (up to ~1.8x at short context) |
|
|
36
|
+
| prefill (156-token prompt) | 5.6 s | **0.9 s** (~6x) |
|
|
37
|
+
|
|
38
|
+
Point-in-time, one machine (Apple M-series, Chrome 150 / WebGPU, 2026-07) - so treat it as a
|
|
39
|
+
ballpark, not a leaderboard. Reproduce it, or run your own model / GPU, with `npm run bench`
|
|
40
|
+
([examples/benchmark.html](examples/benchmark.html) loads both engines side by side and prints the
|
|
41
|
+
numbers). Weights are bit-identical across the two containers (the GGUF sign-bit stream equals the
|
|
42
|
+
onnx-community q1 export), so this measures the runtime, not the model.
|
|
43
|
+
|
|
28
44
|
## Quickstart - no conversion, no hosting
|
|
29
45
|
|
|
30
46
|
Ready-made manifests for all three Bonsai sizes are committed under [`models/`](models/); the
|
|
@@ -34,7 +50,7 @@ weights stream straight from the Hugging Face Hub. This runs as-is:
|
|
|
34
50
|
import { createEngine } from 'bitgpu'
|
|
35
51
|
import { createChat } from 'bitgpu/chat'
|
|
36
52
|
|
|
37
|
-
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.
|
|
53
|
+
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.14.0/models/bonsai-1.7b-gguf'
|
|
38
54
|
const TOK = 'https://huggingface.co/onnx-community/Bonsai-1.7B-ONNX/resolve/main'
|
|
39
55
|
const engine = await createEngine({
|
|
40
56
|
manifestUrl: `${REPO}/manifest.json`,
|
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-iFADjEuf.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
|