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
|
@@ -17,6 +17,21 @@ export class JsSource {
|
|
|
17
17
|
constructor(read: Function, list?: Function | null);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The converted-weight file of one model load (see the module docs).
|
|
22
|
+
*/
|
|
23
|
+
export class JsWeightCache {
|
|
24
|
+
free(): void;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
26
|
+
/**
|
|
27
|
+
* `key` names the converted checkpoint (`"org/name@sha"`; the load
|
|
28
|
+
* format is appended). `read(start, end)` resolves to bytes
|
|
29
|
+
* `[start, end)` of the stored file of `size` bytes (`0`: none);
|
|
30
|
+
* `write(chunk)` appends to the new file and may return a promise.
|
|
31
|
+
*/
|
|
32
|
+
constructor(key: string, size: number, read: Function, write: Function);
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
/**
|
|
21
36
|
* Incremental SHA-256.
|
|
22
37
|
*/
|
|
@@ -43,8 +58,8 @@ export class WasmModel {
|
|
|
43
58
|
free(): void;
|
|
44
59
|
[Symbol.dispose](): void;
|
|
45
60
|
/**
|
|
46
|
-
*
|
|
47
|
-
* replacing the adapter applied before (if any). `options_json`:
|
|
61
|
+
* Applies a PEFT LoRA adapter served by `lora` (in the model's
|
|
62
|
+
* `adapterMode`), replacing the adapter applied before (if any). `options_json`:
|
|
48
63
|
* `{ scale?: number }` (default 1). Resolves to the adapter's
|
|
49
64
|
* description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
|
|
50
65
|
* leaving the model unchanged, when the adapter does not fit the
|
|
@@ -77,7 +92,8 @@ export class WasmModel {
|
|
|
77
92
|
* Loads a checkpoint from `source`. `options_json` is a JSON object:
|
|
78
93
|
* `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
|
|
79
94
|
* contextLength?: number, deterministic?: boolean,
|
|
80
|
-
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto"
|
|
95
|
+
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
|
|
96
|
+
* adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
|
|
81
97
|
*
|
|
82
98
|
* `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
|
|
83
99
|
* is available and the model has more than
|
|
@@ -87,10 +103,17 @@ export class WasmModel {
|
|
|
87
103
|
* results depend on the adapter.
|
|
88
104
|
*
|
|
89
105
|
* `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
|
|
90
|
-
* and `adapter_model.safetensors`)
|
|
91
|
-
*
|
|
106
|
+
* and `adapter_model.safetensors`) applied at load, at `adapterScale`
|
|
107
|
+
* (default 1), in `adapterMode` (default `"unmerged"`: its delta is
|
|
108
|
+
* added in f32 beside the weights; `"merged"` merges it into the
|
|
109
|
+
* weights as they load).
|
|
110
|
+
*
|
|
111
|
+
* `weightCache`, when given, keeps the converted (block-quantized)
|
|
112
|
+
* weights: a valid stored file serves them instead of converting the
|
|
113
|
+
* checkpoint, else they are written to it as they are converted;
|
|
114
|
+
* `info().weightCache` says which (see [`WeightCacheOutcome`]).
|
|
92
115
|
*/
|
|
93
|
-
static load(source: JsSource, options_json: string, lora?: JsSource | null): Promise<WasmModel>;
|
|
116
|
+
static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
|
|
94
117
|
/**
|
|
95
118
|
* Removes the adapter, restoring the base weights exactly. Resolves to
|
|
96
119
|
* the description of the adapter removed, or `null` when there was
|
|
@@ -248,11 +271,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
248
271
|
export interface InitOutput {
|
|
249
272
|
readonly memory: WebAssembly.Memory;
|
|
250
273
|
readonly __wbg_jssource_free: (a: number, b: number) => void;
|
|
274
|
+
readonly __wbg_jsweightcache_free: (a: number, b: number) => void;
|
|
251
275
|
readonly __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
252
276
|
readonly __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
253
277
|
readonly __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
254
278
|
readonly buildInfo: () => [number, number, number];
|
|
255
279
|
readonly jssource_new: (a: any, b: number) => number;
|
|
280
|
+
readonly jsweightcache_new: (a: number, b: number, c: number, d: any, e: any) => number;
|
|
256
281
|
readonly parseSafetensorsHeader: (a: number, b: number) => [number, number, number];
|
|
257
282
|
readonly sha256hasher_finish: (a: number) => [number, number];
|
|
258
283
|
readonly sha256hasher_new: () => number;
|
|
@@ -265,7 +290,7 @@ export interface InitOutput {
|
|
|
265
290
|
readonly wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
266
291
|
readonly wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
267
292
|
readonly wasmmodel_info: (a: number) => [number, number, number];
|
|
268
|
-
readonly wasmmodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
293
|
+
readonly wasmmodel_load: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
269
294
|
readonly wasmmodel_removeAdapter: (a: number) => any;
|
|
270
295
|
readonly wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
271
296
|
readonly wasmmodel_reset: (a: number) => [number, number];
|
|
@@ -286,10 +311,10 @@ export interface InitOutput {
|
|
|
286
311
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___js_sys_56365fc49d784db6___Function_fn_wasm_bindgen_8cf186fa7724d16d___JsValue_____wasm_bindgen_8cf186fa7724d16d___sys__Undefined___js_sys_56365fc49d784db6___Function_fn_wasm_bindgen_8cf186fa7724d16d___JsValue_____wasm_bindgen_8cf186fa7724d16d___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
287
312
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
288
313
|
readonly 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_: (a: number, b: number, c: any) => [number, number];
|
|
289
|
-
readonly 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__37: (a: number, b: number, c: any) => [number, number];
|
|
290
314
|
readonly 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: (a: number, b: number, c: any) => [number, number];
|
|
315
|
+
readonly 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: (a: number, b: number, c: any) => [number, number];
|
|
291
316
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_: (a: number, b: number, c: any) => void;
|
|
292
|
-
readonly
|
|
317
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37: (a: number, b: number, c: any) => void;
|
|
293
318
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
294
319
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
295
320
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/wasm/simd/webslm_wasm.js
CHANGED
|
@@ -34,6 +34,41 @@ export class JsSource {
|
|
|
34
34
|
}
|
|
35
35
|
if (Symbol.dispose) JsSource.prototype[Symbol.dispose] = JsSource.prototype.free;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The converted-weight file of one model load (see the module docs).
|
|
39
|
+
*/
|
|
40
|
+
export class JsWeightCache {
|
|
41
|
+
__destroy_into_raw() {
|
|
42
|
+
const ptr = this.__wbg_ptr;
|
|
43
|
+
this.__wbg_ptr = 0;
|
|
44
|
+
JsWeightCacheFinalization.unregister(this);
|
|
45
|
+
return ptr;
|
|
46
|
+
}
|
|
47
|
+
free() {
|
|
48
|
+
const ptr = this.__destroy_into_raw();
|
|
49
|
+
wasm.__wbg_jsweightcache_free(ptr, 0);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `key` names the converted checkpoint (`"org/name@sha"`; the load
|
|
53
|
+
* format is appended). `read(start, end)` resolves to bytes
|
|
54
|
+
* `[start, end)` of the stored file of `size` bytes (`0`: none);
|
|
55
|
+
* `write(chunk)` appends to the new file and may return a promise.
|
|
56
|
+
* @param {string} key
|
|
57
|
+
* @param {number} size
|
|
58
|
+
* @param {Function} read
|
|
59
|
+
* @param {Function} write
|
|
60
|
+
*/
|
|
61
|
+
constructor(key, size, read, write) {
|
|
62
|
+
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
63
|
+
const len0 = WASM_VECTOR_LEN;
|
|
64
|
+
const ret = wasm.jsweightcache_new(ptr0, len0, size, read, write);
|
|
65
|
+
this.__wbg_ptr = ret;
|
|
66
|
+
JsWeightCacheFinalization.register(this, this.__wbg_ptr, this);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (Symbol.dispose) JsWeightCache.prototype[Symbol.dispose] = JsWeightCache.prototype.free;
|
|
71
|
+
|
|
37
72
|
/**
|
|
38
73
|
* Incremental SHA-256.
|
|
39
74
|
*/
|
|
@@ -104,8 +139,8 @@ export class WasmModel {
|
|
|
104
139
|
wasm.__wbg_wasmmodel_free(ptr, 0);
|
|
105
140
|
}
|
|
106
141
|
/**
|
|
107
|
-
*
|
|
108
|
-
* replacing the adapter applied before (if any). `options_json`:
|
|
142
|
+
* Applies a PEFT LoRA adapter served by `lora` (in the model's
|
|
143
|
+
* `adapterMode`), replacing the adapter applied before (if any). `options_json`:
|
|
109
144
|
* `{ scale?: number }` (default 1). Resolves to the adapter's
|
|
110
145
|
* description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
|
|
111
146
|
* leaving the model unchanged, when the adapter does not fit the
|
|
@@ -208,7 +243,8 @@ export class WasmModel {
|
|
|
208
243
|
* Loads a checkpoint from `source`. `options_json` is a JSON object:
|
|
209
244
|
* `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
|
|
210
245
|
* contextLength?: number, deterministic?: boolean,
|
|
211
|
-
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto"
|
|
246
|
+
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
|
|
247
|
+
* adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
|
|
212
248
|
*
|
|
213
249
|
* `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
|
|
214
250
|
* is available and the model has more than
|
|
@@ -218,14 +254,22 @@ export class WasmModel {
|
|
|
218
254
|
* results depend on the adapter.
|
|
219
255
|
*
|
|
220
256
|
* `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
|
|
221
|
-
* and `adapter_model.safetensors`)
|
|
222
|
-
*
|
|
257
|
+
* and `adapter_model.safetensors`) applied at load, at `adapterScale`
|
|
258
|
+
* (default 1), in `adapterMode` (default `"unmerged"`: its delta is
|
|
259
|
+
* added in f32 beside the weights; `"merged"` merges it into the
|
|
260
|
+
* weights as they load).
|
|
261
|
+
*
|
|
262
|
+
* `weightCache`, when given, keeps the converted (block-quantized)
|
|
263
|
+
* weights: a valid stored file serves them instead of converting the
|
|
264
|
+
* checkpoint, else they are written to it as they are converted;
|
|
265
|
+
* `info().weightCache` says which (see [`WeightCacheOutcome`]).
|
|
223
266
|
* @param {JsSource} source
|
|
224
267
|
* @param {string} options_json
|
|
225
268
|
* @param {JsSource | null} [lora]
|
|
269
|
+
* @param {JsWeightCache | null} [weight_cache]
|
|
226
270
|
* @returns {Promise<WasmModel>}
|
|
227
271
|
*/
|
|
228
|
-
static load(source, options_json, lora) {
|
|
272
|
+
static load(source, options_json, lora, weight_cache) {
|
|
229
273
|
_assertClass(source, JsSource);
|
|
230
274
|
var ptr0 = source.__destroy_into_raw();
|
|
231
275
|
const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -235,7 +279,12 @@ export class WasmModel {
|
|
|
235
279
|
_assertClass(lora, JsSource);
|
|
236
280
|
ptr2 = lora.__destroy_into_raw();
|
|
237
281
|
}
|
|
238
|
-
|
|
282
|
+
let ptr3 = 0;
|
|
283
|
+
if (!isLikeNone(weight_cache)) {
|
|
284
|
+
_assertClass(weight_cache, JsWeightCache);
|
|
285
|
+
ptr3 = weight_cache.__destroy_into_raw();
|
|
286
|
+
}
|
|
287
|
+
const ret = wasm.wasmmodel_load(ptr0, ptr1, len1, ptr2, ptr3);
|
|
239
288
|
return ret;
|
|
240
289
|
}
|
|
241
290
|
/**
|
|
@@ -1035,6 +1084,10 @@ function __wbg_get_imports() {
|
|
|
1035
1084
|
const ret = new Float32Array(getArrayF32FromWasm0(arg0, arg1));
|
|
1036
1085
|
return ret;
|
|
1037
1086
|
},
|
|
1087
|
+
__wbg_new_from_slice_4ee02165f9de919e: function(arg0, arg1) {
|
|
1088
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
1089
|
+
return ret;
|
|
1090
|
+
},
|
|
1038
1091
|
__wbg_new_typed_6f8b0d724fe26c07: function(arg0, arg1) {
|
|
1039
1092
|
try {
|
|
1040
1093
|
var state0 = {a: arg0, b: arg1};
|
|
@@ -1371,33 +1424,33 @@ function __wbg_get_imports() {
|
|
|
1371
1424
|
arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
|
|
1372
1425
|
}, arguments); },
|
|
1373
1426
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
1374
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
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`.
|
|
1375
1428
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_);
|
|
1376
1429
|
return ret;
|
|
1377
1430
|
},
|
|
1378
1431
|
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
1379
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx:
|
|
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`.
|
|
1380
1433
|
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_);
|
|
1381
1434
|
return ret;
|
|
1382
1435
|
},
|
|
1383
1436
|
__wbindgen_generic_0000000000000003: function(arg0, arg1) {
|
|
1384
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx:
|
|
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`.
|
|
1385
1438
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_);
|
|
1386
1439
|
return ret;
|
|
1387
1440
|
},
|
|
1388
1441
|
__wbindgen_generic_0000000000000004: function(arg0, arg1) {
|
|
1389
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx:
|
|
1390
|
-
const ret = makeMutClosure(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`.
|
|
1443
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37);
|
|
1391
1444
|
return ret;
|
|
1392
1445
|
},
|
|
1393
1446
|
__wbindgen_generic_0000000000000005: function(arg0, arg1) {
|
|
1394
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx:
|
|
1395
|
-
const ret = makeMutClosure(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`.
|
|
1448
|
+
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);
|
|
1396
1449
|
return ret;
|
|
1397
1450
|
},
|
|
1398
1451
|
__wbindgen_generic_0000000000000006: function(arg0, arg1) {
|
|
1399
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx:
|
|
1400
|
-
const ret = makeMutClosure(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`.
|
|
1453
|
+
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);
|
|
1401
1454
|
return ret;
|
|
1402
1455
|
},
|
|
1403
1456
|
__wbindgen_generic_0000000000000007: function(arg0) {
|
|
@@ -1440,8 +1493,8 @@ function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_549
|
|
|
1440
1493
|
wasm.wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_(arg0, arg1, arg2);
|
|
1441
1494
|
}
|
|
1442
1495
|
|
|
1443
|
-
function
|
|
1444
|
-
wasm.
|
|
1496
|
+
function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37(arg0, arg1, arg2) {
|
|
1497
|
+
wasm.wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37(arg0, arg1, arg2);
|
|
1445
1498
|
}
|
|
1446
1499
|
|
|
1447
1500
|
function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_(arg0, arg1, arg2) {
|
|
@@ -1458,15 +1511,15 @@ function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bin
|
|
|
1458
1511
|
}
|
|
1459
1512
|
}
|
|
1460
1513
|
|
|
1461
|
-
function
|
|
1462
|
-
const ret = wasm.
|
|
1514
|
+
function 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(arg0, arg1, arg2) {
|
|
1515
|
+
const ret = wasm.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(arg0, arg1, arg2);
|
|
1463
1516
|
if (ret[1]) {
|
|
1464
1517
|
throw takeFromExternrefTable0(ret[0]);
|
|
1465
1518
|
}
|
|
1466
1519
|
}
|
|
1467
1520
|
|
|
1468
|
-
function
|
|
1469
|
-
const ret = wasm.
|
|
1521
|
+
function 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(arg0, arg1, arg2) {
|
|
1522
|
+
const ret = wasm.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(arg0, arg1, arg2);
|
|
1470
1523
|
if (ret[1]) {
|
|
1471
1524
|
throw takeFromExternrefTable0(ret[0]);
|
|
1472
1525
|
}
|
|
@@ -1508,6 +1561,9 @@ const __wbindgen_enum_GpuTextureViewDimension = ["1d", "2d", "2d-array", "cube",
|
|
|
1508
1561
|
const JsSourceFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1509
1562
|
? { register: () => {}, unregister: () => {} }
|
|
1510
1563
|
: new FinalizationRegistry(ptr => wasm.__wbg_jssource_free(ptr, 1));
|
|
1564
|
+
const JsWeightCacheFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1565
|
+
? { register: () => {}, unregister: () => {} }
|
|
1566
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_jsweightcache_free(ptr, 1));
|
|
1511
1567
|
const Sha256HasherFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1512
1568
|
? { register: () => {}, unregister: () => {} }
|
|
1513
1569
|
: new FinalizationRegistry(ptr => wasm.__wbg_sha256hasher_free(ptr, 1));
|
|
Binary file
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_jssource_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_jsweightcache_free: (a: number, b: number) => void;
|
|
5
6
|
export const __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
6
7
|
export const __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
7
8
|
export const __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
8
9
|
export const buildInfo: () => [number, number, number];
|
|
9
10
|
export const jssource_new: (a: any, b: number) => number;
|
|
11
|
+
export const jsweightcache_new: (a: number, b: number, c: number, d: any, e: any) => number;
|
|
10
12
|
export const parseSafetensorsHeader: (a: number, b: number) => [number, number, number];
|
|
11
13
|
export const sha256hasher_finish: (a: number) => [number, number];
|
|
12
14
|
export const sha256hasher_new: () => number;
|
|
@@ -19,7 +21,7 @@ export const wasmmodel_createSession: (a: number) => [number, number, number];
|
|
|
19
21
|
export const wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
20
22
|
export const wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
21
23
|
export const wasmmodel_info: (a: number) => [number, number, number];
|
|
22
|
-
export const wasmmodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
24
|
+
export const wasmmodel_load: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
23
25
|
export const wasmmodel_removeAdapter: (a: number) => any;
|
|
24
26
|
export const wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
25
27
|
export const wasmmodel_reset: (a: number) => [number, number];
|
|
@@ -40,10 +42,10 @@ export const wasmsession_truncate: (a: number, b: number) => [number, number];
|
|
|
40
42
|
export const wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___js_sys_56365fc49d784db6___Function_fn_wasm_bindgen_8cf186fa7724d16d___JsValue_____wasm_bindgen_8cf186fa7724d16d___sys__Undefined___js_sys_56365fc49d784db6___Function_fn_wasm_bindgen_8cf186fa7724d16d___JsValue_____wasm_bindgen_8cf186fa7724d16d___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
41
43
|
export const wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
42
44
|
export const 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_: (a: number, b: number, c: any) => [number, number];
|
|
43
|
-
export const 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__37: (a: number, b: number, c: any) => [number, number];
|
|
44
45
|
export const 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: (a: number, b: number, c: any) => [number, number];
|
|
46
|
+
export const 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: (a: number, b: number, c: any) => [number, number];
|
|
45
47
|
export const wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_: (a: number, b: number, c: any) => void;
|
|
46
|
-
export const
|
|
48
|
+
export const wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__37: (a: number, b: number, c: any) => void;
|
|
47
49
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
48
50
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
49
51
|
export const __wbindgen_exn_store: (a: number) => void;
|
|
@@ -17,6 +17,21 @@ export class JsSource {
|
|
|
17
17
|
constructor(read: Function, list?: Function | null);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The converted-weight file of one model load (see the module docs).
|
|
22
|
+
*/
|
|
23
|
+
export class JsWeightCache {
|
|
24
|
+
free(): void;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
26
|
+
/**
|
|
27
|
+
* `key` names the converted checkpoint (`"org/name@sha"`; the load
|
|
28
|
+
* format is appended). `read(start, end)` resolves to bytes
|
|
29
|
+
* `[start, end)` of the stored file of `size` bytes (`0`: none);
|
|
30
|
+
* `write(chunk)` appends to the new file and may return a promise.
|
|
31
|
+
*/
|
|
32
|
+
constructor(key: string, size: number, read: Function, write: Function);
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
/**
|
|
21
36
|
* Incremental SHA-256.
|
|
22
37
|
*/
|
|
@@ -43,8 +58,8 @@ export class WasmModel {
|
|
|
43
58
|
free(): void;
|
|
44
59
|
[Symbol.dispose](): void;
|
|
45
60
|
/**
|
|
46
|
-
*
|
|
47
|
-
* replacing the adapter applied before (if any). `options_json`:
|
|
61
|
+
* Applies a PEFT LoRA adapter served by `lora` (in the model's
|
|
62
|
+
* `adapterMode`), replacing the adapter applied before (if any). `options_json`:
|
|
48
63
|
* `{ scale?: number }` (default 1). Resolves to the adapter's
|
|
49
64
|
* description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
|
|
50
65
|
* leaving the model unchanged, when the adapter does not fit the
|
|
@@ -77,7 +92,8 @@ export class WasmModel {
|
|
|
77
92
|
* Loads a checkpoint from `source`. `options_json` is a JSON object:
|
|
78
93
|
* `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
|
|
79
94
|
* contextLength?: number, deterministic?: boolean,
|
|
80
|
-
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto"
|
|
95
|
+
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
|
|
96
|
+
* adapterScale?: number, adapterMode?: "unmerged" | "merged" }`.
|
|
81
97
|
*
|
|
82
98
|
* `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
|
|
83
99
|
* is available and the model has more than
|
|
@@ -87,10 +103,17 @@ export class WasmModel {
|
|
|
87
103
|
* results depend on the adapter.
|
|
88
104
|
*
|
|
89
105
|
* `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
|
|
90
|
-
* and `adapter_model.safetensors`)
|
|
91
|
-
*
|
|
106
|
+
* and `adapter_model.safetensors`) applied at load, at `adapterScale`
|
|
107
|
+
* (default 1), in `adapterMode` (default `"unmerged"`: its delta is
|
|
108
|
+
* added in f32 beside the weights; `"merged"` merges it into the
|
|
109
|
+
* weights as they load).
|
|
110
|
+
*
|
|
111
|
+
* `weightCache`, when given, keeps the converted (block-quantized)
|
|
112
|
+
* weights: a valid stored file serves them instead of converting the
|
|
113
|
+
* checkpoint, else they are written to it as they are converted;
|
|
114
|
+
* `info().weightCache` says which (see [`WeightCacheOutcome`]).
|
|
92
115
|
*/
|
|
93
|
-
static load(source: JsSource, options_json: string, lora?: JsSource | null): Promise<WasmModel>;
|
|
116
|
+
static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
|
|
94
117
|
/**
|
|
95
118
|
* Removes the adapter, restoring the base weights exactly. Resolves to
|
|
96
119
|
* the description of the adapter removed, or `null` when there was
|
|
@@ -267,6 +290,7 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
267
290
|
|
|
268
291
|
export interface InitOutput {
|
|
269
292
|
readonly __wbg_jssource_free: (a: number, b: number) => void;
|
|
293
|
+
readonly __wbg_jsweightcache_free: (a: number, b: number) => void;
|
|
270
294
|
readonly __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
271
295
|
readonly __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
272
296
|
readonly __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
@@ -274,6 +298,7 @@ export interface InitOutput {
|
|
|
274
298
|
readonly buildInfo: () => [number, number, number];
|
|
275
299
|
readonly initThreadPool: (a: number) => any;
|
|
276
300
|
readonly jssource_new: (a: any, b: number) => number;
|
|
301
|
+
readonly jsweightcache_new: (a: number, b: number, c: number, d: any, e: any) => number;
|
|
277
302
|
readonly parseSafetensorsHeader: (a: number, b: number) => [number, number, number];
|
|
278
303
|
readonly sha256hasher_finish: (a: number) => [number, number];
|
|
279
304
|
readonly sha256hasher_new: () => number;
|
|
@@ -287,7 +312,7 @@ export interface InitOutput {
|
|
|
287
312
|
readonly wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
288
313
|
readonly wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
289
314
|
readonly wasmmodel_info: (a: number) => [number, number, number];
|
|
290
|
-
readonly wasmmodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
315
|
+
readonly wasmmodel_load: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
291
316
|
readonly wasmmodel_removeAdapter: (a: number) => any;
|
|
292
317
|
readonly wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
293
318
|
readonly wasmmodel_reset: (a: number) => [number, number];
|
|
@@ -312,12 +337,12 @@ export interface InitOutput {
|
|
|
312
337
|
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___js_sys_b608be85a12bc1d0___Function_fn_wasm_bindgen_3c612a990bfab728___JsValue_____wasm_bindgen_3c612a990bfab728___sys__Undefined___js_sys_b608be85a12bc1d0___Function_fn_wasm_bindgen_3c612a990bfab728___JsValue_____wasm_bindgen_3c612a990bfab728___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
313
338
|
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue__core_2b10d7c4e784534e___result__Result_____wasm_bindgen_3c612a990bfab728___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
314
339
|
readonly 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_: (a: number, b: number, c: any) => [number, number];
|
|
315
|
-
readonly 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__45: (a: number, b: number, c: any) => [number, number];
|
|
316
340
|
readonly 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: (a: number, b: number, c: any) => [number, number];
|
|
341
|
+
readonly 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: (a: number, b: number, c: any) => [number, number];
|
|
317
342
|
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___js_sys_b608be85a12bc1d0___futures__task__wait_async_polyfill__MessageEvent______true_: (a: number, b: number, c: any) => void;
|
|
318
343
|
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true_: (a: number, b: number, c: any) => void;
|
|
319
|
-
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true__43: (a: number, b: number, c: any) => void;
|
|
320
344
|
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true__44: (a: number, b: number, c: any) => void;
|
|
345
|
+
readonly wasm_bindgen_3c612a990bfab728___convert__closures_____invoke___wasm_bindgen_3c612a990bfab728___JsValue______true__45: (a: number, b: number, c: any) => void;
|
|
321
346
|
readonly memory: WebAssembly.Memory;
|
|
322
347
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
323
348
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|