webslm 0.3.0 → 0.3.1

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,19 +273,25 @@ type ModelSource =
273
273
  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
274
 
275
275
  ```ts
276
- // Merged as the model loads (also with the simple API: `load(model, { adapter })`).
276
+ // Applied as the model loads (also with the simple API: `load(model, { adapter })`).
277
277
  const model = await loadModel("HuggingFaceTB/SmolLM2-135M-Instruct", {
278
278
  adapter: "user/my-lora",
279
279
  adapterScale: 1, // default
280
+ adapterMode: "unmerged", // default; or "merged"
280
281
  });
281
- model.info().lora; // { modules: ["model.layers.20.self_attn.q_proj", ...], scale, rank, baseModel, repo, revision }
282
+ model.info().lora; // { modules: ["model.layers.20.self_attn.q_proj", ...], scale, rank, mode, baseModel, repo, revision }
282
283
 
283
284
  // Later: swap to another adapter, then back to the base model.
284
285
  await model.applyAdapter({ files: { "adapter_config.json": config, "adapter_model.safetensors": weights } }, { scale: 0.5 });
285
286
  await model.removeAdapter();
286
287
  ```
287
288
 
288
- The adapter is merged into the matrices it targets, `W' = W + (lora_alpha / r) · scale · B·A` (`lora_alpha / sqrt(r)` with `use_rslora`), in f32 before quantization, so decoding runs at the base model's speed. `target_modules` (names, a regular expression or `"all-linear"`), `exclude_modules`, `layers_to_transform`, `layers_pattern`, `rank_pattern` and `alpha_pattern` are honoured. `applyAdapter` reads the affected base matrices again from the model's source (the cache for Hub models; a `fetch` source is called again) and replaces the previous adapter; `removeAdapter` restores the base weights 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
+ 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:
290
+
291
+ - `"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).
292
+ - `"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).
293
+
294
+ `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
295
 
290
296
  ## Low-level sessions
291
297
 
@@ -370,7 +376,7 @@ export default defineConfig({
370
376
  });
371
377
  ```
372
378
 
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.3.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>.
379
+ 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.3.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>.
374
380
 
375
381
  ## Errors
376
382
 
package/dist/engine.js CHANGED
@@ -366,6 +366,7 @@ export class Engine {
366
366
  ...(options.deterministic === true ? { deterministic: true } : {}),
367
367
  ...(options.activations === undefined ? {} : { activations: options.activations }),
368
368
  ...(options.adapterScale === undefined ? {} : { adapterScale: options.adapterScale }),
369
+ ...(options.adapterMode === undefined ? {} : { adapterMode: options.adapterMode }),
369
370
  }), adapter === undefined ? undefined : this.#jsSource(adapter, active, () => { }, engine.bindings).source);
