webslm 0.4.1 → 0.5.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 CHANGED
@@ -273,15 +273,17 @@ await engine.terminate();
273
273
 
274
274
  ```ts
275
275
  type ModelSource =
276
- | { hub: string; revision?: string; hubUrl?: string } // a plain string is a hub repo id
277
- | { files: Record<string, Blob | ArrayBuffer | Uint8Array> } // "config.json", "tokenizer.json", "model.safetensors"...
278
- | { fetch: (path: string, range?: [number, number]) => Promise<ArrayBuffer | Uint8Array | null> };
276
+ | { hub: string; revision?: string; hubUrl?: string; file?: string } // a plain string is a hub repo id
277
+ | { files: Record<string, Blob | ArrayBuffer | Uint8Array>; file?: string } // "config.json", "tokenizer.json", "model.safetensors", "model.gguf"...
278
+ | { fetch: (path: string, range?: [number, number]) => Promise<ArrayBuffer | Uint8Array | null>; file?: string };
279
279
  ```
280
280
 
281
281
  - **Hub**: the revision (default `main`) is resolved to a commit sha, every needed file is downloaded fully into the cache under `webslm/{repo}/{sha}/`, and the engine reads ranges from there. A later load of the same revision makes no request at all; delete the cached model (or pass a newer revision) to pick up new commits. Pass `token` in the options for gated or private repositories; it is only sent to `hubUrl`.
