webslm 0.3.0 → 0.4.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 +71 -15
- package/dist/ai-sdk/index.d.ts +1 -1
- package/dist/ai-sdk/index.js +1 -1
- package/dist/cache/models.d.ts +6 -0
- package/dist/cache/models.js +11 -0
- package/dist/curated.d.ts +31 -1
- package/dist/curated.js +49 -5
- package/dist/engine.d.ts +33 -4
- package/dist/engine.js +451 -43
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/models.d.ts +30 -9
- package/dist/models.js +72 -10
- package/dist/native.d.ts +165 -0
- package/dist/native.js +243 -0
- package/dist/protocol.d.ts +14 -3
- package/dist/recommended-sampling.d.ts +54 -0
- package/dist/recommended-sampling.js +73 -0
- package/dist/simple.d.ts +20 -6
- package/dist/simple.js +33 -7
- package/dist/types.d.ts +106 -20
- package/native-manifest.json +47 -0
- package/package.json +2 -1
- package/wasm/relaxed/webslm_wasm.d.ts +34 -9
- package/wasm/relaxed/webslm_wasm.js +78 -22
- package/wasm/relaxed/webslm_wasm_bg.wasm +0 -0
- package/wasm/relaxed/webslm_wasm_bg.wasm.d.ts +5 -3
- package/wasm/simd/webslm_wasm.d.ts +34 -9
- package/wasm/simd/webslm_wasm.js +78 -22
- package/wasm/simd/webslm_wasm_bg.wasm +0 -0
- package/wasm/simd/webslm_wasm_bg.wasm.d.ts +5 -3
- package/wasm/threads/webslm_wasm.d.ts +34 -9
- package/wasm/threads/webslm_wasm.js +83 -27
- package/wasm/threads/webslm_wasm_bg.wasm +0 -0
- package/wasm/threads/webslm_wasm_bg.wasm.d.ts +5 -3
package/README.md
CHANGED
|
@@ -12,14 +12,14 @@ import { ask } from "webslm";
|
|
|
12
12
|
console.log(await ask("Write a haiku about the sea"));
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
The first call downloads the default model ([
|
|
15
|
+
The first call downloads the default model ([LFM2.5 350M](https://huggingface.co/LiquidAI/LFM2.5-350M), about 710 MB) into a local cache; later runs load it offline. The same code runs in browsers, Node 20+ and Bun, with no bundler or setup in Node.
|
|
16
16
|
|
|
17
17
|
- Runs in a dedicated module Worker in browsers (`worker_threads` in Node), so the page stays responsive.
|
|
18
18
|
- Downloads a checkpoint once into the Origin Private File System (a directory in Node), resumes interrupted downloads, checks the Hub's SHA-256 and loads offline afterwards.
|
|
19
19
|
- Streams answers, keeps conversations, and exposes a low-level session API (teacher-forced scoring, step-wise decoding, logits and hidden states as `Float32Array`s).
|
|
20
20
|
- Searches the Hub for models it can run.
|
|
21
21
|
|
|
22
|
-
Supported architectures: Llama-style (SmolLM2, Mistral), Qwen2, Qwen3, Qwen3.5 (language model; Gated DeltaNet hybrid), LFM2 / LFM2.5 and LFM3. Models run on WebGPU or on the CPU through WebAssembly (SIMD, and Web Worker threads where the page allows): with `device: "auto"` (the default), WebGPU for models above ~100M parameters when the browser has an adapter, the CPU otherwise; `ModelInfo.backend` says which one runs. ESM only; browsers with WebAssembly SIMD (every current browser). Demo: <https://maxgfr.github.io/webslm/>.
|
|
22
|
+
Supported architectures: Llama-style (SmolLM2, Mistral), Qwen2, Qwen3, Qwen3.5 (language model; Gated DeltaNet hybrid), LFM2 / LFM2.5 and LFM3. Models run on WebGPU or on the CPU through WebAssembly (SIMD, and Web Worker threads where the page allows): with `device: "auto"` (the default), WebGPU for models above ~100M parameters when the browser has an adapter, the CPU otherwise; `ModelInfo.backend` says which one runs. In Node and Bun, the [native engine](#native-engine-in-node) runs instead (downloaded once from the release, checked, and cached): native SIMD kernels on every core, and the GPU through Metal, Vulkan or DX12. ESM only; browsers with WebAssembly SIMD (every current browser). Demo: <https://maxgfr.github.io/webslm/>.
|
|
23
23
|
|
|
24
24
|
## Ask
|
|
25
25
|
|
|
@@ -38,7 +38,7 @@ Options, all optional:
|
|
|
38
38
|
| --- | --- | --- |
|
|
39
39
|
| `model` | `DEFAULT_MODEL` | Hub repository id or a [source](#sources) (module-level calls only) |
|
|
40
40
|
| `maxTokens` | `512` | Largest number of new tokens (reasoning included) |
|
|
41
|
-
| `temperature` | the checkpoint's `generation_config.json`, else `0.7` | `0` is greedy, deterministic decoding |
|
|
41
|
+
| `temperature` | the model card's for the [curated models](#sampling-defaults), else the checkpoint's `generation_config.json`, else `0.7` | `0` is greedy, deterministic decoding |
|
|
42
42
|
| `system` | | System prompt |
|
|
43
43
|
| `think` | the template's default | `enable_thinking` for models that reason first (Qwen3, LFM3, and Qwen3.5 when asked); ignored by the others |
|
|
44
44
|
| `stop` | | Strings that end the answer (never emitted, not even in part) |
|
|
@@ -64,7 +64,7 @@ Models such as Qwen3 and LFM3 write their reasoning in a `<think>…</think>` bl
|
|
|
64
64
|
const { text, reasoning } = await ask("Is 97 prime?", { model: "Qwen/Qwen3-0.6B", withReasoning: true });
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
The split is generic: a `<think>` block at the start of the output (or one the chat template opens in the prompt) is reasoning, whatever the model. `splitReasoning(output)` applies it to text you already have. A reasoning model can spend its `maxTokens` thinking, leaving an empty answer: raise `maxTokens` or pass `think: false`.
|
|
67
|
+
The split is generic: a `<think>` block at the start of the output (or one the chat template opens in the prompt) is reasoning, whatever the model. `splitReasoning(output, opened?)` applies it to text you already have (`opened`: the prompt opened the block, as Qwen3.5's and LFM3's do when thinking; inferred when left out). A reasoning model can spend its `maxTokens` thinking, leaving an empty answer: raise `maxTokens` or pass `think: false`.
|
|
68
68
|
|
|
69
69
|
## Stream
|
|
70
70
|
|
|
@@ -99,7 +99,7 @@ chat.reset();
|
|
|
99
99
|
await llm.unload();
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
`load(model?, options?)` takes what `loadModel` takes: a repository id (default `DEFAULT_MODEL`) or a [source](#sources), and options that are all optional: `device` (`"auto"` (default), `"webgpu"` or `"cpu"`; `"webgpu"` falls back to the CPU when no GPU device can be created, and `"auto"` also when the model does not fit in GPU memory or the device fails while loading; `ModelInfo.deviceNote` says why), `quant` (default `"q8"`; `"q4"`, 4-bit blocks of 16 values, is smaller and less accurate, `"f32"` unquantized, `"auto"` picks `"q8"` unless the model does not fit this environment's memory, then `"q4"`, see [`fitModel`](#hub-helpers-and-cache); `ModelInfo.quantNote` says why), `revision`, `token` (gated or private repositories), `contextLength`, `onProgress`, `signal`, `worker` (default `true`), `cacheDir` (Node), `deterministic` (CPU only), and the advanced `wasmFlavour` and `threads` (see [CPU builds](#cpu-builds-and-deterministic-mode)).
|
|
102
|
+
`load(model?, options?)` takes what `loadModel` takes: a repository id (default `DEFAULT_MODEL`) or a [source](#sources), and options that are all optional: `device` (`"auto"` (default), `"webgpu"` or `"cpu"`; `"webgpu"` falls back to the CPU when no GPU device can be created, and `"auto"` also when the model does not fit in GPU memory or the device fails while loading; `ModelInfo.deviceNote` says why), `quant` (default `"q8"`; `"q4"`, 4-bit blocks of 16 values, is smaller and less accurate, `"f32"` unquantized, `"auto"` picks `"q8"` unless the model does not fit this environment's memory, then `"q4"`, see [`fitModel`](#hub-helpers-and-cache); `ModelInfo.quantNote` says why), `revision`, `token` (gated or private repositories), `contextLength`, `onProgress`, `signal`, `worker` (default `true`), `cacheDir` (Node), `weightCache` (default `true`, see [the converted-weight cache](#converted-weight-cache)), `deterministic` (CPU only), and the advanced `wasmFlavour` and `threads` (see [CPU builds](#cpu-builds-and-deterministic-mode)).
|
|
103
103
|
|
|
104
104
|
Each chat keeps its own cache in the engine, so a turn only processes the new message; `chat.dispose()` frees it. Calls on one model, and turns of one chat, run one after the other. `llm.model` is the underlying `Model`, for the advanced API.
|
|
105
105
|
|
|
@@ -150,7 +150,7 @@ await model.unload(); // or webslm.unloadAll()
|
|
|
150
150
|
|
|
151
151
|
| AI SDK | webslm |
|
|
152
152
|
| ------ | ------ |
|
|
153
|
-
| `maxOutputTokens`, `temperature`, `topP`, `topK`, `presencePenalty`, `frequencyPenalty`, `seed`, `stopSequences`, `abortSignal` | passed to the engine; unset
|
|
153
|
+
| `maxOutputTokens`, `temperature`, `topP`, `topK`, `presencePenalty`, `frequencyPenalty`, `seed`, `stopSequences`, `abortSignal` | passed to the engine; unset sampling options are the model card's for the [curated models](#sampling-defaults), else the checkpoint's (`temperature` else 0.7) |
|
|
154
154
|
| `reasoning` | `"none"` turns thinking off (`enable_thinking: false`), any other level on, with a `thinkingBudget` of 128 (`minimal`), 512 (`low`) or 2048 (`medium`) tokens; reasoning comes back as reasoning parts |
|
|
155
155
|
| `providerOptions.webslm` | `think`, `maxTokens`, `temperature`, `topK`, `topP`, `minP`, `repetitionPenalty`, `thinkingBudget`, `templateKwargs` for one call |
|
|
156
156
|
| `usage` | prompt tokens (`cacheRead`: tokens served from the KV cache of earlier turns) and generated tokens |
|
|
@@ -162,7 +162,7 @@ await model.unload(); // or webslm.unloadAll()
|
|
|
162
162
|
|
|
163
163
|
Prompts are text: user and assistant text parts, and text documents (`file` parts whose data is text). Other files are refused. Tool calls and results of earlier turns are sent as plain text. Consecutive messages of one role are merged. A multi-turn conversation reuses the KV cache, so each call only processes the new messages.
|
|
164
164
|
|
|
165
|
-
`CURATED_MODELS` (also exported by `webslm`) lists checkpoints known to run well, for a model picker; `searchModels` finds others on the Hub. `ai` and `@ai-sdk/provider` are optional peer dependencies: the main `webslm` entry does not need them. The demo's [AI SDK page](https://maxgfr.github.io/webslm/ai-sdk.html) (`apps/demo/src/ai-sdk.ts`) is a complete example.
|
|
165
|
+
`CURATED_MODELS` (also exported by `webslm`) lists checkpoints known to run well, with the sampling their model cards recommend, for a model picker; `searchModels` finds others on the Hub. `ai` and `@ai-sdk/provider` are optional peer dependencies: the main `webslm` entry does not need them. The demo's [AI SDK page](https://maxgfr.github.io/webslm/ai-sdk.html) (`apps/demo/src/ai-sdk.ts`) is a complete example.
|
|
166
166
|
|
|
167
167
|
## Advanced API
|
|
168
168
|
|
|
@@ -188,7 +188,23 @@ const text = await model.generate("What is the capital of France?"); // whole an
|
|
|
188
188
|
await model.unload();
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
`chat` reuses the session's cache across turns, so a follow-up only processes the new message. Stop a stream with `stream.stop()`, by breaking out of the loop, or with `signal`. Sampling options left unset come from the checkpoint's `generation_config.json` (`model.info().generationConfig`) when it enables sampling, else decoding is greedy; `temperature: 0` is greedy. Chat template variables go through `templateKwargs`, e.g. `{ enable_thinking: false }` for Qwen3. Output is returned as generated, `<think>` blocks included.
|
|
191
|
+
`chat` reuses the session's cache across turns, so a follow-up only processes the new message. Stop a stream with `stream.stop()`, by breaking out of the loop, or with `signal`. Sampling options left unset come from the model card for the [curated models](#sampling-defaults), else from the checkpoint's `generation_config.json` (`model.info().generationConfig`) when it enables sampling, else decoding is greedy; `temperature: 0` is greedy. Chat template variables go through `templateKwargs`, e.g. `{ enable_thinking: false }` for Qwen3. Output is returned as generated, `<think>` blocks included.
|
|
192
|
+
|
|
193
|
+
### Sampling defaults
|
|
194
|
+
|
|
195
|
+
The checkpoints of SmolLM2, LFM2.5 and Qwen3.5 ship no sampling settings, and Qwen3's are those of its thinking mode, so the curated models (`CURATED_MODELS`) start every generation from what their model cards recommend instead; options a call sets override the matching fields, and `temperature: 0` turns them off (greedy decoding):
|
|
196
|
+
|
|
197
|
+
| Model | Answering directly | Thinking |
|
|
198
|
+
| --- | --- | --- |
|
|
199
|
+
| SmolLM2 135M, 360M | temperature 0.2, top-p 0.9 | |
|
|
200
|
+
| LFM2.5 350M | temperature 0.1, top-k 50, repetition penalty 1.05 | |
|
|
201
|
+
| Qwen3 0.6B | temperature 0.7, top-p 0.8, top-k 20 | temperature 0.6, top-p 0.95, top-k 20 |
|
|
202
|
+
| Qwen3.5 0.8B | temperature 0.7, top-p 0.8, top-k 20, presence penalty 1.5 | temperature 0.6, top-p 0.95, top-k 20, presence penalty 1.5 |
|
|
203
|
+
| LFM3 1.7B | temperature 0.1, top-k 50, repetition penalty 1.1 | |
|
|
204
|
+
|
|
205
|
+
The thinking column applies when `templateKwargs.enable_thinking` (the simple API's `think`) is `true`, or unset for the models that think by default (Qwen3, LFM3). Other checkpoints of these families (`model_type` `qwen3`, `qwen3_5`, `lfm2`, `lfm3`) get their family's settings when their `generation_config.json` does not ask for sampling; any other checkpoint uses its `generation_config.json`. `recommendedSampling(repoOrCheckpoint, think?)` returns the settings (`undefined` when there are none) and `RECOMMENDED_SAMPLING` is the table: the Rust engine's (`crates/webslm-core/src/recommended_sampling.json`), so `webslm run`, `webslm chat` and `webslm serve` pick the same settings.
|
|
206
|
+
|
|
207
|
+
Bigger models use the conversation better: on a three-turn chat ("My name is Ana and I live in Lisbon.", "What is my name?", "Which city do I live in?") decoded greedily, the SmolLM2 checkpoints repeat their first answer, LFM2.5 350M answers "Ana" and "Lisbon", Qwen3.5 0.8B recalls the name; `transformers` gives the same answers, token for token (`test/chat-wasm.test.ts`).
|
|
192
208
|
|
|
193
209
|
## Generation controls
|
|
194
210
|
|
|
@@ -273,19 +289,25 @@ type ModelSource =
|
|
|
273
289
|
PEFT LoRA adapters, as published on the Hub (`adapter_config.json` and `adapter_model.safetensors`), from the same kinds of sources as models (a repo id, `{ hub }`, `{ files }` or `{ fetch }`):
|
|
274
290
|
|
|
275
291
|
```ts
|
|
276
|
-
//
|
|
292
|
+
// Applied as the model loads (also with the simple API: `load(model, { adapter })`).
|
|
277
293
|
const model = await loadModel("HuggingFaceTB/SmolLM2-135M-Instruct", {
|
|
278
294
|
adapter: "user/my-lora",
|
|
279
295
|
adapterScale: 1, // default
|
|
296
|
+
adapterMode: "unmerged", // default; or "merged"
|
|
280
297
|
});
|
|
281
|
-
model.info().lora; // { modules: ["model.layers.20.self_attn.q_proj", ...], scale, rank, baseModel, repo, revision }
|
|
298
|
+
model.info().lora; // { modules: ["model.layers.20.self_attn.q_proj", ...], scale, rank, mode, baseModel, repo, revision }
|
|
282
299
|
|
|
283
300
|
// Later: swap to another adapter, then back to the base model.
|
|
284
301
|
await model.applyAdapter({ files: { "adapter_config.json": config, "adapter_model.safetensors": weights } }, { scale: 0.5 });
|
|
285
302
|
await model.removeAdapter();
|
|
286
303
|
```
|
|
287
304
|
|
|
288
|
-
|
|
305
|
+
With `s = (lora_alpha / r) · scale` (`lora_alpha / sqrt(r)` with `use_rslora`), `adapterMode` (set at load, for every adapter of the model) chooses how an adapter runs:
|
|
306
|
+
|
|
307
|
+
- `"unmerged"` (the default): every adapted layer adds the delta in f32 beside the weights, `y = W·x + s·B(A·x)`, as `peft` computes it. The weights and the adapter each keep their precision: `quant: "q8"` with `activations: "f32"` on a checkpoint whose matrices hold exact Q8_0 values gives the logits of `quant: "f32"` with the same adapter, bit for bit on the CPU. `applyAdapter` and `removeAdapter` only upload or drop the adapter's small f32 factors. Decoding pays two small matmuls per adapted layer (on SmolLM2-135M with one thread, 3 to 5% of the decode speed of Q8_0 and Q4 weights, under 1.5% with f32 weights or f32 activations).
|
|
308
|
+
- `"merged"`: `W' = W + s·B·A` is merged into the matrices it targets in f32 before quantization, so decoding runs at the base model's speed, but quantization rounds the adapter's delta with the weights. `applyAdapter` reads the affected base matrices again from the model's source (the cache for Hub models; a `fetch` source is called again).
|
|
309
|
+
|
|
310
|
+
`target_modules` (names, a regular expression or `"all-linear"`), `exclude_modules`, `layers_to_transform`, `layers_pattern`, `rank_pattern` and `alpha_pattern` are honoured. `applyAdapter` replaces the previous adapter; `removeAdapter` restores the base model exactly (bit-identical logits). An adapter that does not fit the model rejects with `INVALID_ADAPTER` and leaves the model unchanged; DoRA, LoRA biases and `modules_to_save` are refused. Every session starts over at its next call after a change.
|
|
289
311
|
|
|
290
312
|
## Low-level sessions
|
|
291
313
|
|
|
@@ -302,7 +324,7 @@ await session.reset();
|
|
|
302
324
|
|
|
303
325
|
Hidden state `i` is the residual stream after layer `i` counted from 1 (`0` is the embedding output), before the final norm: the indexing of `transformers`' `output_hidden_states`. Buffers are transferred from the worker without copies.
|
|
304
326
|
|
|
305
|
-
Attention caches rewind for free. Models with recurrent layers (LFM2 and LFM3 short convolutions, Qwen3.5 Gated DeltaNet, LFM3's sliding-window ring buffers) cannot rewind their state, so `truncate(n)` recomputes it from the
|
|
327
|
+
Attention caches rewind for free. Models with recurrent layers (LFM2 and LFM3 short convolutions, Qwen3.5 Gated DeltaNet, LFM3's sliding-window ring buffers) cannot rewind their state, so `truncate(n)` recomputes it from the latest checkpoint before `n`, or from the start. `chat` checkpoints those layers where the history ends and at the end of the prompt, so the next turn of a conversation resumes there even when the template renders the last answer differently (Qwen3.5 drops reasoning blocks): it only computes the new turn.
|
|
306
328
|
|
|
307
329
|
## Hub helpers and cache
|
|
308
330
|
|
|
@@ -326,9 +348,22 @@ await cacheUsage(); // { usedBytes, originUsageBytes, quotaBytes, persisted }
|
|
|
326
348
|
|
|
327
349
|
`fitModel` estimates the memory of each weight format from `config.json` and the safetensors headers (no weights are downloaded): the weights in their load format, the KV cache layer by layer at `contextLength` (full attention grows with the context, sliding-window layers keep a ring of `2 × window - 1` positions, convolution and Gated DeltaNet layers a fixed state) and the activations of a prefill, the same numbers as the Rust engine's estimate (`estimateModelMemory` gives them for any config and tensor shapes). It compares them with what the environment reports: `navigator.deviceMemory` less a reserve for the browser and the OS, the 4 GiB a WebAssembly memory can address (the CPU engine), the largest buffer of the WebGPU adapter, and `navigator.storage.estimate()` for the download (`getBrowserResources()` reads them, `fitParams(params, resources)` gives a quick verdict from a parameter count, as search results carry no config). A model fits below 80% of the usable memory and is tight up to 100%. Browsers round `deviceMemory` down and cap it (8 GiB in Chromium), and do not report GPU memory, so the verdict is conservative.
|
|
328
350
|
|
|
351
|
+
### Converted-weight cache
|
|
352
|
+
|
|
353
|
+
Loading a hub model in `"q8"` or a 4-bit format converts its BF16 checkpoint as it loads. The converted weights are stored next to the download (`<repo>/<sha>/quantized/<format>/weights.webslmq`, in OPFS or the Node cache directory, in the command-line tool's file format), and later loads read them instead of converting again. In Node (WebAssembly, one thread, Apple M5), from the cache:
|
|
354
|
+
|
|
355
|
+
| Model, Q8_0 | Converting | From the converted weights |
|
|
356
|
+
| --- | --- | --- |
|
|
357
|
+
| SmolLM2 135M | 0.6 to 0.8 s | 0.11 s |
|
|
358
|
+
| LFM2.5 350M | 1.4 to 1.6 s | 0.26 s |
|
|
359
|
+
| Qwen3 0.6B | 2.4 to 2.7 s | 0.51 to 0.54 s |
|
|
360
|
+
| Qwen3.5 0.8B | 3.2 to 3.5 s | 0.62 to 0.77 s |
|
|
361
|
+
|
|
362
|
+
The first load writes the file as it converts (0.1 to 1.8 s more, once). Each weight carries a CRC-32 and the file a versioned header and the repository, commit and format it was converted from: a file that does not match, or that fails a check, is converted again and rewritten. `info().weightCache` says what a load did (`{ status: "hit" | "written" | "failed" | "off", bytes }`); `weightCache: false` in the load options, or `WEBSLM_QUANT_CACHE=0` in Node, turns it off. Float formats (`"f32"`), sources other than the hub and the Cache API (which keeps a file in memory until it is complete) are not cached. `deleteCachedModel` removes the converted weights with the model, and `listCachedModels` counts them in its sizes.
|
|
363
|
+
|
|
329
364
|
## Node, Bun and Deno
|
|
330
365
|
|
|
331
|
-
The same API works in Node 20+ and Bun, as a plain ESM script with no bundler. The cache lives in `WEBSLM_CACHE_DIR` or `~/.cache/webslm` (`cacheDir` in the options overrides it). `WEBSLM_OFFLINE=1` (or `HF_HUB_OFFLINE=1`) forbids network access: models already in the cache load, anything else rejects with `NETWORK`. `HF_ENDPOINT` replaces `https://huggingface.co` (a mirror, or a local stand-in in tests) unless a source gives its own `hubUrl`. The engine runs in a `worker_threads` worker, which does not keep the process alive between calls; pass `worker: false` to run it on the calling thread. Deno 2 runs Hub models as is; for a `files` source of a few hundred megabytes, pass `worker: false` (Deno's `worker_threads` cannot copy buffers that large).
|
|
366
|
+
The same API works in Node 20+ and Bun, as a plain ESM script with no bundler, on the [native engine](#native-engine-in-node) when it is available, else on WebAssembly. The cache lives in `WEBSLM_CACHE_DIR` or `~/.cache/webslm` (`cacheDir` in the options overrides it). `WEBSLM_OFFLINE=1` (or `HF_HUB_OFFLINE=1`) forbids network access: models already in the cache load, anything else rejects with `NETWORK`. `HF_ENDPOINT` replaces `https://huggingface.co` (a mirror, or a local stand-in in tests) unless a source gives its own `hubUrl`. The engine runs in a `worker_threads` worker, which does not keep the process alive between calls; pass `worker: false` to run it on the calling thread. Deno 2 runs Hub models as is; for a `files` source of a few hundred megabytes, pass `worker: false` (Deno's `worker_threads` cannot copy buffers that large).
|
|
332
367
|
|
|
333
368
|
```ts
|
|
334
369
|
import { readFile } from "node:fs/promises";
|
|
@@ -346,6 +381,27 @@ const llm = await load({ files });
|
|
|
346
381
|
console.log(await llm.ask("Hello!"));
|
|
347
382
|
```
|
|
348
383
|
|
|
384
|
+
## Native engine in Node
|
|
385
|
+
|
|
386
|
+
Each release attaches to its [GitHub Release](https://github.com/maxgfr/webslm/releases) a Node-API addon built from the same Rust engine, for `darwin-arm64`, `darwin-x64`, `linux-x64-gnu`, `linux-arm64-gnu` (glibc 2.28 and later), `linux-x64-musl`, `linux-arm64-musl` (Alpine) and `win32-x64-msvc`: `webslm-node-<version>-<platform>.node.gz`, about 5 MB. The npm package carries the SHA-256 of each (`native-manifest.json`). The first time a model loads in Node or Bun, webslm downloads the addon of its platform and version into the cache directory (`<cache>/native/<version>/`), checks both the download and the uncompressed addon against the manifest, and loads it; later runs load it from the cache, offline. Nothing runs at install time. The addon runs hub models instead of the WebAssembly build:
|
|
387
|
+
|
|
388
|
+
- the native CPU kernels (NEON with dotprod and i8mm, AVX2, AVX-512 VNNI) on every core, capped by the container's CPU quota, instead of WebAssembly SIMD on at most 8 threads;
|
|
389
|
+
- the GPU through Metal (macOS), Vulkan or DX12 (Linux, Windows), with the device rules of the command-line tool: `device: "auto"` runs models above ~100M parameters on a hardware GPU that holds them (software rasterizers such as llvmpipe are skipped; the model is sized against the GPU's memory before anything is uploaded), the CPU otherwise; `device: "gpu"` fails with `UNSUPPORTED_DEVICE` when there is no GPU;
|
|
390
|
+
- `quant: "auto"` decided against the machine's memory and the GPU's (measured with [sift](https://github.com/maxgfr/sift)), not the 4 GiB of WebAssembly;
|
|
391
|
+
- the converted-weight cache in the same file as the command-line tool (`<repo>/<sha>/quantized/<format>/weights.webslmq`), so `webslm pull --quant q8` and the package share it when `WEBSLM_CACHE_DIR` points both at one directory.
|
|
392
|
+
|
|
393
|
+
The API is the same (`load`, `ask`, `stream`, `loadModel`, sessions with `score`, `step`, `fork`, LoRA adapters, the AI SDK provider), and so are the results on the CPU: the quantized kernels are bit-identical across builds, so `q8` gives the WebAssembly engine's greedy tokens, and `f32` the `transformers` goldens (both checked in CI).
|
|
394
|
+
|
|
395
|
+
```ts
|
|
396
|
+
const model = await loadModel("HuggingFaceTB/SmolLM2-360M-Instruct");
|
|
397
|
+
model.info().runtime; // "native" (or "wasm")
|
|
398
|
+
model.info().backend; // "GPU (native, Apple M5 (Metal))", "CPU (native, neon-i8mm, 10 threads)"...
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
`backend` in the load options picks the engine: `"auto"` (the default) the native one when it is available and the source is a hub model, else WebAssembly, with the reason in `info().runtimeNote`; `"native"` fails with `UNSUPPORTED_DEVICE` when it cannot run; `"wasm"` keeps WebAssembly and downloads nothing. `WEBSLM_BACKEND=native|wasm|auto` sets the default for a whole process (to pin a deployment, or to make an unavailable native engine an error in CI). `files` and `fetch` sources always run on WebAssembly (the native engine reads the cache directory); `files` and `fetch` LoRA adapters work on both. The models run on threads of their own: the JavaScript thread never waits for a token, and several calls on one model interleave token by token. `threads` sizes the CPU pool (default: the available cores, capped by the cgroup CPU quota in a container); the first native load of the process decides it.
|
|
402
|
+
|
|
403
|
+
WebAssembly runs instead, and `info().runtimeNote` says why, when the native engine is not available: no build for the platform, offline mode (`WEBSLM_OFFLINE=1`) without the addon in the cache, a download that fails or takes more than 30 seconds, a checksum that does not match (the file is then discarded), or a package built from source (it has no manifest). The download goes to `https://github.com/maxgfr/webslm/releases/download/v<version>/`; `WEBSLM_NATIVE_URL` replaces that base (a mirror holding the same files), and behind a proxy, Node's `fetch` uses `HTTPS_PROXY` when `NODE_USE_ENV_PROXY=1` (Node 24; Bun reads it by itself). For an air-gapped or locked-down deployment, put the addon in the cache directory beforehand (`<cache>/native/<version>/webslm-node-<version>-<platform>.node`, the uncompressed release asset) or point `WEBSLM_NATIVE_PATH` at a `.node` file (`cargo xtask build-native --release` builds one into `target/native/<platform>/webslm.node`). Bun loads the addon through its Node-API support. Deno runs on WebAssembly under `"auto"`; `backend: "native"` loads the addon there with `--allow-ffi`. Browser bundles never download or load it.
|
|
404
|
+
|
|
349
405
|
## CPU builds and deterministic mode
|
|
350
406
|
|
|
351
407
|
The package ships three WebAssembly builds of the engine and each worker picks the fastest one the environment supports (`selectWasmFlavour()`), unless `wasmFlavour` says otherwise:
|
|
@@ -354,7 +410,7 @@ The package ships three WebAssembly builds of the engine and each worker picks t
|
|
|
354
410
|
- `"relaxed"`: SIMD128 and relaxed SIMD, one thread.
|
|
355
411
|
- `"simd"`: SIMD128, one thread; runs wherever WebAssembly SIMD does.
|
|
356
412
|
|
|
357
|
-
`model.info().cpu` reports `{ flavour, kernels, threads, deterministic }
|
|
413
|
+
`model.info().cpu` reports `{ flavour, kernels, threads, deterministic }` (`flavour: "native"` on the native engine), and `model.info().backend` a readable summary such as `"CPU (wasm, relaxed SIMD, 8 threads)"`. Each worker instantiates one build: the first model loaded in it decides.
|
|
358
414
|
|
|
359
415
|
`deterministic: true` selects kernels whose results are bit-identical in every build and natively (the `webslm` command-line tool and the Rust crates on x86_64 and aarch64): same weights, prompt and options, same logits, whatever the browser, CPU or thread count. It gives up fused multiply-adds, which costs speed with `f32` weights only; quantized weights run the same kernels either way.
|
|
360
416
|
|
|
@@ -370,7 +426,7 @@ export default defineConfig({
|
|
|
370
426
|
});
|
|
371
427
|
```
|
|
372
428
|
|
|
373
|
-
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.
|
|
429
|
+
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.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>.
|
|
374
430
|
|
|
375
431
|
## Errors
|
|
376
432
|
|
package/dist/ai-sdk/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import type { ProviderV4 } from "@ai-sdk/provider";
|
|
22
22
|
import { WebslmLanguageModel, type WebslmModelSettings } from "./language-model.js";
|
|
23
23
|
import { type WebslmEngine, type WebslmLoadOptions } from "./loader.js";
|
|
24
|
-
export { CURATED_MODELS, type CuratedModel } from "../curated.js";
|
|
24
|
+
export { CURATED_MODELS, curatedModel, RECOMMENDED_SAMPLING, recommendedSampling, type CheckpointTraits, type CuratedModel, type SamplingDefaults, type SamplingSet, } from "../curated.js";
|
|
25
25
|
export { searchModels, type HubModel, type SearchModelsOptions } from "../hub.js";
|
|
26
26
|
export { DEFAULT_MODEL } from "../simple.js";
|
|
27
27
|
export type { LoadModelOptions, LoadProgress, ModelInfo } from "../types.js";
|
package/dist/ai-sdk/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import { WebslmError } from "../errors.js";
|
|
|
22
22
|
import { loadModel } from "../models.js";
|
|
23
23
|
import { CALL_SETTING_KEYS, WebslmLanguageModel } from "./language-model.js";
|
|
24
24
|
import { ModelSlot, pickLoadOptions, slotKey, } from "./loader.js";
|
|
25
|
-
export { CURATED_MODELS } from "../curated.js";
|
|
25
|
+
export { CURATED_MODELS, curatedModel, RECOMMENDED_SAMPLING, recommendedSampling, } from "../curated.js";
|
|
26
26
|
export { searchModels } from "../hub.js";
|
|
27
27
|
export { DEFAULT_MODEL } from "../simple.js";
|
|
28
28
|
export { WebslmLanguageModel, } from "./language-model.js";
|
package/dist/cache/models.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ export declare function checkRepoId(repo: string): string;
|
|
|
54
54
|
export declare function refPath(repo: string, revision: string): string;
|
|
55
55
|
export declare function revisionDir(repo: string, sha: string): string;
|
|
56
56
|
export declare function filePath(repo: string, sha: string, file: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* The converted weights of a snapshot in load format `quant`:
|
|
59
|
+
* `{repo}/{sha}/quantized/{format}/weights.webslmq`, the command-line tool's
|
|
60
|
+
* layout (and file format).
|
|
61
|
+
*/
|
|
62
|
+
export declare function weightCachePath(repo: string, sha: string, quant: string): string;
|
|
57
63
|
export declare function manifestPath(repo: string, sha: string): string;
|
|
58
64
|
export declare function readRef(store: CacheStore, repo: string, revision: string): Promise<string | undefined>;
|
|
59
65
|
export declare function writeRef(store: CacheStore, repo: string, revision: string, sha: string): Promise<void>;
|
package/dist/cache/models.js
CHANGED
|
@@ -26,6 +26,17 @@ export function revisionDir(repo, sha) {
|
|
|
26
26
|
export function filePath(repo, sha, file) {
|
|
27
27
|
return joinPath(repo, sha, file);
|
|
28
28
|
}
|
|
29
|
+
/** Directory names of the weight formats, as the command-line tool names them. */
|
|
30
|
+
const FORMAT_DIRS = { q8: "q8_0", q4: "q4_0_16" };
|
|
31
|
+
/**
|
|
32
|
+
* The converted weights of a snapshot in load format `quant`:
|
|
33
|
+
* `{repo}/{sha}/quantized/{format}/weights.webslmq`, the command-line tool's
|
|
34
|
+
* layout (and file format).
|
|
35
|
+
*/
|
|
36
|
+
export function weightCachePath(repo, sha, quant) {
|
|
37
|
+
const format = FORMAT_DIRS[quant] ?? quant;
|
|
38
|
+
return joinPath(repo, sha, "quantized", encodeURIComponent(format), "weights.webslmq");
|
|
39
|
+
}
|
|
29
40
|
export function manifestPath(repo, sha) {
|
|
30
41
|
return joinPath(repo, sha, MANIFEST_FILE);
|
|
31
42
|
}
|
package/dist/curated.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/** A short list of checkpoints known to run well, for model pickers. */
|
|
2
|
+
import { type CheckpointTraits, type SamplingDefaults, type SamplingSet } from "./recommended-sampling.js";
|
|
3
|
+
export type { CheckpointTraits, SamplingDefaults, SamplingSet } from "./recommended-sampling.js";
|
|
4
|
+
export { RECOMMENDED_SAMPLING } from "./recommended-sampling.js";
|
|
2
5
|
/** A checkpoint of {@link CURATED_MODELS}. */
|
|
3
6
|
export interface CuratedModel {
|
|
4
7
|
/** Hugging Face repository id, to pass to `load`, `loadModel` or `webslm()`. */
|
|
@@ -13,10 +16,37 @@ export interface CuratedModel {
|
|
|
13
16
|
readonly note: string;
|
|
14
17
|
/** Whether it can reason before answering (`think`, the AI SDK's `reasoning`). */
|
|
15
18
|
readonly thinking?: boolean;
|
|
19
|
+
/** Whether it reasons when `think` (the template's `enable_thinking`) is not set. */
|
|
20
|
+
readonly thinksByDefault?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The sampling its model card recommends, applied by default to every
|
|
23
|
+
* generation of this repository (see {@link recommendedSampling}):
|
|
24
|
+
* `answer` when it answers directly, `thinking` when it reasons first.
|
|
25
|
+
*/
|
|
26
|
+
readonly sampling: SamplingSet;
|
|
16
27
|
}
|
|
17
28
|
/**
|
|
18
29
|
* Checkpoints validated against `transformers`, smallest first: the first
|
|
19
30
|
* ones are quick on a laptop CPU, the largest (LFM3 1.7B) wants WebGPU. Any supported repository works too: see
|
|
20
|
-
* `searchModels` and `checkModel` for the others.
|
|
31
|
+
* `searchModels` and `checkModel` for the others. Larger models answer
|
|
32
|
+
* better: the 135M and 360M SmolLM2 checkpoints lose track of a
|
|
33
|
+
* conversation after a turn or two, while LFM2.5 350M and the Qwen
|
|
34
|
+
* checkpoints recall what was said earlier.
|
|
21
35
|
*/
|
|
22
36
|
export declare const CURATED_MODELS: readonly CuratedModel[];
|
|
37
|
+
/** The entry of {@link CURATED_MODELS} for a repository id (case-insensitive), if any. */
|
|
38
|
+
export declare function curatedModel(repo: string | undefined): CuratedModel | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The sampling a model card recommends for a checkpoint, with or without
|
|
41
|
+
* reasoning (`think` unset: the model's default), or `undefined` when there
|
|
42
|
+
* is none (its `generation_config.json` then applies). `checkpoint` is a
|
|
43
|
+
* repository id, or what identifies a checkpoint: the curated repositories
|
|
44
|
+
* use their card's settings whatever their `generation_config.json` says;
|
|
45
|
+
* other checkpoints of the same families (`model_type` `qwen3`, `qwen3_5`,
|
|
46
|
+
* `lfm2`, `lfm3`) use their family's when their `generation_config.json`
|
|
47
|
+
* does not ask for sampling. The table is the Rust engine's, so the
|
|
48
|
+
* command-line tool and the server pick the same settings. Generations
|
|
49
|
+
* start from it: options a call sets override the matching fields, and
|
|
50
|
+
* `temperature: 0` (greedy decoding) turns it off.
|
|
51
|
+
*/
|
|
52
|
+
export declare function recommendedSampling(checkpoint: string | CheckpointTraits | undefined, think?: boolean): SamplingDefaults | undefined;
|
package/dist/curated.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/** A short list of checkpoints known to run well, for model pickers. */
|
|
2
|
+
import { RECOMMENDED_SAMPLING, samplingSet, settingsFor, } from "./recommended-sampling.js";
|
|
3
|
+
export { RECOMMENDED_SAMPLING } from "./recommended-sampling.js";
|
|
4
|
+
const SETS = RECOMMENDED_SAMPLING.sets;
|
|
5
|
+
const SMOLLM2 = SETS["smollm2"];
|
|
6
|
+
const LFM2 = SETS["lfm2"];
|
|
7
|
+
const LFM3 = SETS["lfm3"];
|
|
8
|
+
const QWEN3 = SETS["qwen3"];
|
|
9
|
+
const QWEN3_5 = SETS["qwen3_5"];
|
|
2
10
|
/**
|
|
3
11
|
* Checkpoints validated against `transformers`, smallest first: the first
|
|
4
12
|
* ones are quick on a laptop CPU, the largest (LFM3 1.7B) wants WebGPU. Any supported repository works too: see
|
|
5
|
-
* `searchModels` and `checkModel` for the others.
|
|
13
|
+
* `searchModels` and `checkModel` for the others. Larger models answer
|
|
14
|
+
* better: the 135M and 360M SmolLM2 checkpoints lose track of a
|
|
15
|
+
* conversation after a turn or two, while LFM2.5 350M and the Qwen
|
|
16
|
+
* checkpoints recall what was said earlier.
|
|
6
17
|
*/
|
|
7
18
|
export const CURATED_MODELS = [
|
|
8
19
|
{
|
|
@@ -10,21 +21,24 @@ export const CURATED_MODELS = [
|
|
|
10
21
|
name: "SmolLM2 135M",
|
|
11
22
|
params: "135M",
|
|
12
23
|
sizeBytes: 269_060_552,
|
|
13
|
-
note: "Fastest
|
|
24
|
+
note: "Fastest, but loses track of a conversation quickly.",
|
|
25
|
+
sampling: SMOLLM2,
|
|
14
26
|
},
|
|
15
27
|
{
|
|
16
28
|
repo: "HuggingFaceTB/SmolLM2-360M-Instruct",
|
|
17
29
|
name: "SmolLM2 360M",
|
|
18
30
|
params: "360M",
|
|
19
31
|
sizeBytes: 723_674_912,
|
|
20
|
-
note: "
|
|
32
|
+
note: "Quick, short answers.",
|
|
33
|
+
sampling: SMOLLM2,
|
|
21
34
|
},
|
|
22
35
|
{
|
|
23
36
|
repo: "LiquidAI/LFM2.5-350M",
|
|
24
37
|
name: "LFM2.5 350M",
|
|
25
38
|
params: "350M",
|
|
26
39
|
sizeBytes: 708_984_464,
|
|
27
|
-
note: "
|
|
40
|
+
note: "Best small model here; follows a conversation well.",
|
|
41
|
+
sampling: LFM2,
|
|
28
42
|
},
|
|
29
43
|
{
|
|
30
44
|
repo: "Qwen/Qwen3-0.6B",
|
|
@@ -33,14 +47,17 @@ export const CURATED_MODELS = [
|
|
|
33
47
|
sizeBytes: 1_503_300_328,
|
|
34
48
|
note: "Can think step by step.",
|
|
35
49
|
thinking: true,
|
|
50
|
+
thinksByDefault: true,
|
|
51
|
+
sampling: QWEN3,
|
|
36
52
|
},
|
|
37
53
|
{
|
|
38
54
|
repo: "Qwen/Qwen3.5-0.8B",
|
|
39
55
|
name: "Qwen3.5 0.8B",
|
|
40
56
|
params: "0.8B",
|
|
41
57
|
sizeBytes: 1_746_942_600,
|
|
42
|
-
note: "
|
|
58
|
+
note: "Strong answers for its size, best on WebGPU. Thinks when asked.",
|
|
43
59
|
thinking: true,
|
|
60
|
+
sampling: QWEN3_5,
|
|
44
61
|
},
|
|
45
62
|
{
|
|
46
63
|
repo: "LiquidAI/LFM3-1.7B",
|
|
@@ -49,5 +66,32 @@ export const CURATED_MODELS = [
|
|
|
49
66
|
sizeBytes: 3_457_635_448,
|
|
50
67
|
note: "Strongest here, best on WebGPU. Thinks by default.",
|
|
51
68
|
thinking: true,
|
|
69
|
+
thinksByDefault: true,
|
|
70
|
+
sampling: LFM3,
|
|
52
71
|
},
|
|
53
72
|
];
|
|
73
|
+
/** The entry of {@link CURATED_MODELS} for a repository id (case-insensitive), if any. */
|
|
74
|
+
export function curatedModel(repo) {
|
|
75
|
+
if (repo === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
const id = repo.toLowerCase();
|
|
78
|
+
return CURATED_MODELS.find((m) => m.repo.toLowerCase() === id);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The sampling a model card recommends for a checkpoint, with or without
|
|
82
|
+
* reasoning (`think` unset: the model's default), or `undefined` when there
|
|
83
|
+
* is none (its `generation_config.json` then applies). `checkpoint` is a
|
|
84
|
+
* repository id, or what identifies a checkpoint: the curated repositories
|
|
85
|
+
* use their card's settings whatever their `generation_config.json` says;
|
|
86
|
+
* other checkpoints of the same families (`model_type` `qwen3`, `qwen3_5`,
|
|
87
|
+
* `lfm2`, `lfm3`) use their family's when their `generation_config.json`
|
|
88
|
+
* does not ask for sampling. The table is the Rust engine's, so the
|
|
89
|
+
* command-line tool and the server pick the same settings. Generations
|
|
90
|
+
* start from it: options a call sets override the matching fields, and
|
|
91
|
+
* `temperature: 0` (greedy decoding) turns it off.
|
|
92
|
+
*/
|
|
93
|
+
export function recommendedSampling(checkpoint, think) {
|
|
94
|
+
const traits = typeof checkpoint === "string" || checkpoint === undefined ? { repo: checkpoint } : checkpoint;
|
|
95
|
+
const set = samplingSet(traits);
|
|
96
|
+
return set === undefined ? undefined : settingsFor(set, think);
|
|
97
|
+
}
|
package/dist/engine.d.ts
CHANGED
|
@@ -9,14 +9,34 @@
|
|
|
9
9
|
* A model keeps reading its source after the load: applying or removing a
|
|
10
10
|
* LoRA adapter reads the affected base matrices again. Reads of a `fetch`
|
|
11
11
|
* source are forwarded to the page under the request being served.
|
|
12
|
+
*
|
|
13
|
+
* In Node, a model runs on the native engine (the Node-API addon, downloaded on first use
|
|
14
|
+
* and verified, see `native.ts`) when it is available, the source is a hub model and `backend` allows it; otherwise
|
|
15
|
+
* on the WebAssembly engine. Both take the same options and report the same
|
|
16
|
+
* descriptions: the requests below are served the same way for both.
|
|
12
17
|
*/
|
|
13
|
-
import
|
|
14
|
-
import type {
|
|
18
|
+
import { type CacheStore } from "./cache/index.js";
|
|
19
|
+
import type { Request, Response, WireSource } from "./protocol.js";
|
|
20
|
+
import type { NativeAddon, NativeModelInfo } from "./native.js";
|
|
21
|
+
import type { Activations, Backend, CpuInfo, ModelInfo } from "./types.js";
|
|
15
22
|
import { type FlavourBindings, type WasmFlavour } from "./wasm-flavour.js";
|
|
16
23
|
/** How the engine talks back to the page. */
|
|
17
24
|
export interface EngineHost {
|
|
18
25
|
post(message: Response, transfer?: Transferable[]): void;
|
|
19
26
|
}
|
|
27
|
+
type Reader = (path: string, start?: number, end?: number) => Promise<Uint8Array | null>;
|
|
28
|
+
/** A source opened for the engine: reads, and what is known of its files. */
|
|
29
|
+
interface OpenedSource {
|
|
30
|
+
readonly read: Reader;
|
|
31
|
+
readonly list?: string[];
|
|
32
|
+
readonly sizes: Map<string, number>;
|
|
33
|
+
readonly hashes: Map<string, string>;
|
|
34
|
+
readonly repo?: string;
|
|
35
|
+
readonly revision?: string;
|
|
36
|
+
readonly fromCache: boolean;
|
|
37
|
+
/** The store a hub checkpoint was downloaded to. */
|
|
38
|
+
readonly store?: CacheStore;
|
|
39
|
+
}
|
|
20
40
|
/** The instantiated engine: its bindings and how it runs. */
|
|
21
41
|
export interface EngineWasm {
|
|
22
42
|
readonly bindings: FlavourBindings;
|
|
@@ -42,8 +62,9 @@ export interface EngineWasmOptions {
|
|
|
42
62
|
*/
|
|
43
63
|
export declare function initEngineWasm(options?: EngineWasmOptions): Promise<EngineWasm>;
|
|
44
64
|
/**
|
|
45
|
-
* Human-readable CPU backend, e.g. `"CPU (wasm, relaxed SIMD, 8 threads)"
|
|
46
|
-
* `"CPU (wasm, SIMD128, 1 thread, deterministic, f32 activations)"
|
|
65
|
+
* Human-readable CPU backend, e.g. `"CPU (wasm, relaxed SIMD, 8 threads)"`,
|
|
66
|
+
* `"CPU (wasm, SIMD128, 1 thread, deterministic, f32 activations)"` or
|
|
67
|
+
* `"CPU (native, neon-i8mm, 10 threads)"`.
|
|
47
68
|
*/
|
|
48
69
|
export declare function describeCpu(cpu: CpuInfo, activations?: Activations): string;
|
|
49
70
|
export declare class Engine {
|
|
@@ -52,3 +73,11 @@ export declare class Engine {
|
|
|
52
73
|
/** Handles one message from the page. Answers are posted through the host. */
|
|
53
74
|
handle(request: Request): void;
|
|
54
75
|
}
|
|
76
|
+
/** The engine `backend` picks for `source`: the native addon, or why not. */
|
|
77
|
+
export declare function chooseNative(backend: Backend, source: WireSource, wasmFlavour?: WasmFlavour, cacheDir?: string): Promise<{
|
|
78
|
+
readonly addon?: NativeAddon;
|
|
79
|
+
readonly note?: string;
|
|
80
|
+
}>;
|
|
81
|
+
/** The {@link ModelInfo} of a model on the native engine. */
|
|
82
|
+
export declare function nativeModelInfo(raw: NativeModelInfo, opened: Pick<OpenedSource, "repo" | "revision" | "hashes" | "sizes" | "fromCache">, adapter: Pick<OpenedSource, "repo" | "revision"> | undefined, loadTimeMs: number): ModelInfo;
|
|
83
|
+
export {};
|