bitgpu 0.15.0 → 0.16.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 CHANGED
@@ -53,7 +53,7 @@ weights stream straight from the Hugging Face Hub. This runs as-is:
53
53
  import { createEngine } from 'bitgpu'
54
54
  import { createChat } from 'bitgpu/chat'
55
55
 
56
- const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.15.0/models/bonsai-1.7b-gguf'
56
+ const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.16.0/models/bonsai-1.7b-gguf'
57
57
  const TOK = 'https://huggingface.co/onnx-community/Bonsai-1.7B-ONNX/resolve/main'
58
58
  const engine = await createEngine({
59
59
  manifestUrl: `${REPO}/manifest.json`,
@@ -136,6 +136,21 @@ Reach for `'q8'` to run a 4x longer window in the same VRAM (or the same window
136
136
  GPUs); keep the default `'f32'` when bit-exact reproducibility is the point.
137
137
  `engine.capabilities.kvCache` reports what is actually active.
138
138
 
139
+ ### f16 activation-compute (`activation: 'f16'`)
140
+
141
+ `activation: 'f16'` runs the decode matmuls with **f16 activations** (the 1-bit weights stay packed,
142
+ the accumulator and residual stream stay f32). It needs `shader-f16` + the subgroup path and silently
143
+ falls back to f32 without them, so it is always safe to request. On GPUs with **packed-f16 throughput
144
+ (NVIDIA / AMD)** it is a real decode win; on Apple it is ~neutral (the 1-bit GEMV is unpack- not
145
+ dot-bound), which is why it is opt-in rather than the default. It is measured **greedy-exact** against
146
+ f32 on every model - dense **and** the qwen3.5 hybrid. If your users run NVIDIA/AMD, turn it on:
147
+
148
+ ```ts
149
+ const engine = await createEngine({ modelUrl, activation: 'f16', kvCache: 'q8', maxSeqLen: 4096 })
150
+ ```
151
+
152
+ `engine.capabilities.activation` reports whether it engaged.
153
+
139
154
  ### Unbounded conversations (`overflow: 'sinks'`)
140
155
 
141
156
  By default a conversation that outgrows `maxSeqLen` throws. `overflow: 'sinks'` switches to a
@@ -362,10 +377,14 @@ The Qwen3.5 hybrid **Bonsai-27B** loads exactly the same way - `fromGguf` is its
362
377
  no offline converter for the hybrid yet), so point at
363
378
  `prism-ml/Bonsai-27B-gguf/resolve/main/Bonsai-27B-Q1_0.gguf` with `kvCache: 'q8'` and, say,
364
379
  `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.
380
+ scope). Text chat works through `bitgpu/chat` unchanged - its Jinja template and tool-call rendering
381
+ go through the same path as the dense models (verified end-to-end) - but the GGUF repo ships no
382
+ tokenizer, so point `createChat` at [prism-ml/Bonsai-27B-unpacked](https://huggingface.co/prism-ml/Bonsai-27B-unpacked)
383
+ for `tokenizer.json` + `tokenizer_config.json`. It is a ~3.8 GB download and comfortably wants a 16 GB
384
+ (or larger) GPU budget - on an 8 GB laptop it runs but the weights spill to swap, so decode is slow.
385
+ A hybrid upside: its 48 gated-DeltaNet layers cost O(1) per token, so decode throughput stays nearly
386
+ flat as context grows (only the 16 full-attention layers scale with length) - a long-context
387
+ durability edge over a same-size pure-attention model.
369
388
 
370
389
  The in-browser parse is gated: it must deep-equal the offline converter's manifest AND an
371
390
  engine built from it must reproduce the known-good greedy ids bit-exactly on GPU. Prefer the
package/dist/index.js CHANGED
@@ -1383,11 +1383,11 @@ async function createEngineInner(options, holder) {
1383
1383
  ["f", A.rms_eps],
1384
1384
  ["u", 0]
1385
1385
  ], [x, W[g].buf], out, R);
1386
- function fusedMM(pass, w, inBuf, S, outs) {
1386
+ function fusedMM(pass, w, inBuf, S, outs, af = false) {
1387
1387
  const Ntot = w.N0 + w.N1 + w.N2;
1388
1388
  if (useSG && S === 1) {
1389
1389
  const gx = Math.min(Ntot, 65535);
1390
- runWG(pass, "matmul_split_sg", [
1390
+ runWG(pass, af ? "matmul_split_sg_af16" : "matmul_split_sg", [
1391
1391
  ["u", w.K],
1392
1392
  ["u", w.nb],
1393
1393
  ["u", w.N0],
@@ -1564,8 +1564,9 @@ async function createEngineInner(options, holder) {
1564
1564
  const w = (r) => W[`layers.${li}.${r}`];
1565
1565
  const ls = posBase > 0 ? 1 : 0;
1566
1566
  const par = hyPar;
1567
- const n1 = actBuf(S * Hd);
1568
- rms(pass, h, `layers.${li}.input_layernorm`, S, Hd, n1);
1567
+ const af = actF16 && S === 1 && !FORCE_SLOW;
1568
+ const n1 = af ? actBuf16(S * Hd) : actBuf(S * Hd);
1569
+ rms(pass, h, `layers.${li}.input_layernorm`, S, Hd, n1, af);
1569
1570
  let h2;
1570
1571
  if (hy.layer_types[li] === "linear") {
1571
1572
  const mixed = actBuf(S * CONVDIM);
@@ -1573,7 +1574,7 @@ async function createEngineInner(options, holder) {
1573
1574
  mixed,
1574
1575
  dummy,
1575
1576
  dummy2
1576
- ]);
1577
+ ], af);
1577
1578
  const convd = actBuf(S * CONVDIM);
1578
1579
  const cvSt = (CONVK - 1) * CONVDIM;
1579
1580
  setup(pass, "conv1d_causal", [
@@ -1614,12 +1615,12 @@ async function createEngineInner(options, holder) {
1614
1615
  a,
1615
1616
  dummy,
1616
1617
  dummy2
1617
- ]);
1618
+ ], af);
1618
1619
  fusedMM(pass, w("linear.b"), n1, S, [
1619
1620
  b,
1620
1621
  dummy,
1621
1622
  dummy2
1622
- ]);
1623
+ ], af);
1623
1624
  const gb = actBuf(2 * S * NV);
1624
1625
  run(pass, "deltanet_gbeta", [
1625
1626
  ["u", S],
@@ -1656,7 +1657,7 @@ async function createEngineInner(options, holder) {
1656
1657
  z,
1657
1658
  dummy,
1658
1659
  dummy2
1659
- ]);
1660
+ ], af);
1660
1661
  const normed = actBuf(S * VALDIM);
1661
1662
  runN(pass, "deltanet_norm_gate", [
1662
1663
  ["u", S * NV],
@@ -1676,7 +1677,7 @@ async function createEngineInner(options, holder) {
1676
1677
  qg,
1677
1678
  dummy,
1678
1679
  dummy2
1679
- ]);
1680
+ ], af);
1680
1681
  const query = actBuf(S * H * Dh), gate = actBuf(S * H * Dh);
1681
1682
  run(pass, "split_head", [
1682
1683
  ["u", S],
@@ -1707,7 +1708,7 @@ async function createEngineInner(options, holder) {
1707
1708
  kk,
1708
1709
  dummy,
1709
1710
  dummy2
1710
- ]);
1711
+ ], af);
1711
1712
  const kn = actBuf(S * KV * Dh), kr = actBuf(S * KV * Dh);
1712
1713
  rms(pass, kk, `layers.${li}.attn.k_norm`, S * KV, Dh, kn);
1713
1714
  run(pass, "rope_partial", [
@@ -1725,7 +1726,7 @@ async function createEngineInner(options, holder) {
1725
1726
  vv,
1726
1727
  dummy,
1727
1728
  dummy2
1728
- ]);
1729
+ ], af);
1729
1730
  appendKV(pass, kr, 0, li, S * KV, posBase * KV);
1730
1731
  appendKV(pass, vv, 1, li, S * KV, posBase * KV);
1731
1732
  const att = actBuf(S * H * Dh);
@@ -1761,19 +1762,19 @@ async function createEngineInner(options, holder) {
1761
1762
  h2 = actBuf(S * Hd);
1762
1763
  residMM(pass, w("attn.o_proj"), gated, h, S, h2);
1763
1764
  }
1764
- const n2 = actBuf(S * Hd);
1765
- rms(pass, h2, `layers.${li}.post_attention_layernorm`, S, Hd, n2);
1765
+ const n2 = af ? actBuf16(S * Hd) : actBuf(S * Hd);
1766
+ rms(pass, h2, `layers.${li}.post_attention_layernorm`, S, Hd, n2, af);
1766
1767
  const g = actBuf(S * F), u = actBuf(S * F);
1767
1768
  fusedMM(pass, w("mlp.gate_proj"), n2, S, [
1768
1769
  g,
1769
1770
  dummy,
1770
1771
  dummy2
1771
- ]);
1772
+ ], af);
1772
1773
  fusedMM(pass, w("mlp.up_proj"), n2, S, [
1773
1774
  u,
1774
1775
  dummy,
1775
1776
  dummy2
1776
- ]);
1777
+ ], af);
1777
1778
  const sw = actBuf(S * F);
1778
1779
  run(pass, "swiglu", [
1779
1780
  ["u", S * F],