bitgpu 0.8.0 → 0.10.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 +142 -13
- package/THIRD_PARTY_LICENSES.md +2 -2
- package/dist/chat.d.ts +220 -9
- package/dist/chat.js +655 -52
- package/dist/chat.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +249 -56
- package/dist/index.js.map +1 -1
- package/dist/{types-CsoJYJlG.d.ts → types-CcgsXirU.d.ts} +77 -12
- package/package.json +1 -1
|
@@ -43,15 +43,20 @@ interface EngineOptions {
|
|
|
43
43
|
/** Prefill GEMM tiling: `'auto'` tiles once a prompt fills the 64-row tiles, `'always'`/`'never'` force it. Default `'auto'`. */
|
|
44
44
|
prefillTiling?: 'auto' | 'always' | 'never';
|
|
45
45
|
/** Max KV-cache length (prompt + generated positions). Caps VRAM (~`maxSeqLen` x 224 KB at f32,
|
|
46
|
-
* half that with `kvCache: 'f16'`). Default `2048`. */
|
|
46
|
+
* half that with `kvCache: 'f16'`, ~a quarter with `'q8'`). Default `2048`. */
|
|
47
47
|
maxSeqLen?: number;
|
|
48
|
-
/** KV-cache STORAGE precision. `'f16'` halves KV memory (
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
|
|
48
|
+
/** KV-cache STORAGE precision. `'f16'` halves KV memory (all arithmetic stays f32; each cached
|
|
49
|
+
* K/V value is rounded once at cache-write); it falls back to `'f32'` silently when the
|
|
50
|
+
* adapter lacks `shader-f16`. `'q8'` QUARTERS KV memory vs f32 (packed 8-bit values with one
|
|
51
|
+
* f32 scale per 32-element block, llama.cpp q8_0-style, ~1.125 bytes/value) and needs no
|
|
52
|
+
* adapter feature, so it works even where f16 does not (and at long context it decodes FASTER
|
|
53
|
+
* than f32 - attention there is memory-bound and reads a quarter of the bytes). Outputs under
|
|
54
|
+
* f16/q8 are no longer
|
|
55
|
+
* guaranteed bit-identical to f32 mode - q8 is the first knowingly-lossy tier, measured per
|
|
56
|
+
* model by the GPU gate - though WITHIN a mode decoding stays exact and deterministic (same
|
|
57
|
+
* seed -> same tokens; cache reuse == full prefill). See `capabilities.kvCache` for what's
|
|
58
|
+
* active. Default `'f32'`. */
|
|
59
|
+
kvCache?: 'f32' | 'f16' | 'q8';
|
|
55
60
|
/** Called as the model loads. */
|
|
56
61
|
onProgress?: (progress: LoadProgress) => void;
|
|
57
62
|
/** Called if the GPU device is lost after creation (driver reset, OS reclaim, tab backgrounding
|
|
@@ -122,6 +127,26 @@ interface GenerateOptions {
|
|
|
122
127
|
ngramSize?: number;
|
|
123
128
|
maxDraft?: number;
|
|
124
129
|
};
|
|
130
|
+
/** Per-token TRUE logprobs (log-softmax over the full vocabulary, after penalties): set to N
|
|
131
|
+
* (1..32) to receive the emitted token's logprob plus the top-N alternatives each step in
|
|
132
|
+
* {@link GenerateResult.logprobs}. Exact, not a top-K approximation - the normalizer is a GPU
|
|
133
|
+
* log-sum-exp over all logits (one extra f32 readback per step). Routes greedy turns through
|
|
134
|
+
* the per-step sampler path and disables `promptLookup` (a verified draft step has no
|
|
135
|
+
* per-token candidate readback); sampled turns pay nothing extra. Use it to expose model
|
|
136
|
+
* confidence: a low top-1 logprob or a flat top-N is the model guessing. Default off. */
|
|
137
|
+
logprobs?: number;
|
|
138
|
+
}
|
|
139
|
+
/** One emitted token's logprob record (see {@link GenerateOptions.logprobs}). */
|
|
140
|
+
interface TokenLogprobs {
|
|
141
|
+
/** The emitted token's logprob (log-softmax over the full vocab, post-penalty). Under a
|
|
142
|
+
* candidateFilter this is the logprob of the token actually chosen, which the filter may
|
|
143
|
+
* have forced far below the top alternatives. */
|
|
144
|
+
logprob: number;
|
|
145
|
+
/** The top-N (id, logprob) pairs in descending order, independent of what was emitted. */
|
|
146
|
+
top: {
|
|
147
|
+
id: number;
|
|
148
|
+
logprob: number;
|
|
149
|
+
}[];
|
|
125
150
|
}
|
|
126
151
|
/** Result of a {@link Engine.generate} call. */
|
|
127
152
|
interface GenerateResult {
|
|
@@ -150,6 +175,9 @@ interface GenerateResult {
|
|
|
150
175
|
accepted: number;
|
|
151
176
|
bailed?: boolean;
|
|
152
177
|
};
|
|
178
|
+
/** Present when {@link GenerateOptions.logprobs} was set: one record per emitted token,
|
|
179
|
+
* aligned with `tokens`. */
|
|
180
|
+
logprobs?: TokenLogprobs[];
|
|
153
181
|
}
|
|
154
182
|
/** Diagnostic result of {@link Engine.forward}: hidden states + logits for a single forward pass. */
|
|
155
183
|
interface ForwardResult {
|
|
@@ -166,8 +194,9 @@ interface EngineCapabilities {
|
|
|
166
194
|
useSubgroups: boolean;
|
|
167
195
|
/** Subgroup width when the subgroup path is active. */
|
|
168
196
|
subgroupSize: number;
|
|
169
|
-
/** Active KV-cache storage precision ('f16' only when requested AND the adapter has shader-f16
|
|
170
|
-
|
|
197
|
+
/** Active KV-cache storage precision ('f16' only when requested AND the adapter has shader-f16;
|
|
198
|
+
* 'q8' whenever requested - it needs no adapter feature). */
|
|
199
|
+
kvCache: 'f32' | 'f16' | 'q8';
|
|
171
200
|
/** The engine's KV window in positions (the resolved maxSeqLen option): prompt + generated
|
|
172
201
|
* tokens per conversation must fit inside it. */
|
|
173
202
|
maxSeqLen: number;
|
|
@@ -184,6 +213,29 @@ interface EngineCapabilities {
|
|
|
184
213
|
maxComputeWorkgroupStorageSize: number;
|
|
185
214
|
};
|
|
186
215
|
}
|
|
216
|
+
/** A saved KV cache + conversation token history, from {@link Engine.saveCache}. A plain object
|
|
217
|
+
* holding one `ArrayBuffer`, so it is structured-cloneable: store it in IndexedDB / OPFS or send
|
|
218
|
+
* it over `postMessage` as-is (it is NOT `JSON.stringify`-able - the buffer would be lost).
|
|
219
|
+
* Restore requires the SAME model architecture and the SAME `kvCache` mode; snapshots never
|
|
220
|
+
* convert across modes. Treat the fields as opaque. */
|
|
221
|
+
interface KvSnapshot {
|
|
222
|
+
/** Snapshot format version (currently `1`). */
|
|
223
|
+
version: 1;
|
|
224
|
+
/** KV storage mode the snapshot was taken under. */
|
|
225
|
+
kvCache: 'f32' | 'f16' | 'q8';
|
|
226
|
+
/** Architecture stamp; restore rejects a snapshot from a different model shape. */
|
|
227
|
+
model: {
|
|
228
|
+
layers: number;
|
|
229
|
+
kvHeads: number;
|
|
230
|
+
headDim: number;
|
|
231
|
+
hidden: number;
|
|
232
|
+
vocab: number;
|
|
233
|
+
};
|
|
234
|
+
/** The full conversation token sequence at save time. */
|
|
235
|
+
ids: number[];
|
|
236
|
+
/** Packed per-layer cached K/V bytes (and q8 block scales). */
|
|
237
|
+
data: ArrayBuffer;
|
|
238
|
+
}
|
|
187
239
|
/** A loaded model ready to generate. Create one with {@link createEngine}. */
|
|
188
240
|
interface Engine {
|
|
189
241
|
/** Generate tokens from a prompt given as token ids. */
|
|
@@ -199,6 +251,19 @@ interface Engine {
|
|
|
199
251
|
forward(tokenIds: number[]): Promise<ForwardResult>;
|
|
200
252
|
/** Clear the cross-turn KV cache and token history (start a fresh conversation). */
|
|
201
253
|
resetCache(): void;
|
|
254
|
+
/** Snapshot the current conversation - KV cache contents + token history - as a
|
|
255
|
+
* structured-cloneable {@link KvSnapshot} (GPU -> CPU readback). Restoring it, into this
|
|
256
|
+
* engine or a fresh one on the same model and `kvCache` mode, is bit-identical to having kept
|
|
257
|
+
* the conversation alive, so conversations survive engine disposal and page reloads (persist
|
|
258
|
+
* the snapshot in IndexedDB / OPFS). Size ~ tokens x layers x kvHeads x headDim x 2 x
|
|
259
|
+
* bytes-per-value (~224 KB/token at f32 on Bonsai-1.7B, ~63 KB/token at q8). Returns `null`
|
|
260
|
+
* when the cache is empty. Serialized with generate/prefill/forward like every engine op. */
|
|
261
|
+
saveCache(): Promise<KvSnapshot | null>;
|
|
262
|
+
/** Replace the current conversation with a {@link KvSnapshot} (CPU -> GPU upload). The next
|
|
263
|
+
* `generate(delta, { reuseCache: true })` continues the saved conversation exactly. Throws if
|
|
264
|
+
* the snapshot's model architecture or `kvCache` mode does not match this engine, or if it
|
|
265
|
+
* exceeds this engine's `maxSeqLen`. */
|
|
266
|
+
restoreCache(snapshot: KvSnapshot): Promise<void>;
|
|
202
267
|
/** Detected GPU capabilities and selected code path. */
|
|
203
268
|
readonly capabilities: EngineCapabilities;
|
|
204
269
|
/** Resolves when the GPU device is lost (including via {@link dispose}, with reason 'destroyed').
|
|
@@ -208,5 +273,5 @@ interface Engine {
|
|
|
208
273
|
dispose(): void;
|
|
209
274
|
}
|
|
210
275
|
//#endregion
|
|
211
|
-
export { ForwardResult as a,
|
|
212
|
-
//# sourceMappingURL=types-
|
|
276
|
+
export { ForwardResult as a, KvSnapshot as c, EngineOptions as i, LoadProgress as l, Engine as n, GenerateOptions as o, EngineCapabilities as r, GenerateResult as s, DeviceLostInfo as t, TokenLogprobs as u };
|
|
277
|
+
//# sourceMappingURL=types-CcgsXirU.d.ts.map
|