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.
@@ -54,6 +54,28 @@ interface ManifestArch {
54
54
  };
55
55
  /** position cap for synthesized rope (GGUF context_length) */
56
56
  max_positions?: number;
57
+ /** Hybrid backbone (qwen3_5 / GGUF `qwen35`): a per-layer mix of gated-DeltaNet linear
58
+ * attention and gated full attention. Absent for the dense qwen3 models. When present, the
59
+ * full-attention layers use partial RoPE ({@link HybridArch.rotary_dim}) and an output gate. */
60
+ hybrid?: HybridArch;
61
+ }
62
+ /** The extra architecture contract for the hybrid qwen3_5 backbone. `heads`/`kv_heads`/`head_dim`
63
+ * on {@link ManifestArch} describe the FULL-attention layers; the linear layers are described here. */
64
+ interface HybridArch {
65
+ /** Per-layer token mixer, length = {@link ManifestArch.layers}: `'linear'` = gated DeltaNet,
66
+ * `'full'` = gated attention. Derived from the 3:1 `full_attention_interval` pattern. */
67
+ layer_types: ('linear' | 'full')[];
68
+ /** Number of key/query heads in the gated-DeltaNet layers (GGUF `ssm.group_count`). */
69
+ linear_key_heads: number;
70
+ /** Number of value heads (>= key heads; query/key are repeat-interleaved to match). GGUF `ssm.time_step_rank`. */
71
+ linear_value_heads: number;
72
+ /** Head dim of the linear-attention keys and values (they share it). GGUF `ssm.state_size`. */
73
+ linear_head_dim: number;
74
+ /** Depthwise causal conv1d kernel width applied to the q/k/v stream (GGUF `ssm.conv_kernel`). */
75
+ conv_kernel: number;
76
+ /** Rotary dims actually rotated in the full-attention layers (partial RoPE, GGUF `rope.dimension_count`);
77
+ * the remaining `head_dim - rotary_dim` dims pass through unrotated. */
78
+ rotary_dim: number;
57
79
  }
58
80
  /** The small model-description file bitgpu loads (see docs/FORMAT.md). Usually fetched as
59
81
  * `manifest.json`; `bitgpu/gguf` builds one in memory straight from a GGUF header. */
@@ -131,6 +153,15 @@ interface EngineOptions {
131
153
  * seed -> same tokens; cache reuse == full prefill). See `capabilities.kvCache` for what's
132
154
  * active. Default `'f32'`. */
133
155
  kvCache?: 'f32' | 'f16' | 'q8';
156
+ /** Activation-compute precision for the decode matmuls (the 1-bit GEMVs that dominate decode).
157
+ * `'f16'` reads activations as f16 and runs the per-block dot in f16 (2x ALU rate on
158
+ * Apple/AMD/recent NVIDIA) with f32 accumulation; the residual stream and weights stay f32.
159
+ * Like `kvCache: 'f16'` it needs the `shader-f16` adapter feature and the subgroup path, and
160
+ * SILENTLY FALLS BACK to f32 without them, so it is safe to request unconditionally. Outputs
161
+ * are not bit-identical to f32 (measured near-lossless by the GPU gate, q8-KV tier) but WITHIN
162
+ * the mode decoding is exact and deterministic. Applies to decode only (prefill stays f32).
163
+ * See `capabilities.activation` for what is active. Default `'f32'`. */
164
+ activation?: 'f32' | 'f16';
134
165
  /** What happens when a conversation outgrows `maxSeqLen`. `'error'` (default): generate
135
166
  * throws, exactly as before. `'sinks'`: StreamingLLM-style rolling window - the first
136
167
  * `sinkTokens` positions (attention sinks) plus the most recent window are kept and the
@@ -285,6 +316,9 @@ interface EngineCapabilities {
285
316
  /** Active KV-cache storage precision ('f16' only when requested AND the adapter has shader-f16;
286
317
  * 'q8' whenever requested - it needs no adapter feature). */
287
318
  kvCache: 'f32' | 'f16' | 'q8';
319
+ /** Active activation-compute precision ('f16' only when requested AND the adapter has shader-f16
320
+ * AND the subgroup path is in use; else 'f32'). */
321
+ activation: 'f32' | 'f16';
288
322
  /** Active overflow policy ('sinks' = rolling window with attention sinks). */
289
323
  overflow: 'error' | 'sinks';
290
324
  /** The engine's KV window in positions (the resolved maxSeqLen option). Under
@@ -303,6 +337,9 @@ interface EngineCapabilities {
303
337
  maxStorageBufferBindingSize: number;
304
338
  maxComputeWorkgroupStorageSize: number;
305
339
  };
340
+ /** Whether the device has the `timestamp-query` feature (true GPU-side kernel timing is
341
+ * available to the dev profiler; see the profileDecode diagnostics). */
342
+ timestampQuery: boolean;
306
343
  }
