bitgpu 0.6.0 → 0.8.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.
@@ -97,15 +97,28 @@ interface GenerateOptions {
97
97
  noRepeatNgramSize?: number;
98
98
  /** Seed for the sampler RNG. Omit to seed from entropy (non-deterministic, like production). */
99
99
  seed?: number;
100
+ /** EXPERIMENTAL. Per-step constrained-decoding hook: receives the top-K candidate token ids
101
+ * (rank order, penalized logits alongside) and returns the PERMITTED subset (any order).
102
+ * Greedy picks the best permitted candidate; sampling renormalizes the draw over them. When
103
+ * it permits none, the engine walks the full vocabulary in logit order (rare; the step costs
104
+ * a full logits readback) and throws if no token at all is permitted. Must be deterministic
105
+ * and synchronous; the engine calls it once per emitted token, in order. Incompatible with
106
+ * `promptLookup` (speculation is disabled while a filter is set). Used by bitgpu/chat's
107
+ * `format: 'json'`. */
108
+ candidateFilter?: (candidateIds: Uint32Array, candidateLogits: Float32Array) => number[];
100
109
  /** EXPERIMENTAL. Prompt-lookup speculative decoding: draft the continuation from an n-gram
101
110
  * match in the sequence so far and verify every draft in ONE batched forward. Output is
102
111
  * identical to normal decoding, greedy AND sampled (each emitted token still comes from its
103
112
  * true penalized distribution, and the RNG advances one draw per emitted token, in order).
104
- * INCOMPATIBLE with `noRepeatNgramSize`: a prompt-lookup draft is the continuation of a
105
- * repeated n-gram, which is exactly what the ngram ban forbids, so acceptance is ~zero when
106
- * both are on (measured 0/320). Use with greedy decoding or ngram-ban-free sampling. No
107
- * draft model, no extra VRAM. `true` = `{ ngramSize: 3, maxDraft: 8 }`. Default `false`. */
108
- promptLookup?: boolean | {
113
+ * `'auto'` speculates for a short probation window, then keeps PLD only when the measured
114
+ * acceptance actually beats plain decoding for this content - and falls back to the plain
115
+ * path otherwise (output still identical; `speculation.bailed` reports the decision). Use
116
+ * `'auto'` unless you know the content repeats (quoting, lists, code), where `true` skips
117
+ * the probation. INCOMPATIBLE with `noRepeatNgramSize`: a prompt-lookup draft is the
118
+ * continuation of a repeated n-gram, which is exactly what the ngram ban forbids, so
119
+ * acceptance is ~zero when both are on (measured 0/320). No draft model, no extra VRAM.
120
+ * `true`/`'auto'` = `{ ngramSize: 3, maxDraft: 8 }`. Default `false`. */
121
+ promptLookup?: boolean | 'auto' | {
109
122
  ngramSize?: number;
110
123
  maxDraft?: number;
111
124
  };
@@ -120,17 +133,22 @@ interface GenerateResult {
120
133
  decodeMs: number;
121
134
  /** Decode throughput (tokens / second), excluding prefill. */
122
135
  tokensPerSecond: number;
123
- /** Per-token decode timing breakdown, in milliseconds. */
136
+ /** Per-token decode timing breakdown, in milliseconds. In sampled mode the GPU wait and the
137
+ * readback map share one sync, so the wait is attributed to `gpuMs` and `readbackMs` covers
138
+ * only the post-map CPU work (near zero). */
124
139
  timing: {
125
140
  recordMs: number;
126
141
  gpuMs: number;
127
142
  readbackMs: number;
128
143
  };
129
- /** Present when prompt-lookup decoding ran: verify steps taken, tokens drafted, drafts accepted. */
144
+ /** Present when prompt-lookup decoding ran: verify steps taken, tokens drafted, drafts
145
+ * accepted. With `promptLookup: 'auto'`, `bailed` reports whether the probation decided to
146
+ * stop speculating for the rest of the turn. */
130
147
  speculation?: {
131
148
  steps: number;
132
149
  drafted: number;
133
150
  accepted: number;
151
+ bailed?: boolean;
134
152
  };
135
153
  }
136
154
  /** Diagnostic result of {@link Engine.forward}: hidden states + logits for a single forward pass. */
@@ -150,6 +168,9 @@ interface EngineCapabilities {
150
168
  subgroupSize: number;
151
169
  /** Active KV-cache storage precision ('f16' only when requested AND the adapter has shader-f16). */
152
170
  kvCache: 'f32' | 'f16';
171
+ /** The engine's KV window in positions (the resolved maxSeqLen option): prompt + generated
172
+ * tokens per conversation must fit inside it. */
173
+ maxSeqLen: number;
153
174
  /** Adapter identification, when the browser exposes it. */
154
175
  adapter: {
155
176
  vendor?: string;
@@ -188,4 +209,4 @@ interface Engine {
188
209
  }
189
210
  //#endregion
190
211
  export { ForwardResult as a, LoadProgress as c, EngineOptions as i, Engine as n, GenerateOptions as o, EngineCapabilities as r, GenerateResult as s, DeviceLostInfo as t };
191
- //# sourceMappingURL=types-C3FWn4rd.d.ts.map
212
+ //# sourceMappingURL=types-CsoJYJlG.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitgpu",
3
- "version": "0.6.0",
3
+ "version": "0.8.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",