bitgpu 0.19.0 → 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 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.0/models/bonsai-1.7b-gguf'
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; CI covers only the CPU-checkable parts (types, sampler math,
562
- drafter, chat, packaging). The headless driver also runs the baseline model once with
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 re-runs the CPU checks, verifies the tag matches the package version, and
589
- publishes.
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-CBW7T_3s.js";
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;
@@ -246,6 +240,8 @@ declare class ToolBodyMachineXml implements ToolBody {
246
240
  private elem;
247
241
  private keyBuf;
248
242
  private keyCands;
243
+ private declared;
244
+ private valWs;
249
245
  private reqLeft;
250
246
  private valTail;
251
247
  private valStarted;
@@ -283,14 +279,14 @@ interface PreparedTools {
283
279
  * text again (another call, prose, or eos). Forced mode: the FIRST token must be <tool_call>,
284
280
  * the body is constrained to the named tool, and after </tool_call> only eos is permitted.
285
281
  * Call advance() with each emitted token to move the real machine. */
286
- declare function makeToolFilter(table: TokenByteTable, prep: PreparedTools, startInThink?: boolean): {
282
+ export declare function makeToolFilter(table: TokenByteTable, prep: PreparedTools, startInThink?: boolean): {
287
283
  filter: (ids: Uint32Array | number[]) => number[];
288
284
  advance: (id: number) => void;
289
285
  };
290
286
  /** Stream-safe <tool_call> block extraction (the tool sibling of ThinkSplitter): visible text on
291
287
  * one channel, each COMPLETED block's content as its own string, tags never surfacing anywhere.
292
288
  * Tags can straddle token boundaries, so chunk edges hold back possible partial tags. */
293
- declare class ToolCallSplitter {
289
+ export declare class ToolCallSplitter {
294
290
  private readonly open;
295
291
  private readonly close;
296
292
  private inside;
@@ -311,21 +307,19 @@ declare class ToolCallSplitter {
311
307
  }
312
308
  /** Parse one block's content into a ToolCall. With enforcement on this cannot fail for a
313
309
  * completed block; a failure (unenforced or truncated content) yields name '' and the raw text. */
314
- declare function parseToolCall(raw: string): ToolCall;
310
+ export declare function parseToolCall(raw: string): ToolCall;
315
311
  /** Parse one XML block's content into a ToolCall (the Qwen3.5 `<function=…><parameter=…>` protocol).
316
312
  * Values are coerced by the tool's schema - string params keep their raw text, everything else is
317
313
  * JSON.parse'd. Returns name '' if the block names an unknown tool/property, a required property is
318
314
  * missing, or a non-string value is not valid JSON (so a surfaced call always conforms). */
319
- declare function parseToolCallXml(raw: string, tools: readonly ChatTool[]): ToolCall;
320
- //#endregion
321
- //#region src/chat/think.d.ts
315
+ export declare function parseToolCallXml(raw: string, tools: readonly ChatTool[]): ToolCall;
322
316
  interface SplitChunk {
323
317
  /** Visible reply text (outside any tag pair). */
324
318
  text: string;
325
319
  /** Content inside the tag pair (the model's reasoning), without the tags themselves. */
326
320
  think: string;
327
321
  }
328
- declare class ThinkSplitter {
322
+ export declare class ThinkSplitter {
329
323
  private readonly open;
330
324
  private readonly close;
331
325
  private inside;
@@ -333,7 +327,6 @@ declare class ThinkSplitter {
333
327
  constructor(open?: string, close?: string,
334
328
  /** Start already inside a think block - for templates whose generation prompt PRE-OPENS `<think>`
335
329
  * (e.g. Qwen3.5 thinking mode), so the opening tag is in the prompt, not the generated stream. */
336
-
337
330
  startInside?: boolean);
338
331
  push(chunk: string): SplitChunk;
339
332
  /** Emit whatever is held back. An unterminated think block (generation hit maxTokens inside it)
@@ -343,7 +336,7 @@ declare class ThinkSplitter {
343
336
  /** Stream-safe stop-sequence scanner: emits visible text up to (excluding) the earliest match of
344
337
  * any stop string, holding back chunk-edge suffixes that could begin one (stops can straddle
345
338
  * token boundaries). Once matched, everything further is swallowed. */
346
- declare class StopScanner {
339
+ export declare class StopScanner {
347
340
  private readonly stops;
348
341
  matched: boolean;
349
342
  private hold;
@@ -371,7 +364,7 @@ interface ThinkEarlyStop {
371
364
  * thinking-mode template. advance() must see every emitted token; observe() should see each
372
365
  * step's candidate logits (descending) BEFORE the pick - the filter callback receives exactly
373
366
  * that. */
374
- declare class ThinkBudget {
367
+ export declare class ThinkBudget {
375
368
  private readonly openId;
376
369
  private readonly closeId;
377
370
  private readonly budget;
@@ -381,19 +374,21 @@ declare class ThinkBudget {
381
374
  private closed;
382
375
  private run;
383
376
  private earlyFired;
377
+ private seen;
384
378
  constructor(openId: number | undefined, closeId: number | undefined, budget: number, startInside: boolean, early?: ThinkEarlyStop | null);
385
379
  advance(id: number): void;
386
- /** Feed one step's candidate logits (descending). Only meaningful inside think. */
380
+ /** Feed one step's candidate logits (descending). Only meaningful inside think. Counted at most
381
+ * once per emitted step: the engine re-invokes the candidate filter (and thus observe) once per
382
+ * 512-token batch when it has to walk the full vocabulary for a forced token, and those
383
+ * batch-local gaps must not eat the early-stop window. */
387
384
  observe(vals: ArrayLike<number>): void;
388
385
  /** The forced token id once the budget is exhausted or early stop fired, else null. */
389
386
  force(): number | null;
390
387
  }
391
- //#endregion
392
- //#region src/chat/index.d.ts
393
388
  /** Options for {@link createChat}. Point it at the model directory (which already hosts
394
389
  * tokenizer.json + tokenizer_config.json next to the manifest), at explicit URLs, or at
395
390
  * preloaded JSON (bring your own caching, e.g. OPFS). */
396
- interface ChatOptions {
391
+ export interface ChatOptions {
397
392
  /** Directory holding tokenizer.json + tokenizer_config.json (usually the same modelUrl passed
398
393
  * to createEngine). */
399
394
  modelUrl?: string;
@@ -410,7 +405,7 @@ interface ChatOptions {
410
405
  }
411
406
  /** Per-turn options. Sampling fields pass through to the engine (same semantics as
412
407
  * {@link GenerateOptions}); the rest control the chat layer. */
413
- interface ChatSendOptions {
408
+ export interface ChatSendOptions {
414
409
  maxTokens?: number;
415
410
  temperature?: number;
416
411
  topK?: number;
@@ -508,7 +503,7 @@ interface ChatSendOptions {
508
503
  };
509
504
  };
510
505
  }
511
- interface ChatResult {
506
+ export interface ChatResult {
512
507
  /** The visible reply (think blocks and tool_call blocks removed). */
513
508
  text: string;
514
509
  /** Content of <think> blocks, when the model emitted any. */
@@ -535,7 +530,7 @@ interface ChatResult {
535
530
  * chat-layer bookkeeping that makes cache reuse safe. Structured-cloneable (store in
536
531
  * IndexedDB / OPFS or postMessage as-is; NOT `JSON.stringify`-able - the KV buffer would be
537
532
  * lost). Treat the fields as opaque. */
538
- interface ChatSnapshot {
533
+ export interface ChatSnapshot {
539
534
  /** Snapshot format version (currently `1`). */
540
535
  version: 1;
541
536
  /** The engine-level KV cache + token history snapshot. */
@@ -547,7 +542,7 @@ interface ChatSnapshot {
547
542
  /** Canonical JSON of the tools list the conversation was rendered with (null = no tools). */
548
543
  toolsKey: string | null;
549
544
  }
550
- interface Chat {
545
+ export interface Chat {
551
546
  /** Generate a reply for the message list. Resolves with the full result; stream text via
552
547
  * `onText`. Turns are serialized: overlapping calls queue instead of interleaving. */
553
548
  send(messages: ChatMessage[], options?: ChatSendOptions): Promise<ChatResult>;
@@ -595,7 +590,5 @@ interface Chat {
595
590
  readonly tokenizer: ChatTokenizer;
596
591
  }
597
592
  /** Load the tokenizer files and return a {@link Chat} bound to the engine. */
598
- declare function createChat(engine: Engine, options: ChatOptions): Promise<Chat>;
599
- //#endregion
600
- 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 };
601
- //# 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 };