307
344
  /** A saved KV cache + conversation token history, from {@link Engine.saveCache}. A plain object
308
345
  * holding one `ArrayBuffer`, so it is structured-cloneable: store it in IndexedDB / OPFS or send
@@ -330,7 +367,14 @@ interface KvSnapshot {
330
367
  };
331
368
  /** The full conversation token sequence at save time. */
332
369
  ids: number[];
333
- /** Packed per-layer cached K/V bytes (and q8 block scales). */
370
+ /** DELTA snapshot: `data` holds only cache positions `[base, len)` - the leading `base` positions
371
+ * (e.g. a shared prewarmed system prompt) are NOT stored and must already be present in the
372
+ * restore target (restore into an engine freshly prewarmed with the same prefix). Absent/0 = a
373
+ * full snapshot (all positions in `data`). Restore validates the target is exactly at the base
374
+ * boundary with a matching token prefix. */
375
+ base?: number;
376
+ /** Packed cached K/V bytes (and q8 block scales) for the stored positions, per KV-bearing layer;
377
+ * for the qwen3_5 hybrid the DeltaNet recurrent + conv state of each linear layer is appended. */
334
378
  data: ArrayBuffer;
335
379
  }
336
380
  /** A loaded model ready to generate. Create one with {@link createEngine}. */
@@ -354,8 +398,17 @@ interface Engine {
354
398
  * the conversation alive, so conversations survive engine disposal and page reloads (persist
355
399
  * the snapshot in IndexedDB / OPFS). Size ~ tokens x layers x kvHeads x headDim x 2 x
356
400
  * bytes-per-value (~224 KB/token at f32 on Bonsai-1.7B, ~63 KB/token at q8). Returns `null`
357
- * when the cache is empty. Serialized with generate/prefill/forward like every engine op. */
358
- saveCache(): Promise<KvSnapshot | null>;
401
+ * when the cache is empty. Serialized with generate/prefill/forward like every engine op.
402
+ *
403
+ * `from` makes a DELTA snapshot that excludes the first `from` cache positions (a shared
404
+ * prewarmed prefix), so per-conversation snapshots drop the redundant system-prompt KV (tens of
405
+ * MB at chat scale). Restore it into an engine freshly prewarmed with the SAME prefix - see the
406
+ * `base` field on {@link KvSnapshot}. `from` counts cache positions: for a prewarm of P tokens
407
+ * pass `from = P - 1` (a fresh prewarm caches P-1 positions; the last prewarm token's K/V is part
408
+ * of the delta). `bitgpu/chat`'s `save({ delta: true })` computes this for you. */
409
+ saveCache(opts?: {
410
+ from?: number;
411
+ }): Promise<KvSnapshot | null>;
359
412
  /** Replace the current conversation with a {@link KvSnapshot} (CPU -> GPU upload). The next
360
413
  * `generate(delta, { reuseCache: true })` continues the saved conversation exactly. Throws if
361
414
  * the snapshot's model architecture or `kvCache` mode does not match this engine, or if it
@@ -371,4 +424,4 @@ interface Engine {
371
424
  }
372
425
  //#endregion
373
426
  export { ForwardResult as a, KvSnapshot as c, ManifestArch as d, ManifestRef as f, EngineOptions as i, LoadProgress as l, TokenLogprobs as m, Engine as n, GenerateOptions as o, ManifestTensor as p, EngineCapabilities as r, GenerateResult as s, DeviceLostInfo as t, Manifest as u };
374
- //# sourceMappingURL=types-ByYx15Yw.d.ts.map
427
+ //# sourceMappingURL=types-Wg8VrdrL.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitgpu",
3
- "version": "0.13.1",
3
+ "version": "0.15.0",
4
4
  "description": "Fast WebGPU runtime for 1-bit (binary-weight) LLMs in the browser. Bit-exact, zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,7 +55,11 @@
55
55
  "check:publish": "publint --strict && attw --pack . --profile esm-only",
56
56
  "prepare": "npm run build",
57
57
  "prepublishOnly": "npm run build && npm run check:publish",
58
- "test:gguf": "tsx scripts/verify-gguf.ts"
58
+ "test:gguf": "tsx scripts/verify-gguf.ts",
59
+ "test:kernels": "python3 tools/gen-kernel-cases.py && node scripts/verify-kernels.mjs",
60
+ "test:hybrid": "python3 tools/gen-synth-qwen35.py && npm run build && node scripts/verify-hybrid.mjs",
61
+ "profile": "node scripts/profile.mjs",
62
+ "bench": "node scripts/benchmark.mjs"
59
63
  },
60
64
  "devDependencies": {
61
65
  "@arethetypeswrong/cli": "0.18.4",