370
371
  if (signal.aborted) {
371
372
  wasm.free();
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ import type { SafetensorsHeader } from "./safetensors.js";
18
18
  export { ask, DEFAULT_MAX_TOKENS, DEFAULT_MODEL, DEFAULT_TEMPERATURE, load, splitReasoning, stream, unloadAll, type Answer, type AskOptions, type Chat, type ChatOptions, type ChatTurnOptions, type LLM, type PromptOptions, type SharedAskOptions, type SharedStreamOptions, type TextStream, } from "./simple.js";
19
19
  export { detectCapabilities, getWebGpuAdapterSummary, type Capabilities, type CapabilityEnvironment, type GpuAdapterLike, type GpuLike, type WebGpuAdapterSummary, } from "./capabilities.js";
20
20
  export { createEngine, EngineHandle, loadModel, Model, MODEL_FAMILIES, Session, type ModelFamily, } from "./models.js";
21
- export type { Activations, AdapterSource, ApplyAdapterOptions, ChatMessage, ChatStream, GeneratedToken, CpuInfo, CompletionOptions, Device, FetchFile, FileData, FinishReason, GenerateOptions, GenerationConfig, GenerationResult, LoadedFile, LoadModelOptions, LoadProgress, LoraInfo, ModelInfo, ModelSource, Quant, ScoreOptions, ScoreOutput, StepOptions, } from "./types.js";
21
+ export type { Activations, AdapterMode, AdapterSource, ApplyAdapterOptions, ChatMessage, ChatStream, GeneratedToken, CpuInfo, CompletionOptions, Device, FetchFile, FileData, FinishReason, GenerateOptions, GenerationConfig, GenerationResult, LoadedFile, LoadModelOptions, LoadProgress, LoraInfo, ModelInfo, ModelSource, Quant, ScoreOptions, ScoreOutput, StepOptions, } from "./types.js";
22
22
  export { WebslmError, type WebslmErrorCode } from "./errors.js";
23
23
  export { CURATED_MODELS, type CuratedModel } from "./curated.js";
24
24
  export { checkModel, DEFAULT_HUB_URL, EMBEDDING_REASON, isEmbeddingModel, formatParams, searchModels, SUPPORTED_MODEL_TYPES, type CheckModelOptions, type HubModel, type HubOptions, type ModelCheck, type SearchModelsOptions, } from "./hub.js";
package/dist/models.d.ts CHANGED
@@ -139,11 +139,13 @@ export declare class Model extends Conversation {
139
139
  /** Clears the default session's cache. */
140
140
  reset(): Promise<void>;
141
141
  /**
142
- * Merges a PEFT LoRA adapter (`adapter_config.json` and
143
- * `adapter_model.safetensors`, as published on the Hub) into the weights,
144
- * replacing the adapter applied before, if any. The affected base
145
- * matrices are read again from the model's source and merged in f32
146
- * before quantization: decoding runs at the base model's speed.
142
+ * Applies a PEFT LoRA adapter (`adapter_config.json` and
143
+ * `adapter_model.safetensors`, as published on the Hub), replacing the
144
+ * adapter applied before, if any, in the model's `adapterMode` (see
145
+ * {@link AdapterMode}): unmerged (the default), its small f32 factors are
146
+ * uploaded beside the weights; merged, the affected base matrices are
147
+ * read again from the model's source and merged in f32 before
148
+ * quantization.
147
149
  *
148
150
  * Rejects with `INVALID_ADAPTER`, leaving the model unchanged, when the
149
151
  * adapter does not fit the model (a module it does not have, other
package/dist/models.js CHANGED
@@ -6,6 +6,7 @@ import { autoQuant, getBrowserResources, readCheckpointShapes } from "./fit.js";
6
6
  import { checkModel } from "./hub.js";
7
7
  import { isNode } from "./runtime.js";
8
8
  const QUANTS = ["q8", "q4", "f32"];
9
+ const ADAPTER_MODES = ["unmerged", "merged"];
9
10
  /**
10
11
  * An engine (a worker, or the calling thread) that several models can share
11
12
  * (see {@link LoadModelOptions.engine}): one WebAssembly instance, its memory
@@ -180,6 +181,9 @@ export async function loadModel(source, options = {}) {
180
181
  const normalized = normalizeSource(source, options.revision);
181
182
  const adapter = options.adapter === undefined ? undefined : normalizeAdapterSource(options.adapter);
182
183
  checkScale(options.adapterScale);
184
+ if (options.adapterMode !== undefined && !ADAPTER_MODES.includes(options.adapterMode)) {
185
+ throw new WebslmError("INVALID_ARGUMENT", `adapterMode must be one of ${ADAPTER_MODES.join(", ")}`);
186
+ }
183
187
  if (isAborted(options.signal))
184
188
  throw abortError(options.signal);
185
189
  if (normalized.kind === "hub" && !isNode())
@@ -200,6 +204,7 @@ export async function loadModel(source, options = {}) {
200
204
  quant,
201
205
  device,
202
206
  ...(options.adapterScale === undefined ? {} : { adapterScale: options.adapterScale }),
207
+ ...(options.adapterMode === undefined ? {} : { adapterMode: options.adapterMode }),
203
208
  ...(options.contextLength === undefined ? {} : { contextLength: options.contextLength }),
204
209
  ...(options.cacheDir === undefined ? {} : { cacheDir: options.cacheDir }),
205
210
  ...(options.deterministic === true ? { deterministic: true } : {}),
@@ -539,11 +544,13 @@ export class Model extends Conversation {
539
544
  await this.client.request({ type: "reset", model: this.modelId });
540
545
  }
541
546
  /**
542
- * Merges a PEFT LoRA adapter (`adapter_config.json` and
543
- * `adapter_model.safetensors`, as published on the Hub) into the weights,
544
- * replacing the adapter applied before, if any. The affected base
545
- * matrices are read again from the model's source and merged in f32
546
- * before quantization: decoding runs at the base model's speed.
547
+ * Applies a PEFT LoRA adapter (`adapter_config.json` and
548
+ * `adapter_model.safetensors`, as published on the Hub), replacing the
549
+ * adapter applied before, if any, in the model's `adapterMode` (see
550
+ * {@link AdapterMode}): unmerged (the default), its small f32 factors are
551
+ * uploaded beside the weights; merged, the affected base matrices are
552
+ * read again from the model's source and merged in f32 before
553
+ * quantization.
547
554
  *
548
555
  * Rejects with `INVALID_ADAPTER`, leaving the model unchanged, when the
549
556
  * adapter does not fit the model (a module it does not have, other
@@ -6,7 +6,7 @@
6
6
  * `read` messages. `abort` and `readResult` get no answer.
7
7
  */
8
8
  import type { SerializedError } from "./errors.js";
9
- import type { Activations, FileData, LoadProgress, LoraInfo, ModelInfo } from "./types.js";
9
+ import type { Activations, AdapterMode, FileData, LoadProgress, LoraInfo, ModelInfo } from "./types.js";
10
10
  import type { WasmFlavour } from "./wasm-flavour.js";
11
11
  /** A model source in a form that can be posted to a worker. */
12
12
  export type WireSource = {
@@ -30,6 +30,7 @@ export interface WireLoadOptions {
30
30
  readonly contextLength?: number;
31
31
  /** Scale of the adapter of a `load` request. */
32
32
  readonly adapterScale?: number;
33
+ readonly adapterMode?: AdapterMode;
33
34
  readonly cacheDir?: string;
34
35
  readonly deterministic?: boolean;
35
36
  readonly activations?: Activations;
@@ -72,7 +73,7 @@ type WithId<T> = T & {
72
73
  export type Request = WithId<{
73
74
  readonly type: "load";
74
75
  readonly source: WireSource;
75
- /** A LoRA adapter merged at load. */
76
+ /** A LoRA adapter applied at load. */
76
77
  readonly adapter?: WireSource;
77
78
  readonly options: WireLoadOptions;
78
79
  } | {
package/dist/types.d.ts CHANGED
@@ -15,6 +15,19 @@ export type Quant = "q8" | "q4" | "f32";
15
15
  * dequantizes the weights instead. WebGPU always uses f32 activations.
16
16
  */
17
17
  export type Activations = "quantized" | "f32";
18
+ /**
19
+ * How LoRA adapters run on a model. `"unmerged"` (the default) keeps the
20
+ * adapter beside the weights and adds its delta in f32 (`y = W·x + s·B(A·x)`,
21
+ * PEFT's definition): the weights and the adapter each keep their precision,
22
+ * so `quant: "q8"` with `activations: "f32"` on Q8_0-exact weights gives the
23
+ * logits of `quant: "f32"` with the same adapter bit for bit on the CPU, and
24
+ * applying, swapping or removing an adapter reads no base weights. It costs
25
+ * two small matmuls per adapted layer (a few percent of decode speed on
26
+ * quantized weights). `"merged"` merges the adapter into the weights before
27
+ * they are quantized: no decode cost, but `W + s·B·A` is quantized again,
28
+ * which loses part of the adapter.
29
+ */
30
+ export type AdapterMode = "unmerged" | "merged";
18
31
  /** Checkpoint files held by the page: bytes from OPFS, IndexedDB, an upload, a training job... */
19
32
  export type FileData = Blob | ArrayBuffer | Uint8Array;
20
33
  /**
@@ -58,15 +71,17 @@ export interface ApplyAdapterOptions {
58
71
  readonly onProgress?: (progress: LoadProgress) => void;
59
72
  readonly signal?: AbortSignal;
60
73
  }
61
- /** A LoRA adapter merged into a model's weights. */
74
+ /** A LoRA adapter applied to a model. */
62
75
  export interface LoraInfo {
63
- /** Modules whose weights changed, e.g. `"model.layers.0.self_attn.q_proj"`. */
76
+ /** Adapted modules, e.g. `"model.layers.0.self_attn.q_proj"`. */
64
77
  readonly modules: readonly string[];
65
78
  readonly scale: number;
66
79
  /** Largest rank over the modules. */
67
80
  readonly rank: number;
68
81
  /** `base_model_name_or_path` from `adapter_config.json`. */
69
82
  readonly baseModel?: string;
83
+ /** How the adapter runs (see {@link AdapterMode}). */
84
+ readonly mode: AdapterMode;
70
85
  /** Hub repository id, when the adapter came from the hub. */
71
86
  readonly repo?: string;
72
87
  /** Commit sha of the hub revision, when the adapter came from the hub. */
@@ -124,13 +139,18 @@ export interface LoadModelOptions {
124
139
  /** Largest number of positions a session holds. Defaults to min(4096, model maximum). */
125
140
  readonly contextLength?: number;
126
141
  /**
127
- * A PEFT LoRA adapter merged into the weights as they load (in f32,
128
- * before quantization). It can be swapped or removed later with
129
- * {@link Model.applyAdapter} and {@link Model.removeAdapter}.
142
+ * A PEFT LoRA adapter applied at load, in {@link LoadModelOptions.adapterMode}.
143
+ * It can be swapped or removed later with {@link Model.applyAdapter} and
144
+ * {@link Model.removeAdapter}.
130
145
  */
131
146
  readonly adapter?: AdapterSource;
132
147
  /** Scale of {@link LoadModelOptions.adapter} (default `1`). */
133
148
  readonly adapterScale?: number;
149
+ /**
150
+ * How LoRA adapters run on this model, the one given at load and those
151
+ * applied later (default `"unmerged"`; see {@link AdapterMode}).
152
+ */
153
+ readonly adapterMode?: AdapterMode;
134
154
  readonly onProgress?: (progress: LoadProgress) => void;
135
155
  readonly signal?: AbortSignal;
136
156
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webslm",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",
@@ -43,8 +43,8 @@ export class WasmModel {
43
43
  free(): void;
44
44
  [Symbol.dispose](): void;
45
45
  /**
46
- * Merges a PEFT LoRA adapter served by `lora` into the weights,
47
- * replacing the adapter applied before (if any). `options_json`:
46
+ * Applies a PEFT LoRA adapter served by `lora` (in the model's
47
+ * `adapterMode`), replacing the adapter applied before (if any). `options_json`:
48
48
  * `{ scale?: number }` (default 1). Resolves to the adapter's
49
49
  * description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
50
50
  * leaving the model unchanged, when the adapter does not fit the
@@ -77,7 +77,8 @@ export class WasmModel {
77
77
  * Loads a checkpoint from `source`. `options_json` is a JSON object:
78
78
  * `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
79
79
  * contextLength?: number, deterministic?: boolean,
80
- * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
80
+ * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
81
+ * adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
81
82
  *
82
83
  * `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
83
84
  * is available and the model has more than
@@ -87,8 +88,10 @@ export class WasmModel {
87
88
  * results depend on the adapter.
88
89
  *
89
90
  * `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
90
- * and `adapter_model.safetensors`) merged into the weights as they
91
- * load, at `adapterScale` (default 1).
91
+ * and `adapter_model.safetensors`) applied at load, at `adapterScale`
92
+ * (default 1), in `adapterMode` (default `"unmerged"`: its delta is
93
+ * added in f32 beside the weights; `"merged"` merges it into the
94
+ * weights as they load).
92
95
  */
93
96
  static load(source: JsSource, options_json: string, lora?: JsSource | null): Promise<WasmModel>;
94
97
  /**
@@ -104,8 +104,8 @@ export class WasmModel {
104
104
  wasm.__wbg_wasmmodel_free(ptr, 0);
105
105
  }
106
106
  /**
107
- * Merges a PEFT LoRA adapter served by `lora` into the weights,
108
- * replacing the adapter applied before (if any). `options_json`:
107
+ * Applies a PEFT LoRA adapter served by `lora` (in the model's
108
+ * `adapterMode`), replacing the adapter applied before (if any). `options_json`:
109
109
  * `{ scale?: number }` (default 1). Resolves to the adapter's
110
110
  * description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
111
111
  * leaving the model unchanged, when the adapter does not fit the
@@ -208,7 +208,8 @@ export class WasmModel {
208
208
  * Loads a checkpoint from `source`. `options_json` is a JSON object:
209
209
  * `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
210
210
  * contextLength?: number, deterministic?: boolean,
211
- * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
211
+ * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
212
+ * adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
212
213
  *
213
214
  * `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
214
215
  * is available and the model has more than
@@ -218,8 +219,10 @@ export class WasmModel {
218
219
  * results depend on the adapter.
219
220
  *
220
221
  * `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
221
- * and `adapter_model.safetensors`) merged into the weights as they
222
- * load, at `adapterScale` (default 1).
222
+ * and `adapter_model.safetensors`) applied at load, at `adapterScale`
223
+ * (default 1), in `adapterMode` (default `"unmerged"`: its delta is
224
+ * added in f32 beside the weights; `"merged"` merges it into the
225
+ * weights as they load).
223
226
  * @param {JsSource} source
224
227
  * @param {string} options_json
225
228
  * @param {JsSource | null} [lora]
Binary file
@@ -43,8 +43,8 @@ export class WasmModel {
43
43
  free(): void;
44
44
  [Symbol.dispose](): void;
45
45
  /**
46
- * Merges a PEFT LoRA adapter served by `lora` into the weights,
47
- * replacing the adapter applied before (if any). `options_json`:
46
+ * Applies a PEFT LoRA adapter served by `lora` (in the model's
47
+ * `adapterMode`), replacing the adapter applied before (if any). `options_json`:
48
48
  * `{ scale?: number }` (default 1). Resolves to the adapter's
49
49
  * description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
50
50
  * leaving the model unchanged, when the adapter does not fit the
@@ -77,7 +77,8 @@ export class WasmModel {
77
77
  * Loads a checkpoint from `source`. `options_json` is a JSON object:
78
78
  * `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
79
79
  * contextLength?: number, deterministic?: boolean,
80
- * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
80
+ * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
81
+ * adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
81
82
  *
82
83
  * `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
83
84
  * is available and the model has more than
@@ -87,8 +88,10 @@ export class WasmModel {
87
88
  * results depend on the adapter.
88
89
  *
89
90
  * `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
90
- * and `adapter_model.safetensors`) merged into the weights as they
91
- * load, at `adapterScale` (default 1).
91
+ * and `adapter_model.safetensors`) applied at load, at `adapterScale`
92
+ * (default 1), in `adapterMode` (default `"unmerged"`: its delta is
93
+ * added in f32 beside the weights; `"merged"` merges it into the
94
+ * weights as they load).
92
95
  */
93
96
  static load(source: JsSource, options_json: string, lora?: JsSource | null): Promise<WasmModel>;
94
97
  /**
@@ -104,8 +104,8 @@ export class WasmModel {
104
104
  wasm.__wbg_wasmmodel_free(ptr, 0);
105
105
  }
106
106
  /**
107
- * Merges a PEFT LoRA adapter served by `lora` into the weights,
108
- * replacing the adapter applied before (if any). `options_json`:
107
+ * Applies a PEFT LoRA adapter served by `lora` (in the model's
108
+ * `adapterMode`), replacing the adapter applied before (if any). `options_json`:
109
109
  * `{ scale?: number }` (default 1). Resolves to the adapter's
110
110
  * description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
111
111
  * leaving the model unchanged, when the adapter does not fit the
@@ -208,7 +208,8 @@ export class WasmModel {
208
208
  * Loads a checkpoint from `source`. `options_json` is a JSON object:
209
209
  * `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
210
210
  * contextLength?: number, deterministic?: boolean,
211
- * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
211
+ * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
212
+ * adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
212
213
  *
213
214
  * `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
214
215
  * is available and the model has more than
@@ -218,8 +219,10 @@ export class WasmModel {
218
219
  * results depend on the adapter.
219
220
  *
220
221
  * `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
221
- * and `adapter_model.safetensors`) merged into the weights as they
222
- * load, at `adapterScale` (default 1).
222
+ * and `adapter_model.safetensors`) applied at load, at `adapterScale`
223
+ * (default 1), in `adapterMode` (default `"unmerged"`: its delta is
224
+ * added in f32 beside the weights; `"merged"` merges it into the
225
+ * weights as they load).
223
226
  * @param {JsSource} source
224
227
  * @param {string} options_json
225
228
  * @param {JsSource | null} [lora]
Binary file
@@ -43,8 +43,8 @@ export class WasmModel {
43
43
  free(): void;
44
44
  [Symbol.dispose](): void;
45
45
  /**
46
- * Merges a PEFT LoRA adapter served by `lora` into the weights,
47
- * replacing the adapter applied before (if any). `options_json`:
46
+ * Applies a PEFT LoRA adapter served by `lora` (in the model's
47
+ * `adapterMode`), replacing the adapter applied before (if any). `options_json`:
48
48
  * `{ scale?: number }` (default 1). Resolves to the adapter's
49
49
  * description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
50
50
  * leaving the model unchanged, when the adapter does not fit the
@@ -77,7 +77,8 @@ export class WasmModel {
77
77
  * Loads a checkpoint from `source`. `options_json` is a JSON object:
78
78
  * `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
79
79
  * contextLength?: number, deterministic?: boolean,
80
- * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
80
+ * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
81
+ * adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
81
82
  *
82
83
  * `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
83
84
  * is available and the model has more than
@@ -87,8 +88,10 @@ export class WasmModel {
87
88
  * results depend on the adapter.
88
89
  *
89
90
  * `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
90
- * and `adapter_model.safetensors`) merged into the weights as they
91
- * load, at `adapterScale` (default 1).
91
+ * and `adapter_model.safetensors`) applied at load, at `adapterScale`
92
+ * (default 1), in `adapterMode` (default `"unmerged"`: its delta is
93
+ * added in f32 beside the weights; `"merged"` merges it into the
94
+ * weights as they load).
92
95
  */
93
96
  static load(source: JsSource, options_json: string, lora?: JsSource | null): Promise<WasmModel>;
94
97
  /**
@@ -106,8 +106,8 @@ export class WasmModel {
106
106
  wasm.__wbg_wasmmodel_free(ptr, 0);
107
107
  }
108
108
  /**
109
- * Merges a PEFT LoRA adapter served by `lora` into the weights,
110
- * replacing the adapter applied before (if any). `options_json`:
109
+ * Applies a PEFT LoRA adapter served by `lora` (in the model's
110
+ * `adapterMode`), replacing the adapter applied before (if any). `options_json`:
111
111
  * `{ scale?: number }` (default 1). Resolves to the adapter's
112
112
  * description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
113
113
  * leaving the model unchanged, when the adapter does not fit the
@@ -210,7 +210,8 @@ export class WasmModel {
210
210
  * Loads a checkpoint from `source`. `options_json` is a JSON object:
211
211
  * `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
212
212
  * contextLength?: number, deterministic?: boolean,
213
- * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
213
+ * activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
214
+ * adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
214
215
  *
215
216
  * `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
216
217
  * is available and the model has more than
@@ -220,8 +221,10 @@ export class WasmModel {
220
221
  * results depend on the adapter.
221
222
  *
222
223
  * `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
223
- * and `adapter_model.safetensors`) merged into the weights as they
224
- * load, at `adapterScale` (default 1).
224
+ * and `adapter_model.safetensors`) applied at load, at `adapterScale`
225
+ * (default 1), in `adapterMode` (default `"unmerged"`: its delta is
226
+ * added in f32 beside the weights; `"merged"` merges it into the
227
+ * weights as they load).
225
228
  * @param {JsSource} source
226
229
  * @param {string} options_json
227
230
  * @param {JsSource | null} [lora]
Binary file