bitgpu 0.19.1 → 0.19.2
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 +18 -5
- package/dist/chat.d.ts +21 -34
- package/dist/chat.js +1268 -418
- package/dist/chat.js.map +1 -1
- package/dist/gguf.d.ts +6 -11
- package/dist/gguf.js +1 -2
- package/dist/index.d.ts +5 -11
- package/dist/index.js +21 -26
- package/dist/index.js.map +1 -1
- package/dist/{types-CBW7T_3s.d.ts → types-_ie0s0iY.d.ts} +1 -4
- package/package.json +12 -12
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.19.
|
|
56
|
+
const REPO = 'https://cdn.jsdelivr.net/gh/stfurkan/bitgpu@v0.19.2/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`,
|
|
@@ -558,8 +558,9 @@ npm run test:27b # LIVE Bonsai-27B gate: streams the
|
|
|
558
558
|
|
|
559
559
|
Or serve the repo root (`python3 -m http.server 8000`) and open
|
|
560
560
|
`http://localhost:8000/examples/verify.html` in a WebGPU browser and click Run. Run this gate on
|
|
561
|
-
real hardware before every release
|
|
562
|
-
drafter, chat, packaging)
|
|
561
|
+
real hardware before every release. CI covers the CPU-checkable parts (types, sampler math,
|
|
562
|
+
drafter, chat, packaging) plus a real-GPU smoke job on the hosted Mac runners that runs the
|
|
563
|
+
two weight-free gates (test:kernels and test:hybrid); the full weighted gate above stays local. The headless driver also runs the baseline model once with
|
|
563
564
|
`?nosg=1` (the no-subgroup workgroup-reduction fallback used on Firefox and older adapters), so
|
|
564
565
|
that path is release-gated too - it is bit-identical to the subgroup path on the committed
|
|
565
566
|
known-good ids.
|
|
@@ -585,8 +586,20 @@ After the GPU gate passes locally: bump `version` in package.json, commit, then
|
|
|
585
586
|
git tag v0.1.1 && git push origin main v0.1.1
|
|
586
587
|
```
|
|
587
588
|
|
|
588
|
-
The release workflow
|
|
589
|
-
|
|
589
|
+
The release workflow then runs three jobs, each holding only the permission it needs:
|
|
590
|
+
|
|
591
|
+
1. `gpu-smoke` - the two weight-free real-GPU gates (`test:kernels`, `test:hybrid`) on a hosted
|
|
592
|
+
Mac runner, on the tagged commit.
|
|
593
|
+
2. `publish` - re-runs the CPU checks, verifies the tag matches the package version, and
|
|
594
|
+
publishes. It waits for `gpu-smoke` and for a reviewer's approval on the `npm-release`
|
|
595
|
+
environment (Actions tab -> the run -> Review deployments).
|
|
596
|
+
3. `github-release` - creates the matching GitHub Release.
|
|
597
|
+
|
|
598
|
+
To rehearse without publishing, run the workflow manually (Actions tab -> Release -> Run
|
|
599
|
+
workflow): it does everything except the publish and the GitHub Release. Actions are pinned to
|
|
600
|
+
commit SHAs (Dependabot opens the update PRs) and dependencies install with `--ignore-scripts`.
|
|
601
|
+
The npm Trusted Publisher entry is tied to this repo, the file name `release.yml` and the
|
|
602
|
+
`npm-release` environment - renaming any of them breaks publishing.
|
|
590
603
|
|
|
591
604
|
The WGSL kernels live in `shaders/` and are inlined into the bundle at build time (no runtime
|
|
592
605
|
`fetch`). `scripts/gen-shaders.ts` does the inlining.
|
package/dist/chat.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { c as KvSnapshot, m as TokenLogprobs, n as Engine, o as GenerateOptions } from "./types-
|
|
2
|
-
|
|
3
|
-
//#region src/chat/tokenizer.d.ts
|
|
1
|
+
import { c as KvSnapshot, m as TokenLogprobs, n as Engine, o as GenerateOptions } from "./types-_ie0s0iY.js";
|
|
4
2
|
interface ChatMessage {
|
|
5
3
|
role: 'system' | 'user' | 'assistant' | 'tool' | (string & {});
|
|
6
4
|
content: string;
|
|
@@ -20,7 +18,7 @@ interface DecoderStream {
|
|
|
20
18
|
push(tokenId: number): string;
|
|
21
19
|
flush(): string;
|
|
22
20
|
}
|
|
23
|
-
declare class ChatTokenizer {
|
|
21
|
+
export declare class ChatTokenizer {
|
|
24
22
|
private readonly tok;
|
|
25
23
|
private readonly template;
|
|
26
24
|
private readonly templateContext;
|
|
@@ -51,8 +49,6 @@ declare class ChatTokenizer {
|
|
|
51
49
|
}): string;
|
|
52
50
|
createDecoderStream(skipSpecialTokens?: boolean): DecoderStream;
|
|
53
51
|
}
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/chat/json.d.ts
|
|
56
52
|
/** The enforceable JSON Schema subset (see validateJsonSchema). */
|
|
57
53
|
interface JsonSchema {
|
|
58
54
|
type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
@@ -91,8 +87,8 @@ interface JsonSchema {
|
|
|
91
87
|
$id?: string;
|
|
92
88
|
}
|
|
93
89
|
/** Validate a schema against the enforceable subset; throws listing anything unsupported. */
|
|
94
|
-
declare function validateJsonSchema(schema: JsonSchema, path?: string, isRoot?: boolean): void;
|
|
95
|
-
declare class JsonMachine {
|
|
90
|
+
export declare function validateJsonSchema(schema: JsonSchema, path?: string, isRoot?: boolean): void;
|
|
91
|
+
export declare class JsonMachine {
|
|
96
92
|
private readonly root;
|
|
97
93
|
private stack;
|
|
98
94
|
private phase;
|
|
@@ -164,8 +160,6 @@ declare class TokenByteTable {
|
|
|
164
160
|
constructor(tk: TokenBytesSource);
|
|
165
161
|
bytes(id: number): Uint8Array | null;
|
|
166
162
|
}
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/chat/tools.d.ts
|
|
169
163
|
/** A tool declaration, in the shape Qwen-family models were trained on (and the shape the
|
|
170
164
|
* OpenAI/HF ecosystems use); the template serializes it verbatim into the system block. */
|
|
171
165
|
interface ChatTool {
|
|
@@ -196,8 +190,8 @@ type ToolChoice = 'auto' | 'none' | {
|
|
|
196
190
|
name: string;
|
|
197
191
|
};
|
|
198
192
|
/** Validate a tools list + choice; throws on anything the enforcer cannot guarantee. */
|
|
199
|
-
declare function validateTools(tools: readonly ChatTool[], choice: ToolChoice): void;
|
|
200
|
-
declare class ToolBodyMachine {
|
|
193
|
+
export declare function validateTools(tools: readonly ChatTool[], choice: ToolChoice): void;
|
|
194
|
+
export declare class ToolBodyMachine {
|
|
201
195
|
private readonly cands;
|
|
202
196
|
private readonly schemas;
|
|
203
197
|
private phase;
|
|
@@ -236,7 +230,7 @@ interface XmlToolProps {
|
|
|
236
230
|
/** byte-space property key -> that parameter's schema (used to pick the value grammar). */
|
|
237
231
|
schemas?: ReadonlyMap<string, JsonSchema>;
|
|
238
232
|
}
|
|
239
|
-
declare class ToolBodyMachineXml implements ToolBody {
|
|
233
|
+
export declare class ToolBodyMachineXml implements ToolBody {
|
|
240
234
|
private readonly cands;
|
|
241
235
|
private readonly props;
|
|
242
236
|
private phase;
|
|
@@ -285,14 +279,14 @@ interface PreparedTools {
|
|
|
285
279
|
* text again (another call, prose, or eos). Forced mode: the FIRST token must be <tool_call>,
|
|
286
280
|
* the body is constrained to the named tool, and after </tool_call> only eos is permitted.
|
|
287
281
|
* Call advance() with each emitted token to move the real machine. */
|
|
288
|
-
declare function makeToolFilter(table: TokenByteTable, prep: PreparedTools, startInThink?: boolean): {
|
|
282
|
+
export declare function makeToolFilter(table: TokenByteTable, prep: PreparedTools, startInThink?: boolean): {
|
|
289
283
|
filter: (ids: Uint32Array | number[]) => number[];
|
|
290
284
|
advance: (id: number) => void;
|
|
291
285
|
};
|
|
292
286
|
/** Stream-safe <tool_call> block extraction (the tool sibling of ThinkSplitter): visible text on
|
|
293
287
|
* one channel, each COMPLETED block's content as its own string, tags never surfacing anywhere.
|
|
294
288
|
* Tags can straddle token boundaries, so chunk edges hold back possible partial tags. */
|
|
295
|
-
declare class ToolCallSplitter {
|
|
289
|
+
export declare class ToolCallSplitter {
|
|
296
290
|
private readonly open;
|
|
297
291
|
private readonly close;
|
|
298
292
|
private inside;
|
|
@@ -313,21 +307,19 @@ declare class ToolCallSplitter {
|
|
|
313
307
|
}
|
|
314
308
|
/** Parse one block's content into a ToolCall. With enforcement on this cannot fail for a
|
|
315
309
|
* completed block; a failure (unenforced or truncated content) yields name '' and the raw text. */
|
|
316
|
-
declare function parseToolCall(raw: string): ToolCall;
|
|
310
|
+
export declare function parseToolCall(raw: string): ToolCall;
|
|
317
311
|
/** Parse one XML block's content into a ToolCall (the Qwen3.5 `<function=…><parameter=…>` protocol).
|
|
318
312
|
* Values are coerced by the tool's schema - string params keep their raw text, everything else is
|
|
319
313
|
* JSON.parse'd. Returns name '' if the block names an unknown tool/property, a required property is
|
|
320
314
|
* missing, or a non-string value is not valid JSON (so a surfaced call always conforms). */
|
|
321
|
-
declare function parseToolCallXml(raw: string, tools: readonly ChatTool[]): ToolCall;
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/chat/think.d.ts
|
|
315
|
+
export declare function parseToolCallXml(raw: string, tools: readonly ChatTool[]): ToolCall;
|
|
324
316
|
interface SplitChunk {
|
|
325
317
|
/** Visible reply text (outside any tag pair). */
|
|
326
318
|
text: string;
|
|
327
319
|
/** Content inside the tag pair (the model's reasoning), without the tags themselves. */
|
|
328
320
|
think: string;
|
|
329
321
|
}
|
|
330
|
-
declare class ThinkSplitter {
|
|
322
|
+
export declare class ThinkSplitter {
|
|
331
323
|
private readonly open;
|
|
332
324
|
private readonly close;
|
|
333
325
|
private inside;
|
|
@@ -335,7 +327,6 @@ declare class ThinkSplitter {
|
|
|
335
327
|
constructor(open?: string, close?: string,
|
|
336
328
|
/** Start already inside a think block - for templates whose generation prompt PRE-OPENS `<think>`
|
|
337
329
|
* (e.g. Qwen3.5 thinking mode), so the opening tag is in the prompt, not the generated stream. */
|
|
338
|
-
|
|
339
330
|
startInside?: boolean);
|
|
340
331
|
push(chunk: string): SplitChunk;
|
|
341
332
|
/** Emit whatever is held back. An unterminated think block (generation hit maxTokens inside it)
|
|
@@ -345,7 +336,7 @@ declare class ThinkSplitter {
|
|
|
345
336
|
/** Stream-safe stop-sequence scanner: emits visible text up to (excluding) the earliest match of
|
|
346
337
|
* any stop string, holding back chunk-edge suffixes that could begin one (stops can straddle
|
|
347
338
|
* token boundaries). Once matched, everything further is swallowed. */
|
|
348
|
-
declare class StopScanner {
|
|
339
|
+
export declare class StopScanner {
|
|
349
340
|
private readonly stops;
|
|
350
341
|
matched: boolean;
|
|
351
342
|
private hold;
|
|
@@ -373,7 +364,7 @@ interface ThinkEarlyStop {
|
|
|
373
364
|
* thinking-mode template. advance() must see every emitted token; observe() should see each
|
|
374
365
|
* step's candidate logits (descending) BEFORE the pick - the filter callback receives exactly
|
|
375
366
|
* that. */
|
|
376
|
-
declare class ThinkBudget {
|
|
367
|
+
export declare class ThinkBudget {
|
|
377
368
|
private readonly openId;
|
|
378
369
|
private readonly closeId;
|
|
379
370
|
private readonly budget;
|
|
@@ -394,12 +385,10 @@ declare class ThinkBudget {
|
|
|
394
385
|
/** The forced token id once the budget is exhausted or early stop fired, else null. */
|
|
395
386
|
force(): number | null;
|
|
396
387
|
}
|
|
397
|
-
//#endregion
|
|
398
|
-
//#region src/chat/index.d.ts
|
|
399
388
|
/** Options for {@link createChat}. Point it at the model directory (which already hosts
|
|
400
389
|
* tokenizer.json + tokenizer_config.json next to the manifest), at explicit URLs, or at
|
|
401
390
|
* preloaded JSON (bring your own caching, e.g. OPFS). */
|
|
402
|
-
interface ChatOptions {
|
|
391
|
+
export interface ChatOptions {
|
|
403
392
|
/** Directory holding tokenizer.json + tokenizer_config.json (usually the same modelUrl passed
|
|
404
393
|
* to createEngine). */
|
|
405
394
|
modelUrl?: string;
|
|
@@ -416,7 +405,7 @@ interface ChatOptions {
|
|
|
416
405
|
}
|
|
417
406
|
/** Per-turn options. Sampling fields pass through to the engine (same semantics as
|
|
418
407
|
* {@link GenerateOptions}); the rest control the chat layer. */
|
|
419
|
-
interface ChatSendOptions {
|
|
408
|
+
export interface ChatSendOptions {
|
|
420
409
|
maxTokens?: number;
|
|
421
410
|
temperature?: number;
|
|
422
411
|
topK?: number;
|
|
@@ -514,7 +503,7 @@ interface ChatSendOptions {
|
|
|
514
503
|
};
|
|
515
504
|
};
|
|
516
505
|
}
|
|
517
|
-
interface ChatResult {
|
|
506
|
+
export interface ChatResult {
|
|
518
507
|
/** The visible reply (think blocks and tool_call blocks removed). */
|
|
519
508
|
text: string;
|
|
520
509
|
/** Content of <think> blocks, when the model emitted any. */
|
|
@@ -541,7 +530,7 @@ interface ChatResult {
|
|
|
541
530
|
* chat-layer bookkeeping that makes cache reuse safe. Structured-cloneable (store in
|
|
542
531
|
* IndexedDB / OPFS or postMessage as-is; NOT `JSON.stringify`-able - the KV buffer would be
|
|
543
532
|
* lost). Treat the fields as opaque. */
|
|
544
|
-
interface ChatSnapshot {
|
|
533
|
+
export interface ChatSnapshot {
|
|
545
534
|
/** Snapshot format version (currently `1`). */
|
|
546
535
|
version: 1;
|
|
547
536
|
/** The engine-level KV cache + token history snapshot. */
|
|
@@ -553,7 +542,7 @@ interface ChatSnapshot {
|
|
|
553
542
|
/** Canonical JSON of the tools list the conversation was rendered with (null = no tools). */
|
|
554
543
|
toolsKey: string | null;
|
|
555
544
|
}
|
|
556
|
-
interface Chat {
|
|
545
|
+
export interface Chat {
|
|
557
546
|
/** Generate a reply for the message list. Resolves with the full result; stream text via
|
|
558
547
|
* `onText`. Turns are serialized: overlapping calls queue instead of interleaving. */
|
|
559
548
|
send(messages: ChatMessage[], options?: ChatSendOptions): Promise<ChatResult>;
|
|
@@ -601,7 +590,5 @@ interface Chat {
|
|
|
601
590
|
readonly tokenizer: ChatTokenizer;
|
|
602
591
|
}
|
|
603
592
|
/** Load the tokenizer files and return a {@link Chat} bound to the engine. */
|
|
604
|
-
declare function createChat(engine: Engine, options: ChatOptions): Promise<Chat>;
|
|
605
|
-
|
|
606
|
-
export { Chat, type ChatMessage, ChatOptions, ChatResult, ChatSendOptions, ChatSnapshot, ChatTokenizer, type ChatTool, type DecoderStream, JsonMachine, type JsonSchema, StopScanner, ThinkBudget, ThinkSplitter, ToolBodyMachine, ToolBodyMachineXml, type ToolCall, ToolCallSplitter, type ToolChoice, createChat, makeToolFilter, parseToolCall, parseToolCallXml, validateJsonSchema, validateTools };
|
|
607
|
-
//# sourceMappingURL=chat.d.ts.map
|
|
593
|
+
export declare function createChat(engine: Engine, options: ChatOptions): Promise<Chat>;
|
|
594
|
+
export type { ChatMessage, ChatTool, DecoderStream, JsonSchema, ToolCall, ToolChoice };
|