282
282
  - **Files**: bytes the page already holds (an upload, IndexedDB, a training job's output).
283
283
  - **Fetch**: a custom store. `range` is `[start, end)`. Return `null` for a missing file: optional files such as `generation_config.json` are probed.
284
284
 
285
+ `file` names a GGUF file of the source to load instead of safetensors weights, e.g. `{ hub: "bartowski/SmolLM2-135M-Instruct-GGUF", file: "SmolLM2-135M-Instruct-Q8_0.gguf" }`: only that file (and the repository's tokenizer files, if any) is downloaded, its metadata gives the configuration, the tokenizer (unless a `tokenizer.json` sits next to it) and the chat template. A hub repository or `files` holding GGUF files and no safetensors loads its preferred GGUF file (Q8_0, else Q4_K_M, Q4_0...) without `file`; a `fetch` source needs it. A GGUF source loads in the format of its matrices unless `quant` says otherwise: a Q8_0 file runs as Q8_0 with its blocks unchanged. Checkpoints written by `webslm export --quant q8` (Q8_0 matrices stored as an `I8` and an `F16` tensor each) load the same way, at Q8_0 size. See [GGUF and pre-quantized checkpoints](../../README.md#gguf-and-pre-quantized-checkpoints) for the tensor types and architectures. `searchModels` lists GGUF repositories of supported architectures (`gguf: true`).
286
+
285
287
  `model.info()` lists every file read with its SHA-256, so an application can check what it runs.
286
288
 
287
289
  ## LoRA adapters
@@ -428,7 +430,7 @@ export default defineConfig({
428
430
  });
429
431
  ```
430
432
 
431
- Server code that imports webslm must not be bundled: webslm runs from its own files in `node_modules` (Next.js: `serverExternalPackages: ["webslm"]`). Without a bundler, a page can import it from jsDelivr (`https://cdn.jsdelivr.net/npm/webslm@0.4.1/dist/index.js`); webslm starts its workers through same-origin `blob:` workers when its files come from another origin. Guides for Next.js, Vite, webpack, Node servers, Bun, Deno and CDNs, each with a tested example: <https://github.com/maxgfr/webslm#frameworks-bundlers-and-runtimes>.
433
+ Server code that imports webslm must not be bundled: webslm runs from its own files in `node_modules` (Next.js: `serverExternalPackages: ["webslm"]`). Without a bundler, a page can import it from jsDelivr (`https://cdn.jsdelivr.net/npm/webslm@0.5.0/dist/index.js`); webslm starts its workers through same-origin `blob:` workers when its files come from another origin. Guides for Next.js, Vite, webpack, Node servers, Bun, Deno and CDNs, each with a tested example: <https://github.com/maxgfr/webslm#frameworks-bundlers-and-runtimes>.
432
434
 
433
435
  ## Errors
434
436
 
@@ -83,9 +83,10 @@ export declare function writeManifest(store: CacheStore, manifest: CacheManifest
83
83
  */
84
84
  export declare function readCliManifest(store: CacheStore, repo: string, sha: string): Promise<CacheManifest | undefined>;
85
85
  /**
86
- * Writes the command-line tool's manifest of a complete snapshot, unless it
87
- * has one, so that `webslm` (the command-line tool) uses the files without
88
- * pulling them again.
86
+ * Writes the command-line tool's manifest of a complete snapshot, so that
87
+ * `webslm` (the command-line tool) uses the files without pulling them
88
+ * again. A manifest it already has keeps its entries and gains the files it
89
+ * lacks (another GGUF file of the same commit).
89
90
  */
90
91
  export declare function writeCliManifest(store: CacheStore, manifest: CacheManifest, revision: string): Promise<void>;
91
92
  /** Every cached repository of `store`. */
@@ -121,25 +121,38 @@ export async function readCliManifest(store, repo, sha) {
121
121
  return { version: 1, repo, sha, files, complete: true, updatedAt: new Date(created).toISOString() };
122
122
  }
123
123
  /**
124
- * Writes the command-line tool's manifest of a complete snapshot, unless it
125
- * has one, so that `webslm` (the command-line tool) uses the files without
126
- * pulling them again.
124
+ * Writes the command-line tool's manifest of a complete snapshot, so that
125
+ * `webslm` (the command-line tool) uses the files without pulling them
126
+ * again. A manifest it already has keeps its entries and gains the files it
127
+ * lacks (another GGUF file of the same commit).
127
128
  */
128
129
  export async function writeCliManifest(store, manifest, revision) {
130
+ if (!manifest.complete)
131
+ return;
129
132
  const path = cliManifestPath(manifest.repo, manifest.sha);
130
- if (!manifest.complete || (await store.size(path)) !== undefined)
133
+ let existing;
134
+ if ((await store.size(path)) !== undefined) {
135
+ try {
136
+ existing = JSON.parse((await readText(store, path)) ?? "");
137
+ }
138
+ catch {
139
+ return; // not ours to repair
140
+ }
141
+ if (!Array.isArray(existing?.files))
142
+ return;
143
+ }
144
+ const known = new Set((existing?.files ?? []).map((f) => f.name));
145
+ const added = Object.entries(manifest.files)
146
+ .filter(([name]) => !known.has(name))
147
+ .map(([name, info]) => ({ name, size: info.size, sha256: info.sha256 ?? null, blob_id: null }));
148
+ if (existing !== undefined && added.length === 0)
131
149
  return;
132
150
  const cli = {
133
151
  repo: manifest.repo,
134
- revision,
152
+ revision: existing?.revision ?? revision,
135
153
  sha: manifest.sha,
136
- files: Object.entries(manifest.files).map(([name, info]) => ({
137
- name,
138
- size: info.size,
139
- sha256: info.sha256 ?? null,
140
- blob_id: null,
141
- })),
142
- created_unix: Math.floor(Date.now() / 1000),
154
+ files: [...(existing?.files ?? []), ...added],
155
+ created_unix: existing?.created_unix ?? Math.floor(Date.now() / 1000),
143
156
  };
144
157
  await writeText(store, path, JSON.stringify(cli, null, 2));
145
158
  }
@@ -30,6 +30,11 @@ export interface HubDownloadOptions extends HubOptions {
30
30
  readonly retries?: number;
31
31
  /** Minimum delay between two progress events of the same file, in ms (default 50). */
32
32
  readonly progressIntervalMs?: number;
33
+ /**
34
+ * A GGUF file of the repository to download as the weights (a repository
35
+ * without safetensors weights gets its preferred one anyway).
36
+ */
37
+ readonly file?: string;
33
38
  }
34
39
  /** A checkpoint ready to be read from the cache. */
35
40
  export interface CachedCheckpoint {
package/dist/download.js CHANGED
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import { checkRepoId, filePath, readCliManifest, readManifest, readRef, writeCliManifest, writeManifest, writeRef, } from "./cache/models.js";
16
16
  import { WebslmError, abortError, isAborted, toWebslmError } from "./errors.js";
17
- import { SAFETENSORS_INDEX, fetchRevision, fileUrl, hubFetch, isAdapterListing, selectCheckpointFiles, } from "./hub.js";
17
+ import { SAFETENSORS_INDEX, fetchRevision, fileUrl, hubFetch, isAdapterListing, isGgufFile, selectCheckpointFiles, } from "./hub.js";
18
18
  const SHA_PATTERN = /^[0-9a-f]{40}$/;
19
19
  /** Makes `repo@revision` available in `options.store` and returns a reader over it. */
20
20
  export async function prepareHubCheckpoint(repoId, revision, options) {
@@ -26,10 +26,12 @@ export async function prepareHubCheckpoint(repoId, revision, options) {
26
26
  const knownSha = SHA_PATTERN.test(rev) ? rev : await readRef(store, repo, rev);
27
27
  if (knownSha !== undefined) {
28
28
  const ours = await readManifest(store, repo, knownSha);
29
- const manifest = ours?.complete === true && (await filesPresent(store, ours))
29
+ // A named GGUF file must be in the snapshot (another one may be).
30
+ const holds = (m) => options.file === undefined || m?.files[options.file] !== undefined;
31
+ const manifest = ours?.complete === true && holds(ours) && (await filesPresent(store, ours))
30
32
  ? ours
31
33
  : await readCliManifest(store, repo, knownSha);
32
- if (manifest !== undefined) {
34
+ if (manifest !== undefined && holds(manifest)) {
33
35
  await shareWithCli(store, manifest, rev);
34
36
  emitCachedProgress(manifest, emit);
35
37
  return reader(store, manifest, true);
@@ -82,11 +84,14 @@ export async function prepareHubCheckpoint(repoId, revision, options) {
82
84
  throw new WebslmError("INVALID_CHECKPOINT", `invalid ${SAFETENSORS_INDEX}`, { cause: error });
83
85
  }
84
86
  }
85
- const selected = selectCheckpointFiles(names, index);
87
+ const selected = selectCheckpointFiles(names, index, options.file);
86
88
  if (selected.weights.length === 0) {
87
- throw new WebslmError("UNSUPPORTED_MODEL", `${repo}@${rev} has no safetensors weights`);
89
+ throw new WebslmError("UNSUPPORTED_MODEL", options.file === undefined
90
+ ? `${repo}@${rev} has no safetensors weights or GGUF files`
91
+ : `${repo}@${rev} has no ${options.file}`);
88
92
  }
89
- if (!names.includes("config.json") && !isAdapterListing(names)) {
93
+ const ggufWeights = selected.weights.some(isGgufFile);
94
+ if (!names.includes("config.json") && !isAdapterListing(names) && !ggufWeights) {
90
95
  throw new WebslmError("INVALID_CHECKPOINT", `${repo}@${rev} has no config.json`);
91
96
  }
92
97
  const files = [...selected.side, ...(selected.index ? [selected.index] : []), ...selected.weights];
package/dist/engine.js CHANGED
@@ -19,7 +19,21 @@ import { openStore } from "./cache/index.js";
19
19
  import { weightCachePath } from "./cache/models.js";
20
20
  import { prepareHubCheckpoint } from "./download.js";
21
21
  import { WebslmError, abortError, deserializeError, serializeError } from "./errors.js";
22
- import { SAFETENSORS_INDEX } from "./hub.js";
22
+ import { SAFETENSORS_INDEX, isGgufFile, pickGgufFile } from "./hub.js";
23
+ /** Whether a read is of the weights (safetensors or GGUF), for progress. */
24
+ function isWeightFile(path) {
25
+ return (path.endsWith(".safetensors") && path !== SAFETENSORS_INDEX) || isGgufFile(path);
26
+ }
27
+ /**
28
+ * The GGUF file a source loads: the one it names, else the preferred one of
29
+ * a file list without safetensors weights (a GGUF repository).
30
+ */
31
+ function ggufFileOf(source, opened) {
32
+ if (source.file !== undefined)
33
+ return source.file;
34
+ const list = opened.list ?? [];
35
+ return list.some((f) => f.endsWith(".safetensors")) ? undefined : pickGgufFile(list);
36
+ }
23
37
  import { scoreTransferables } from "./protocol.js";
24
38
  import { installNodeWebWorker, nodePoolAvailable } from "./node-web-worker.js";
25
39
  import { installPoolWorkerFactory } from "./pool.js";
@@ -342,7 +356,10 @@ export class Engine {
342
356
  ...(source.hubUrl === undefined ? {} : { hubUrl: source.hubUrl }),
343
357
  ...(source.token === undefined ? {} : { token: source.token }),
344
358
  };
345
- const checkpoint = await prepareHubCheckpoint(source.repo, source.revision, hubOptions);
359
+ const checkpoint = await prepareHubCheckpoint(source.repo, source.revision, {
360
+ ...hubOptions,
361
+ ...(source.file === undefined ? {} : { file: source.file }),
362
+ });
346
363
  for (const [file, info] of Object.entries(checkpoint.info)) {
347
364
  sizes.set(file, info.size);
348
365
  if (info.sha256 !== undefined)
@@ -392,7 +409,7 @@ export class Engine {
392
409
  * signal and reports the weight bytes read as the `"load"` phase.
393
410
  */
394
411
  #jsSource(opened, active, progress, bindings) {
395
- const weightFiles = (opened.list ?? []).filter((f) => f.endsWith(".safetensors"));
412
+ const weightFiles = (opened.list ?? []).filter(isWeightFile);
396
413
  const weightTotal = weightFiles.reduce((n, f) => n + (opened.sizes.get(f) ?? 0), 0);
397
414
  let weightRead = 0;
398
415
  let lastReport = 0;
@@ -400,7 +417,7 @@ export class Engine {
400
417
  if (active.signal.aborted)
401
418
  throw abortError(active.signal);
402
419
  const bytes = await opened.read(path, start, end);
403
- if (bytes !== null && path.endsWith(".safetensors") && path !== SAFETENSORS_INDEX) {
420
+ if (bytes !== null && isWeightFile(path)) {
404
421
  weightRead += bytes.length;
405
422
  const t = now();
406
423
  if (t - lastReport > 50) {
@@ -504,7 +521,7 @@ export class Engine {
504
521
  const adapter = adapterSource === undefined
505
522
  ? undefined
506
523
  : await this.#openSource(active, adapterSource, options.cacheDir, progress, createHasher, "adapter");
507
- return this.#loadNative(native.addon, opened, adapter, options, active, started, progress);
524
+ return this.#loadNative(native.addon, opened, adapter, options, active, started, progress, ggufFileOf(source, opened));
508
525
  }
509
526
  const engine = await initEngineWasm({
510
527
  ...(options.wasmFlavour === undefined ? {} : { flavour: options.wasmFlavour }),
@@ -517,11 +534,16 @@ export class Engine {
517
534
  ? undefined
518
535
  : await this.#openSource(active, adapterSource, options.cacheDir, progress, wasmHasher, "adapter");
519
536
  const { source: jsSource, weightTotal } = this.#jsSource(opened, active, progress, engine.bindings);
520
- const weightCache = await this.#openWeightCache(opened, options, progress, engine.bindings);
537
+ const gguf = ggufFileOf(source, opened);
538
+ // A GGUF file usually holds its weights in the format they load in: no
539
+ // converted-weight cache (whose files are keyed by repository).
540
+ const weightCache = gguf === undefined ? await this.#openWeightCache(opened, options, progress, engine.bindings) : undefined;
521
541
  let wasm;
522
542
  try {
523
543
  wasm = await WasmModel.load(jsSource, JSON.stringify({
524
- format: options.quant,
544
+ // `auto` on a GGUF file: the engine keeps the file's own format.
545
+ ...(options.quant === "auto" ? {} : { format: options.quant }),
546
+ ...(gguf === undefined ? {} : { ggufFile: gguf }),
525
547
  device: options.device ?? "auto",
526
548
  ...(options.contextLength === undefined ? {} : { contextLength: options.contextLength }),
527
549
  ...(options.deterministic === true ? { deterministic: true } : {}),
@@ -604,10 +626,13 @@ export class Engine {
604
626
  * the download wrote (the command-line tool's layout), with its
605
627
  * converted-weight cache next to it.
606
628
  */
607
- async #loadNative(addon, opened, adapter, options, active, started, progress) {
608
- const dir = await snapshotDirectory(opened);
609
- if (dir === undefined)
629
+ async #loadNative(addon, opened, adapter, options, active, started, progress, gguf) {
630
+ const snapshot = await snapshotDirectory(opened);
631
+ if (snapshot === undefined) {
610
632
  throw new WebslmError("ENGINE", "the native engine needs the model in the cache directory");
633
+ }
634
+ // A GGUF file is loaded by its path (its directory holds the tokenizer files).
635
+ const dir = gguf === undefined ? snapshot : await joinFsPath(snapshot, gguf);
611
636
  // Block-quantized weights only, as the WebAssembly engine keeps them
612
637
  // (float formats convert quickly).
613
638
  const cache = options.weightCache !== false &&
@@ -615,11 +640,16 @@ export class Engine {
615
640
  (options.autoQuant === true || options.quant !== "f32") &&
616
641
  opened.repo !== undefined &&
617
642
  opened.revision !== undefined
618
- ? { weightCacheDir: await joinFsPath(dir, "quantized"), weightCacheKey: `${opened.repo}@${opened.revision}` }
643
+ ? gguf === undefined
644
+ ? { weightCacheDir: await joinFsPath(dir, "quantized"), weightCacheKey: `${opened.repo}@${opened.revision}` }
645
+ : {
646
+ weightCacheDir: await joinFsPath(snapshot, "quantized", gguf),
647
+ weightCacheKey: `${opened.repo}@${opened.revision}/${gguf}`,
648
+ }
619
649
  : {};
620
650
  const adapterDir = adapter === undefined ? undefined : await adapterDirectory(adapter);
621
651
  const weightTotal = [...opened.sizes]
622
- .filter(([file]) => file.endsWith(".safetensors"))
652
+ .filter(([file]) => isWeightFile(file))
623
653
  .reduce((n, [, size]) => n + size, 0);
624
654
  progress({ phase: "load", loadedBytes: 0, totalBytes: weightTotal, overallLoadedBytes: 0, overallTotalBytes: weightTotal });
625
655
  let model;
package/dist/hub.d.ts CHANGED
@@ -16,6 +16,19 @@ export declare const SUPPORTED_MODEL_TYPES: readonly string[];
16
16
  export declare const CHECKPOINT_SIDE_FILES: readonly string[];
17
17
  export declare const SAFETENSORS_INDEX = "model.safetensors.index.json";
18
18
  export declare const SAFETENSORS_SINGLE = "model.safetensors";
19
+ /**
20
+ * GGUF architectures the engine runs (`general.architecture`), with the
21
+ * `model_type` each runs as.
22
+ */
23
+ export declare const GGUF_ARCHITECTURES: Readonly<Record<string, string>>;
24
+ /** Whether `name` is a GGUF file. */
25
+ export declare function isGgufFile(name: string): boolean;
26
+ /**
27
+ * The GGUF file a repository runs when none is named: Q8_0, else Q4_K_M,
28
+ * Q4_0, Q4_K_S, F16, BF16, else the first by name (split files and
29
+ * multimodal projectors left out). The engine's `pick_gguf`.
30
+ */
31
+ export declare function pickGgufFile(names: readonly string[]): string | undefined;
19
32
  /** Configuration of a PEFT LoRA adapter. */
20
33
  export declare const ADAPTER_CONFIG = "adapter_config.json";
21
34
  /** Weights of a PEFT LoRA adapter. */
@@ -76,10 +89,12 @@ export declare function fetchRevision(repo: string, revision: string, options?:
76
89
  * Picks the files to download: the side files the repository has, plus the
77
90
  * weights (the shards named by the index, `model.safetensors`, or every
78
91
  * top-level `*.safetensors`). `index` is the parsed index when there is one.
92
+ * With `gguf`, or for a repository without safetensors weights, the weights
93
+ * are one GGUF file ({@link pickGgufFile}).
79
94
  */
80
95
  export declare function selectCheckpointFiles(names: readonly string[], index?: {
81
96
  weight_map?: Record<string, string>;
82
- }): {
97
+ }, gguf?: string): {
83
98
  side: string[];
84
99
  weights: string[];
85
100
  index?: string;
@@ -102,8 +117,13 @@ export interface HubModel {
102
117
  };
103
118
  /** Whether a token with accepted terms is needed to download it. */
104
119
  readonly gated: false | "auto" | "manual";
105
- /** Whether webslm can run it (architecture supported, safetensors weights, under `maxParams`). */
120
+ /**
121
+ * Whether webslm can run it (architecture supported, safetensors weights
122
+ * or GGUF files, under `maxParams`).
123
+ */
106
124
  readonly supported: boolean;
125
+ /** Whether it runs from its GGUF files (their architecture is supported). */
126
+ readonly gguf?: boolean;
107
127
  /** Why it is not supported. */
108
128
  readonly reason?: string;
109
129
  readonly downloads?: number;
package/dist/hub.js CHANGED
@@ -33,6 +33,39 @@ export const CHECKPOINT_SIDE_FILES = [
33
33
  ];
34
34
  export const SAFETENSORS_INDEX = "model.safetensors.index.json";
35
35
  export const SAFETENSORS_SINGLE = "model.safetensors";
36
+ /**
37
+ * GGUF architectures the engine runs (`general.architecture`), with the
38
+ * `model_type` each runs as.
39
+ */
40
+ export const GGUF_ARCHITECTURES = {
41
+ llama: "llama",
42
+ qwen2: "qwen2",
43
+ qwen3: "qwen3",
44
+ lfm2: "lfm2",
45
+ };
46
+ /** Whether `name` is a GGUF file. */
47
+ export function isGgufFile(name) {
48
+ return name.toLowerCase().endsWith(".gguf");
49
+ }
50
+ /**
51
+ * The GGUF file a repository runs when none is named: Q8_0, else Q4_K_M,
52
+ * Q4_0, Q4_K_S, F16, BF16, else the first by name (split files and
53
+ * multimodal projectors left out). The engine's `pick_gguf`.
54
+ */
55
+ export function pickGgufFile(names) {
56
+ const candidates = names
57
+ .filter((n) => {
58
+ const lower = n.toLowerCase();
59
+ return isGgufFile(n) && !n.includes("/") && !lower.includes("mmproj") && !lower.includes("-of-0");
60
+ })
61
+ .sort();
62
+ for (const preferred of ["q8_0", "q4_k_m", "q4_0", "q4_k_s", "f16", "bf16"]) {
63
+ const found = candidates.find((n) => n.toLowerCase().includes(preferred));
64
+ if (found !== undefined)
65
+ return found;
66
+ }
67
+ return candidates[0];
68
+ }
36
69
  /** Configuration of a PEFT LoRA adapter. */
37
70
  export const ADAPTER_CONFIG = "adapter_config.json";
38
71
  /** Weights of a PEFT LoRA adapter. */
@@ -156,13 +189,19 @@ function parseGated(value) {
156
189
  * Picks the files to download: the side files the repository has, plus the
157
190
  * weights (the shards named by the index, `model.safetensors`, or every
158
191
  * top-level `*.safetensors`). `index` is the parsed index when there is one.
192
+ * With `gguf`, or for a repository without safetensors weights, the weights
193
+ * are one GGUF file ({@link pickGgufFile}).
159
194
  */
160
- export function selectCheckpointFiles(names, index) {
195
+ export function selectCheckpointFiles(names, index, gguf) {
161
196
  // A LoRA adapter needs only its two files.
162
197
  if (isAdapterListing(names))
163
198
  return { side: [ADAPTER_CONFIG], weights: [ADAPTER_WEIGHTS] };
164
199
  const present = new Set(names);
165
200
  const side = CHECKPOINT_SIDE_FILES.filter((f) => present.has(f));
201
+ const hasSafetensors = present.has(SAFETENSORS_INDEX) || names.some((n) => !n.includes("/") && n.endsWith(".safetensors"));
202
+ const ggufFile = gguf ?? (hasSafetensors ? undefined : pickGgufFile(names));
203
+ if (ggufFile !== undefined)
204
+ return { side, weights: present.has(ggufFile) ? [ggufFile] : [] };
166
205
  if (present.has(SAFETENSORS_INDEX) && index !== undefined) {
167
206
  const weights = [...new Set(Object.values(index.weight_map ?? {}))].sort();
168
207
  return { side, weights, index: SAFETENSORS_INDEX };
@@ -258,7 +297,7 @@ export async function searchModels(query, options = {}) {
258
297
  const maxParams = options.maxParams ?? 2e9;
259
298
  const limit = Math.max(1, Math.min(options.limit ?? 20, 100));
260
299
  const params = new URLSearchParams({ search: query.trim(), sort: "downloads", limit: String(limit) });
261
- for (const field of ["safetensors", "config", "gated", "downloads", "pipeline_tag", "library_name", "tags"]) {
300
+ for (const field of ["safetensors", "gguf", "config", "gated", "downloads", "pipeline_tag", "library_name", "tags"]) {
262
301
  params.append("expand[]", field);
263
302
  }
264
303
  const url = `${hubBase(options.hubUrl)}/api/models?${params.toString()}`;
@@ -285,17 +324,22 @@ function toHubModel(entry, maxParams) {
285
324
  byDtype[dtype] = count;
286
325
  }
287
326
  const total = entry.safetensors?.total;
288
- const params = typeof total === "number" ? total : undefined;
327
+ const ggufArchitecture = typeof entry.gguf?.architecture === "string" ? entry.gguf.architecture : undefined;
328
+ const ggufType = ggufArchitecture === undefined ? undefined : GGUF_ARCHITECTURES[ggufArchitecture];
329
+ const ggufTotal = entry.gguf?.total;
330
+ const params = typeof total === "number" ? total : typeof ggufTotal === "number" && ggufType !== undefined ? ggufTotal : undefined;
289
331
  const embedding = isEmbeddingModel({
290
332
  repo: entry.id,
291
333
  pipelineTag: typeof entry.pipeline_tag === "string" ? entry.pipeline_tag : undefined,
292
334
  libraryName: typeof entry.library_name === "string" ? entry.library_name : undefined,
293
335
  tags: Array.isArray(entry.tags) ? entry.tags.filter((t) => typeof t === "string") : undefined,
294
336
  });
295
- let reason = embedding ? EMBEDDING_REASON : unsupportedReason(modelType);
337
+ // GGUF files of a supported architecture run whatever else the repository holds.
338
+ const gguf = ggufType !== undefined && SUPPORTED_MODEL_TYPES.includes(ggufType);
339
+ let reason = embedding ? EMBEDDING_REASON : gguf ? undefined : unsupportedReason(modelType);
296
340
  if (reason === undefined && params === undefined)
297
341
  reason = "no safetensors weights";
298
- if (reason === undefined)
342
+ if (reason === undefined && !gguf)
299
343
  reason = packedWeightsReason(byDtype);
300
344
  if (reason === undefined && params !== undefined && params > maxParams) {
301
345
  reason = `${formatParams(params)} parameters exceed the ${formatParams(maxParams)} limit`;
@@ -307,6 +351,10 @@ function toHubModel(entry, maxParams) {
307
351
  };
308
352
  if (modelType !== undefined)
309
353
  model.modelType = modelType;
354
+ else if (gguf)
355
+ model.modelType = ggufType;
356
+ if (gguf)
357
+ model.gguf = true;
310
358
  if (architectures !== undefined)
311
359
  model.architectures = architectures;
312
360
  if (params !== undefined) {
package/dist/models.d.ts CHANGED
@@ -48,15 +48,20 @@ export type NormalizedSource = {
48
48
  readonly repo: string;
49
49
  readonly revision?: string;
50
50
  readonly hubUrl?: string;
51
+ readonly file?: string;
51
52
  } | {
52
53
  readonly kind: "files";
53
54
  readonly files: NonNullable<Extract<ModelSource, {
54
55
  files: unknown;
55
56
  }>["files"]>;
57
+ readonly file?: string;
56
58
  } | {
57
59
  readonly kind: "fetch";
58
60
  readonly fetch: FetchFile;
61
+ readonly file?: string;
59
62
  };
63
+ /** Whether a normalized source loads a GGUF file (named, or the only weights of `files`). */
64
+ export declare function isGgufSource(source: NormalizedSource): boolean;
60
65
  /** Checks a source and turns a repository id string into a hub source. */
61
66
  export declare function normalizeSource(source: string | ModelSource, revision?: string): NormalizedSource;
62
67
  /**
package/dist/models.js CHANGED
@@ -4,7 +4,7 @@ import { EngineClient } from "./client.js";
4
4
  import { recommendedSampling } from "./curated.js";
5
5
  import { WebslmError, abortError, isAborted, toWebslmError } from "./errors.js";
6
6
  import { autoQuant, getBrowserResources, readCheckpointShapes } from "./fit.js";
7
- import { checkModel } from "./hub.js";
7
+ import { checkModel, isGgufFile } from "./hub.js";
8
8
  import { isNode } from "./runtime.js";
9
9
  const QUANTS = ["q8", "q4", "f32"];
10
10
  const ADAPTER_MODES = ["unmerged", "merged"];
@@ -77,6 +77,24 @@ export function resolveBackend(backend, env = globalThis.process?.env) {
77
77
  }
78
78
  return value;
79
79
  }
80
+ /** Checks the `file` of a source: a GGUF file name. */
81
+ function checkGgufName(file) {
82
+ if (file === undefined)
83
+ return undefined;
84
+ if (typeof file !== "string" || !isGgufFile(file.trim())) {
85
+ throw new WebslmError("INVALID_ARGUMENT", "`file` must name a .gguf file");
86
+ }
87
+ return file.trim();
88
+ }
89
+ /** Whether a normalized source loads a GGUF file (named, or the only weights of `files`). */
90
+ export function isGgufSource(source) {
91
+ if (source.file !== undefined)
92
+ return true;
93
+ if (source.kind !== "files")
94
+ return false;
95
+ const names = Object.keys(source.files);
96
+ return names.some(isGgufFile) && !names.some((n) => n.endsWith(".safetensors"));
97
+ }
80
98
  /** Checks a source and turns a repository id string into a hub source. */
81
99
  export function normalizeSource(source, revision) {
82
100
  if (typeof source === "string") {
@@ -92,6 +110,8 @@ export function normalizeSource(source, revision) {
92
110
  if (keys.length !== 1) {
93
111
  throw new WebslmError("INVALID_ARGUMENT", "a model source must have exactly one of `hub`, `files` or `fetch`");
94
112
  }
113
+ const file = checkGgufName(source.file);
114
+ const withFile = file === undefined ? {} : { file };
95
115
  if ("hub" in source) {
96
116
  if (typeof source.hub !== "string" || source.hub.trim() === "") {
97
117
  throw new WebslmError("INVALID_ARGUMENT", "`hub` must be a repository id");
@@ -102,6 +122,7 @@ export function normalizeSource(source, revision) {
102
122
  repo: source.hub.trim(),
103
123
  ...(rev === undefined ? {} : { revision: rev }),
104
124
  ...(source.hubUrl === undefined ? {} : { hubUrl: source.hubUrl }),
125
+ ...withFile,
105
126
  };
106
127
  }
107
128
  if ("files" in source) {
@@ -114,15 +135,19 @@ export function normalizeSource(source, revision) {
114
135
  throw new WebslmError("INVALID_ARGUMENT", `file "${name}" must be a Blob, an ArrayBuffer or a Uint8Array`);
115
136
  }
116
137
  }
117
- if (!("config.json" in files)) {
118
- throw new WebslmError("INVALID_ARGUMENT", "`files` must include config.json");
138
+ if (file !== undefined && !(file in files)) {
139
+ throw new WebslmError("INVALID_ARGUMENT", `\`files\` has no "${file}"`);
119
140
  }
120
- return { kind: "files", files };
141
+ // A GGUF file carries its configuration.
142
+ if (!("config.json" in files) && !Object.keys(files).some(isGgufFile)) {
143
+ throw new WebslmError("INVALID_ARGUMENT", "`files` must include config.json or a .gguf file");
144
+ }
145
+ return { kind: "files", files, ...withFile };
121
146
  }
122
147
  if (typeof source.fetch !== "function") {
123
148
  throw new WebslmError("INVALID_ARGUMENT", "`fetch` must be a function");
124
149
  }
125
- return { kind: "fetch", fetch: source.fetch };
150
+ return { kind: "fetch", fetch: source.fetch, ...withFile };
126
151
  }
127
152
  /**
128
153
  * Checks a LoRA adapter source: like {@link normalizeSource}, but `files`
@@ -154,11 +179,12 @@ function toWire(normalized, token) {
154
179
  ...(normalized.revision === undefined ? {} : { revision: normalized.revision }),
155
180
  ...(normalized.hubUrl === undefined ? {} : { hubUrl: normalized.hubUrl }),
156
181
  ...(token === undefined ? {} : { token }),
182
+ ...(normalized.file === undefined ? {} : { file: normalized.file }),
157
183
  };
158
184
  case "files":
159
- return { kind: "files", files: normalized.files };
185
+ return { kind: "files", files: normalized.files, ...(normalized.file === undefined ? {} : { file: normalized.file }) };
160
186
  case "fetch":
161
- return { kind: "fetch" };
187
+ return { kind: "fetch", ...(normalized.file === undefined ? {} : { file: normalized.file }) };
162
188
  }
163
189
  }
164
190
  function checkScale(scale) {
@@ -193,11 +219,13 @@ function requestPersistentStorage() {
193
219
  export async function loadModel(source, options = {}) {
194
220
  const device = resolveDevice(options.device);
195
221
  const backend = resolveBackend(options.backend);
196
- const requested = options.quant ?? "q8";
222
+ const normalized = normalizeSource(source, options.revision);
223
+ // A GGUF file loads in its own format unless told otherwise.
224
+ const gguf = isGgufSource(normalized);
225
+ const requested = options.quant ?? (gguf ? "auto" : "q8");
197
226
  if (requested !== "auto" && !QUANTS.includes(requested)) {
198
227
  throw new WebslmError("INVALID_ARGUMENT", `quant must be one of ${QUANTS.join(", ")} or auto`);
199
228
  }
200
- const normalized = normalizeSource(source, options.revision);
201
229
  const adapter = options.adapter === undefined ? undefined : normalizeAdapterSource(options.adapter);
202
230
  checkScale(options.adapterScale);
203
231
  if (options.adapterMode !== undefined && !ADAPTER_MODES.includes(options.adapterMode)) {
@@ -207,7 +235,12 @@ export async function loadModel(source, options = {}) {
207
235
  throw abortError(options.signal);
208
236
  if (normalized.kind === "hub" && !isNode())
209
237
  requestPersistentStorage();
210
- const { quant, note: quantNote } = requested === "auto" ? await resolveAutoQuant(normalized, options) : { quant: requested, note: undefined };
238
+ // `auto` on a GGUF file: the engine keeps the file's own format.
239
+ const { quant, note: quantNote } = requested !== "auto"
240
+ ? { quant: requested, note: undefined }
241
+ : gguf
242
+ ? { quant: "auto", note: undefined }
243
+ : await resolveAutoQuant(normalized, options);
211
244
  const shared = options.engine;
212
245
  if (shared !== undefined && !(shared instanceof EngineHandle)) {
213
246
  throw new WebslmError("INVALID_ARGUMENT", "`engine` must come from createEngine()");
@@ -15,13 +15,17 @@ export type WireSource = {
15
15
  readonly revision?: string;
16
16
  readonly hubUrl?: string;
17
17
  readonly token?: string;
18
+ /** A GGUF file of the repository. */
19
+ readonly file?: string;
18
20
  } | {
19
21
  readonly kind: "files";
20
22
  readonly files: Readonly<Record<string, FileData>>;
23
+ readonly file?: string;
21
24
  }
22
25
  /** Reads are forwarded to the page with `read` messages. */
23
26
  | {
24
27
  readonly kind: "fetch";
28
+ readonly file?: string;
25
29
  };
26
30
  export interface WireLoadOptions {
27
31
  readonly quant: string;
package/dist/types.d.ts CHANGED
@@ -52,21 +52,33 @@ export type FileData = Blob | ArrayBuffer | Uint8Array;
52
52
  * optional files such as `generation_config.json` are probed this way.
53
53
  */
54
54
  export type FetchFile = (path: string, range?: readonly [number, number]) => Promise<ArrayBuffer | Uint8Array | null | undefined>;
55
- /** Where a checkpoint comes from. A plain string is a Hugging Face repository id. */
55
+ /**
56
+ * Where a checkpoint comes from. A plain string is a Hugging Face repository id.
57
+ *
58
+ * `file` names a GGUF file of the source to load instead of safetensors
59
+ * weights (e.g. `"SmolLM2-135M-Instruct-Q8_0.gguf"`): its metadata gives
60
+ * the configuration, the tokenizer (unless a `tokenizer.json` sits next to
61
+ * it) and the chat template. A hub repository or a `files` source holding
62
+ * GGUF files and no safetensors loads its preferred GGUF file (Q8_0, else
63
+ * Q4_K_M, Q4_0...) without it; a `fetch` source needs it.
64
+ */
56
65
  export type ModelSource =
57
66
  /** A Hugging Face repository, downloaded once into the local cache. */
58
67
  {
59
68
  readonly hub: string;
60
69
  readonly revision?: string;
61
70
  readonly hubUrl?: string;
71
+ readonly file?: string;
62
72
  }
63
- /** Files by name: `"config.json"`, `"tokenizer.json"`, `"model.safetensors"`... */
73
+ /** Files by name: `"config.json"`, `"tokenizer.json"`, `"model.safetensors"`, `"model.gguf"`... */
64
74
  | {
65
75
  readonly files: Readonly<Record<string, FileData>>;
76
+ readonly file?: string;
66
77
  }
67
78
  /** A custom store. */
68
79
  | {
69
80
  readonly fetch: FetchFile;
81
+ readonly file?: string;
70
82
  };
71
83
  /**
72
84
  * A PEFT LoRA adapter: a Hugging Face repository id (a string or
@@ -1,47 +1,47 @@
1
1
  {
2
- "version": "0.4.1",
2
+ "version": "0.5.0",
3
3
  "assets": {
4
4
  "darwin-arm64": {
5
- "file": "webslm-node-0.4.1-darwin-arm64.node.gz",
6
- "size": 4528290,
7
- "sha256": "fef370b0bc05f3190cd91c963bec7d05a48e1c32528ee394c2a38fe599af1e02",
8
- "nodeSha256": "11c00c4af4394be95076c45cb14a39bf6486cd22c59e93a0c6745bc1c0f8fa6c"
5
+ "file": "webslm-node-0.5.0-darwin-arm64.node.gz",
6
+ "size": 4661767,
7
+ "sha256": "9cfcbd6e93f0e65a504ab5208d028a373de6bfba4b424f2a42484f9d44b2aba6",
8
+ "nodeSha256": "e9c942c1a20be8db41ae24264d8ce55c5cc32fa943f6199328ec402e87ef139d"
9
9
  },
10
10
  "darwin-x64": {
11
- "file": "webslm-node-0.4.1-darwin-x64.node.gz",
12
- "size": 4781839,
13
- "sha256": "b1e11294b083e8b7f7db9f3100193d2aa9642796e9791feb7582803ac2831b03",
14
- "nodeSha256": "25b7f086532e91f0c3fca8ad709f7c4a7000eaff00d9a93970d808b13ba0b923"
11
+ "file": "webslm-node-0.5.0-darwin-x64.node.gz",
12
+ "size": 4934785,
13
+ "sha256": "461f6b93b95a07548eee2034c8db8cd2afc08c4f00b0726ad7cad840419294fa",
14
+ "nodeSha256": "aebea474ee71dd98827bbc5ca0b91f7dc30e25039f708fa10d8c1c7eff020190"
15
15
  },
16
16
  "linux-x64-gnu": {
17
- "file": "webslm-node-0.4.1-linux-x64-gnu.node.gz",
18
- "size": 4811944,
19
- "sha256": "147528671faa5e52485eb409207b72b5bc225175713194e99c783c7da2b70d4a",
20
- "nodeSha256": "80a1cbcc204ed65d8799c13d2c8a5248646a66f72f0ea18aaa7f629f37e1f695"
17
+ "file": "webslm-node-0.5.0-linux-x64-gnu.node.gz",
18
+ "size": 4956357,
19
+ "sha256": "c124223f558869a8d1c79a03c5b05de9e6f01ab2edb5805717e91dc0d9ee2a33",
20
+ "nodeSha256": "b1c284b96462edb134077334f4d955b00f580ec7955d12c7df963f6789230bb1"
21
21
  },
22
22
  "linux-arm64-gnu": {
23
- "file": "webslm-node-0.4.1-linux-arm64-gnu.node.gz",
24
- "size": 4531590,
25
- "sha256": "cc9bb90288fc968f92f462f31dd7929054243d39fc03401525ad0ddc04b1f505",
26
- "nodeSha256": "3f5189ce553fb76f7439568dc492ce464849e11f31f82da865fa3079e5176407"
23
+ "file": "webslm-node-0.5.0-linux-arm64-gnu.node.gz",
24
+ "size": 4662654,
25
+ "sha256": "7d522027d215352920ad106c766247eddf6eeb50eec8d6bd087d5432cbab251b",
26
+ "nodeSha256": "3f752b007f4093338c0d698d9624db936c2b4afc5e0bc02d5e52e987c6a5e3e7"
27
27
  },
28
28
  "linux-x64-musl": {
29
- "file": "webslm-node-0.4.1-linux-x64-musl.node.gz",
30
- "size": 5174150,
31
- "sha256": "dfced45eaaccaaaf90ceb7b3685198d137181dda270956164a462af847ebc341",
32
- "nodeSha256": "bf54d6bf59c205f2f03ce4da64e5a015ccf510b92013fc1a6bc7a5c33cd752d1"
29
+ "file": "webslm-node-0.5.0-linux-x64-musl.node.gz",
30
+ "size": 5333007,
31
+ "sha256": "64e8f7d82eb9b2d34046fa7d712d9b5316eea23b0da33b488be4352fcf8836c1",
32
+ "nodeSha256": "f46def8367a6a33ae72f4d6abde7edabe8a5a82bad049dabfaed467f5f629e05"
33
33
  },
34
34
  "linux-arm64-musl": {
35
- "file": "webslm-node-0.4.1-linux-arm64-musl.node.gz",
36
- "size": 5012588,
37
- "sha256": "e4293a066377971e4e900256fcb182a12371b3907c9f2b6dbe5bc7a01a3f7053",
38
- "nodeSha256": "e6dd20315c5354a8c21ffebb59476bdc8c993ae21e9a3c00d573ae8a0adc7928"
35
+ "file": "webslm-node-0.5.0-linux-arm64-musl.node.gz",
36
+ "size": 5145035,
37
+ "sha256": "b2c712242f50e6a21347237a07a91e342edde0abe357fd57389399d907d32a45",
38
+ "nodeSha256": "561c9368986c7182e36148aadb44fa20d385828c4c106d95774a8ed188a3739b"
39
39
  },
40
40
  "win32-x64-msvc": {
41
- "file": "webslm-node-0.4.1-win32-x64-msvc.node.gz",
42
- "size": 5247323,
43
- "sha256": "570e537e95223ccc2a25c650ae7cd96f2999ce5f08b059add1e98846074a506d",
44
- "nodeSha256": "a1cd8bf4a3c77f01bdc848f783daa1aeae7786d1aa28f8d7a262915d7f6b3152"
41
+ "file": "webslm-node-0.5.0-win32-x64-msvc.node.gz",
42
+ "size": 5400333,
43
+ "sha256": "28476b37c7d7828dd539fdfc711bbe04fb7fde8a0fa1e732496df62fbce438cd",
44
+ "nodeSha256": "7d353430123a74894748cd8189a9920a5537d9beec36fe625d56e0aaf10910db"
45
45
  }
46
46
  }
47
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webslm",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Run small language models in the browser and in Node, straight from their original Hugging Face checkpoints: a Rust engine compiled to WebAssembly, in a worker, with an offline cache.",
5
5
  "license": "MIT",
6
6
  "author": "Maxime Golfier",
@@ -112,6 +112,12 @@ export class WasmModel {
112
112
  * weights: a valid stored file serves them instead of converting the
113
113
  * checkpoint, else they are written to it as they are converted;
114
114
  * `info().weightCache` says which (see [`WeightCacheOutcome`]).
115
+ *
116
+ * `ggufFile` loads that GGUF file of the source (a source listing
117
+ * GGUF files and no safetensors loads its preferred one). Without
118
+ * `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
119
+ * `webslm export` checkpoint) loads in its own format, its blocks
120
+ * unchanged; weights already in the load format skip `weightCache`.
115
121
  */
116
122
  static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
117
123
  /**
@@ -263,6 +263,12 @@ export class WasmModel {
263
263
  * weights: a valid stored file serves them instead of converting the
264
264
  * checkpoint, else they are written to it as they are converted;
265
265
  * `info().weightCache` says which (see [`WeightCacheOutcome`]).
266
+ *
267
+ * `ggufFile` loads that GGUF file of the source (a source listing
268
+ * GGUF files and no safetensors loads its preferred one). Without
269
+ * `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
270
+ * `webslm export` checkpoint) loads in its own format, its blocks
271
+ * unchanged; weights already in the load format skip `weightCache`.
266
272
  * @param {JsSource} source
267
273
  * @param {string} options_json
268
274
  * @param {JsSource | null} [lora]
@@ -1424,32 +1430,32 @@ function __wbg_get_imports() {
1424
1430
  arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
1425
1431
  }, arguments); },
1426
1432
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
1427
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 312, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1433
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 315, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1428
1434
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_);
1429
1435
  return ret;
1430
1436
  },
1431
1437
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
1432
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 245, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1438
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 248, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1433
1439
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_);
1434
1440
  return ret;
1435
1441
  },
1436
1442
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
1437
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 249, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1443
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 252, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1438
1444
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_);
1439
1445
  return ret;
1440
1446
  },
1441
1447
  __wbindgen_generic_0000000000000004: function(arg0, arg1) {
1442
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 249, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1448
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 252, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1443
1449
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37);
1444
1450
  return ret;
1445
1451
  },
1446
1452
  __wbindgen_generic_0000000000000005: function(arg0, arg1) {
1447
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 245, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1453
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 248, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1448
1454
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true__38);
1449
1455
  return ret;
1450
1456
  },
1451
1457
  __wbindgen_generic_0000000000000006: function(arg0, arg1) {
1452
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 245, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1458
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 248, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1453
1459
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true__39);
1454
1460
  return ret;
1455
1461
  },
Binary file
@@ -112,6 +112,12 @@ export class WasmModel {
112
112
  * weights: a valid stored file serves them instead of converting the
113
113
  * checkpoint, else they are written to it as they are converted;
114
114
  * `info().weightCache` says which (see [`WeightCacheOutcome`]).
115
+ *
116
+ * `ggufFile` loads that GGUF file of the source (a source listing
117
+ * GGUF files and no safetensors loads its preferred one). Without
118
+ * `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
119
+ * `webslm export` checkpoint) loads in its own format, its blocks
120
+ * unchanged; weights already in the load format skip `weightCache`.
115
121
  */
116
122
  static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
117
123
  /**
@@ -263,6 +263,12 @@ export class WasmModel {
263
263
  * weights: a valid stored file serves them instead of converting the
264
264
  * checkpoint, else they are written to it as they are converted;
265
265
  * `info().weightCache` says which (see [`WeightCacheOutcome`]).
266
+ *
267
+ * `ggufFile` loads that GGUF file of the source (a source listing
268
+ * GGUF files and no safetensors loads its preferred one). Without
269
+ * `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
270
+ * `webslm export` checkpoint) loads in its own format, its blocks
271
+ * unchanged; weights already in the load format skip `weightCache`.
266
272
  * @param {JsSource} source
267
273
  * @param {string} options_json
268
274
  * @param {JsSource | null} [lora]
@@ -1424,32 +1430,32 @@ function __wbg_get_imports() {
1424
1430
  arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
1425
1431
  }, arguments); },
1426
1432
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
1427
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 303, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1433
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 306, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1428
1434
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_);
1429
1435
  return ret;
1430
1436
  },
1431
1437
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
1432
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 236, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1438
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 239, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1433
1439
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_);
1434
1440
  return ret;
1435
1441
  },
1436
1442
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
1437
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 240, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1443
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 243, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1438
1444
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_);
1439
1445
  return ret;
1440
1446
  },
1441
1447
  __wbindgen_generic_0000000000000004: function(arg0, arg1) {
1442
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 240, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1448
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 243, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1443
1449
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37);
1444
1450
  return ret;
1445
1451
  },
1446
1452
  __wbindgen_generic_0000000000000005: function(arg0, arg1) {
1447
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 236, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1453
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 239, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1448
1454
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true__38);
1449
1455
  return ret;
1450
1456
  },
1451
1457
  __wbindgen_generic_0000000000000006: function(arg0, arg1) {
1452
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 236, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1458
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 239, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1453
1459
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true__39);
1454
1460
  return ret;
1455
1461
  },
Binary file
@@ -112,6 +112,12 @@ export class WasmModel {
112
112
  * weights: a valid stored file serves them instead of converting the
113
113
  * checkpoint, else they are written to it as they are converted;
114
114
  * `info().weightCache` says which (see [`WeightCacheOutcome`]).
115
+ *
116
+ * `ggufFile` loads that GGUF file of the source (a source listing
117
+ * GGUF files and no safetensors loads its preferred one). Without
118
+ * `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
119
+ * `webslm export` checkpoint) loads in its own format, its blocks
120
+ * unchanged; weights already in the load format skip `weightCache`.
115
121
  */
116
122
  static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
117
123
  /**
@@ -265,6 +265,12 @@ export class WasmModel {
265
265
  * weights: a valid stored file serves them instead of converting the
266
266
  * checkpoint, else they are written to it as they are converted;
267
267
  * `info().weightCache` says which (see [`WeightCacheOutcome`]).
268
+ *
269
+ * `ggufFile` loads that GGUF file of the source (a source listing
270
+ * GGUF files and no safetensors loads its preferred one). Without
271
+ * `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
272
+ * `webslm export` checkpoint) loads in its own format, its blocks
273
+ * unchanged; weights already in the load format skip `weightCache`.
268
274
  * @param {JsSource} source
269
275
  * @param {string} options_json
270
276
  * @param {JsSource | null} [lora]
@@ -1584,42 +1590,42 @@ function __wbg_get_imports(memory) {
1584
1590
  arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
1585
1591
  }, arguments); },
1586
1592
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
1587
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 365, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1593
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 368, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1588
1594
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true_);
1589
1595
  return ret;
1590
1596
  },
1591
1597
  __wbindgen_generic_0000000000000002: function(arg0, arg1) {
1592
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 888, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1598
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 908, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1593
1599
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue__core_2b10d7c4e784534e___result__Result_____wasm_bindgen_3c612a990bfab728___JsError___true_);
1594
1600
  return ret;
1595
1601
  },
1596
1602
  __wbindgen_generic_0000000000000003: function(arg0, arg1) {
1597
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 890, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1603
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 910, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1598
1604
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___js_sys_b608be85a12bc1d0___futures__task__wait_async_polyfill__MessageEvent______true_);
1599
1605
  return ret;
1600
1606
  },
1601
1607
  __wbindgen_generic_0000000000000004: function(arg0, arg1) {
1602
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 363, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1608
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 366, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1603
1609
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___sys__JsNullable_wgpu_4ecf802b864e9046___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_2b10d7c4e784534e___result__Result_____wasm_bindgen_3c612a990bfab728___JsError___true_);
1604
1610
  return ret;
1605
1611
  },
1606
1612
  __wbindgen_generic_0000000000000005: function(arg0, arg1) {
1607
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 365, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1613
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 368, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1608
1614
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true__44);
1609
1615
  return ret;
1610
1616
  },
1611
1617
  __wbindgen_generic_0000000000000006: function(arg0, arg1) {
1612
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 365, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1618
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 368, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1613
1619
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true__45);
1614
1620
  return ret;
1615
1621
  },
1616
1622
  __wbindgen_generic_0000000000000007: function(arg0, arg1) {
1617
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 363, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1623
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 366, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1618
1624
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___sys__JsNullable_wgpu_4ecf802b864e9046___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_2b10d7c4e784534e___result__Result_____wasm_bindgen_3c612a990bfab728___JsError___true__46);
1619
1625
  return ret;
1620
1626
  },
1621
1627
  __wbindgen_generic_0000000000000008: function(arg0, arg1) {
1622
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 363, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1628
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 366, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1623
1629
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___sys__JsNullable_wgpu_4ecf802b864e9046___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_2b10d7c4e784534e___result__Result_____wasm_bindgen_3c612a990bfab728___JsError___true__47);
1624
1630
  return ret;
1625
1631
  },
Binary file