webslm 0.6.0 → 0.9.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 +86 -3
- package/dist/ai-sdk/embedding-model.d.ts +52 -0
- package/dist/ai-sdk/embedding-model.js +112 -0
- package/dist/ai-sdk/image-model.d.ts +53 -0
- package/dist/ai-sdk/image-model.js +148 -0
- package/dist/ai-sdk/index.d.ts +39 -0
- package/dist/ai-sdk/index.js +66 -11
- package/dist/client.d.ts +6 -0
- package/dist/client.js +8 -1
- package/dist/download.js +2 -2
- package/dist/engine.js +187 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +1 -0
- package/dist/fit.d.ts +2 -2
- package/dist/fit.js +5 -2
- package/dist/hub.d.ts +38 -3
- package/dist/hub.js +87 -8
- package/dist/image.d.ts +201 -0
- package/dist/image.js +353 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +5 -3
- package/dist/memory.d.ts +24 -7
- package/dist/memory.js +49 -11
- package/dist/models.d.ts +19 -1
- package/dist/models.js +64 -7
- package/dist/native.d.ts +28 -0
- package/dist/protocol.d.ts +79 -2
- package/dist/simple.d.ts +4 -1
- package/dist/simple.js +9 -2
- package/dist/types.d.ts +87 -0
- package/dist/wasm.d.ts +2 -0
- package/native-manifest.json +29 -29
- package/package.json +1 -1
- package/wasm/relaxed/webslm_wasm.d.ts +72 -7
- package/wasm/relaxed/webslm_wasm.js +165 -19
- package/wasm/relaxed/webslm_wasm_bg.wasm +0 -0
- package/wasm/relaxed/webslm_wasm_bg.wasm.d.ts +10 -3
- package/wasm/simd/webslm_wasm.d.ts +72 -7
- package/wasm/simd/webslm_wasm.js +165 -19
- package/wasm/simd/webslm_wasm_bg.wasm +0 -0
- package/wasm/simd/webslm_wasm_bg.wasm.d.ts +10 -3
- package/wasm/threads/webslm_wasm.d.ts +73 -8
- package/wasm/threads/webslm_wasm.js +171 -25
- package/wasm/threads/webslm_wasm_bg.wasm +0 -0
- package/wasm/threads/webslm_wasm_bg.wasm.d.ts +11 -4
|
@@ -49,9 +49,41 @@ export class Sha256Hasher {
|
|
|
49
49
|
update(bytes: Uint8Array): void;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* A loaded text-to-image pipeline.
|
|
54
|
+
*/
|
|
55
|
+
export class WasmImageModel {
|
|
56
|
+
private constructor();
|
|
57
|
+
free(): void;
|
|
58
|
+
[Symbol.dispose](): void;
|
|
59
|
+
/**
|
|
60
|
+
* Generates an image of `prompt`. `options_json`: `{ width?, height?,
|
|
61
|
+
* steps?, guidance?, seed?, negativePrompt? }` (see `ImageOptionsJs`).
|
|
62
|
+
* `on_progress(phase, step, steps)` is called before encoding the
|
|
63
|
+
* prompt, before each denoising step and before decoding; returning
|
|
64
|
+
* `false` stops the generation (it rejects with `"ABORTED"`).
|
|
65
|
+
* Resolves to `{ width, height, seed, rgba: Uint8Array }` (row-major
|
|
66
|
+
* 8-bit RGBA).
|
|
67
|
+
*/
|
|
68
|
+
generate(prompt: string, options_json: string, on_progress?: Function | null): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Describes the pipeline (see [`ImageModelInfo`]).
|
|
71
|
+
*/
|
|
72
|
+
info(): any;
|
|
73
|
+
/**
|
|
74
|
+
* Loads a pipeline from `source`. `options_json`:
|
|
75
|
+
* `{ format?: "f16" | "f32" | "bf16" | "q8" | ..., device?: "cpu" |
|
|
76
|
+
* "webgpu" | "auto" }` (defaults: f16 weights, `auto`). `decoder`,
|
|
77
|
+
* when given, serves a standalone autoencoder (`config.json` and
|
|
78
|
+
* `diffusion_pytorch_model.safetensors`, e.g. `madebyollin/taesd`)
|
|
79
|
+
* that replaces the pipeline's decoder.
|
|
80
|
+
*/
|
|
81
|
+
static load(source: JsSource, options_json: string, decoder?: JsSource | null): Promise<WasmImageModel>;
|
|
82
|
+
}
|
|
83
|
+
|
|
52
84
|
/**
|
|
53
85
|
* A loaded checkpoint, with a default session used by `chat` and
|
|
54
|
-
* `generate`.
|
|
86
|
+
* `generate` (language models), or an encoder answering `embed`.
|
|
55
87
|
*/
|
|
56
88
|
export class WasmModel {
|
|
57
89
|
private constructor();
|
|
@@ -84,6 +116,17 @@ export class WasmModel {
|
|
|
84
116
|
* Decodes token ids into text.
|
|
85
117
|
*/
|
|
86
118
|
detokenize(ids: Uint32Array, skip_special_tokens: boolean): string;
|
|
119
|
+
/**
|
|
120
|
+
* Embeds texts with an encoder. `texts_json` is a JSON array of
|
|
121
|
+
* strings; `options_json`: `{ pooling?: "cls" | "mean" | "max" |
|
|
122
|
+
* "mean_sqrt_len_tokens" | "weightedmean" | "lasttoken", normalize?:
|
|
123
|
+
* boolean }` (defaults: the model's sentence-transformers settings).
|
|
124
|
+
* Resolves to `{ data: Float32Array, dimensions: number, tokens:
|
|
125
|
+
* number[] }`: the vectors one after the other, and the number of
|
|
126
|
+
* tokens read from each text (texts longer than the model's limit are
|
|
127
|
+
* cut). Rejects with `UNSUPPORTED_TASK` on a language model.
|
|
128
|
+
*/
|
|
129
|
+
embed(texts_json: string, options_json: string): Promise<any>;
|
|
87
130
|
/**
|
|
88
131
|
* Completes raw text in the default session; see
|
|
89
132
|
* [`WasmSession::generate`].
|
|
@@ -99,7 +142,8 @@ export class WasmModel {
|
|
|
99
142
|
* contextLength?: number, deterministic?: boolean,
|
|
100
143
|
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
|
|
101
144
|
* adapterScale?: number, adapterMode?: "unmerged" | "merged",
|
|
102
|
-
* vision?: boolean
|
|
145
|
+
* vision?: boolean, kvCache?: "f32" | "int8", kvResidual?: number,
|
|
146
|
+
* kvBudget?: number }` (`vision: false` skips the vision encoder of a
|
|
103
147
|
* vision-language checkpoint).
|
|
104
148
|
*
|
|
105
149
|
* `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
|
|
@@ -125,6 +169,9 @@ export class WasmModel {
|
|
|
125
169
|
* `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
|
|
126
170
|
* `webslm export` checkpoint) loads in its own format, its blocks
|
|
127
171
|
* unchanged; weights already in the load format skip `weightCache`.
|
|
172
|
+
*
|
|
173
|
+
* An encoder loads in f32 unless `format` says otherwise, and takes
|
|
174
|
+
* no `lora`.
|
|
128
175
|
*/
|
|
129
176
|
static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
|
|
130
177
|
/**
|
|
@@ -141,13 +188,18 @@ export class WasmModel {
|
|
|
141
188
|
*/
|
|
142
189
|
renderChat(messages_json: string, kwargs_json: string): string;
|
|
143
190
|
/**
|
|
144
|
-
* Clears the default session.
|
|
191
|
+
* Clears the default session (nothing to clear for an encoder).
|
|
145
192
|
*/
|
|
146
193
|
reset(): void;
|
|
147
194
|
/**
|
|
148
|
-
* Encodes text into token ids
|
|
195
|
+
* Encodes text into token ids (an encoder's tokenizer cuts texts at
|
|
196
|
+
* its limit, as `embed` does).
|
|
149
197
|
*/
|
|
150
198
|
tokenize(text: string, add_special_tokens: boolean): Uint32Array;
|
|
199
|
+
/**
|
|
200
|
+
* Whether the model is an encoder (it answers `embed`, not `chat`).
|
|
201
|
+
*/
|
|
202
|
+
readonly isEncoder: boolean;
|
|
151
203
|
}
|
|
152
204
|
|
|
153
205
|
/**
|
|
@@ -278,6 +330,12 @@ export function buildInfo(): any;
|
|
|
278
330
|
*/
|
|
279
331
|
export function parseSafetensorsHeader(bytes: Uint8Array): any;
|
|
280
332
|
|
|
333
|
+
/**
|
|
334
|
+
* `model_type` values of the encoders this build embeds with (models
|
|
335
|
+
* whose `WasmModel` answers `embed`).
|
|
336
|
+
*/
|
|
337
|
+
export function supportedEncoderTypes(): string[];
|
|
338
|
+
|
|
281
339
|
/**
|
|
282
340
|
* `model_type` values (from `config.json`) of the architectures this build
|
|
283
341
|
* can run.
|
|
@@ -296,6 +354,7 @@ export interface InitOutput {
|
|
|
296
354
|
readonly __wbg_jssource_free: (a: number, b: number) => void;
|
|
297
355
|
readonly __wbg_jsweightcache_free: (a: number, b: number) => void;
|
|
298
356
|
readonly __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
357
|
+
readonly __wbg_wasmimagemodel_free: (a: number, b: number) => void;
|
|
299
358
|
readonly __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
300
359
|
readonly __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
301
360
|
readonly buildInfo: () => [number, number, number];
|
|
@@ -305,15 +364,21 @@ export interface InitOutput {
|
|
|
305
364
|
readonly sha256hasher_finish: (a: number) => [number, number];
|
|
306
365
|
readonly sha256hasher_new: () => number;
|
|
307
366
|
readonly sha256hasher_update: (a: number, b: number, c: number) => void;
|
|
367
|
+
readonly supportedEncoderTypes: () => [number, number];
|
|
308
368
|
readonly supportedModelTypes: () => [number, number];
|
|
309
369
|
readonly version: () => [number, number];
|
|
370
|
+
readonly wasmimagemodel_generate: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
|
|
371
|
+
readonly wasmimagemodel_info: (a: number) => [number, number, number];
|
|
372
|
+
readonly wasmimagemodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
310
373
|
readonly wasmmodel_applyAdapter: (a: number, b: number, c: number, d: number) => any;
|
|
311
374
|
readonly wasmmodel_chat: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
312
375
|
readonly wasmmodel_chatWithMedia: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: any, k: number) => any;
|
|
313
376
|
readonly wasmmodel_createSession: (a: number) => [number, number, number];
|
|
314
377
|
readonly wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
378
|
+
readonly wasmmodel_embed: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
315
379
|
readonly wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
316
380
|
readonly wasmmodel_info: (a: number) => [number, number, number];
|
|
381
|
+
readonly wasmmodel_isEncoder: (a: number) => number;
|
|
317
382
|
readonly wasmmodel_load: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
318
383
|
readonly wasmmodel_removeAdapter: (a: number) => any;
|
|
319
384
|
readonly wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
@@ -336,10 +401,10 @@ export interface InitOutput {
|
|
|
336
401
|
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;
|
|
337
402
|
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];
|
|
338
403
|
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];
|
|
339
|
-
readonly
|
|
340
|
-
readonly
|
|
404
|
+
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__46: (a: number, b: number, c: any) => [number, number];
|
|
405
|
+
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__47: (a: number, b: number, c: any) => [number, number];
|
|
341
406
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_: (a: number, b: number, c: any) => void;
|
|
342
|
-
readonly
|
|
407
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__45: (a: number, b: number, c: any) => void;
|
|
343
408
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
344
409
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
345
410
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/wasm/simd/webslm_wasm.js
CHANGED
|
@@ -117,9 +117,89 @@ export class Sha256Hasher {
|
|
|
117
117
|
}
|
|
118
118
|
if (Symbol.dispose) Sha256Hasher.prototype[Symbol.dispose] = Sha256Hasher.prototype.free;
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* A loaded text-to-image pipeline.
|
|
122
|
+
*/
|
|
123
|
+
export class WasmImageModel {
|
|
124
|
+
static __wrap(ptr) {
|
|
125
|
+
const obj = Object.create(WasmImageModel.prototype);
|
|
126
|
+
obj.__wbg_ptr = ptr;
|
|
127
|
+
WasmImageModelFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
128
|
+
return obj;
|
|
129
|
+
}
|
|
130
|
+
__destroy_into_raw() {
|
|
131
|
+
const ptr = this.__wbg_ptr;
|
|
132
|
+
this.__wbg_ptr = 0;
|
|
133
|
+
WasmImageModelFinalization.unregister(this);
|
|
134
|
+
return ptr;
|
|
135
|
+
}
|
|
136
|
+
free() {
|
|
137
|
+
const ptr = this.__destroy_into_raw();
|
|
138
|
+
wasm.__wbg_wasmimagemodel_free(ptr, 0);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Generates an image of `prompt`. `options_json`: `{ width?, height?,
|
|
142
|
+
* steps?, guidance?, seed?, negativePrompt? }` (see `ImageOptionsJs`).
|
|
143
|
+
* `on_progress(phase, step, steps)` is called before encoding the
|
|
144
|
+
* prompt, before each denoising step and before decoding; returning
|
|
145
|
+
* `false` stops the generation (it rejects with `"ABORTED"`).
|
|
146
|
+
* Resolves to `{ width, height, seed, rgba: Uint8Array }` (row-major
|
|
147
|
+
* 8-bit RGBA).
|
|
148
|
+
* @param {string} prompt
|
|
149
|
+
* @param {string} options_json
|
|
150
|
+
* @param {Function | null} [on_progress]
|
|
151
|
+
* @returns {Promise<any>}
|
|
152
|
+
*/
|
|
153
|
+
generate(prompt, options_json, on_progress) {
|
|
154
|
+
const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
155
|
+
const len0 = WASM_VECTOR_LEN;
|
|
156
|
+
const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
157
|
+
const len1 = WASM_VECTOR_LEN;
|
|
158
|
+
const ret = wasm.wasmimagemodel_generate(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(on_progress) ? 0 : addToExternrefTable0(on_progress));
|
|
159
|
+
return ret;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Describes the pipeline (see [`ImageModelInfo`]).
|
|
163
|
+
* @returns {any}
|
|
164
|
+
*/
|
|
165
|
+
info() {
|
|
166
|
+
const ret = wasm.wasmimagemodel_info(this.__wbg_ptr);
|
|
167
|
+
if (ret[2]) {
|
|
168
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
169
|
+
}
|
|
170
|
+
return takeFromExternrefTable0(ret[0]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Loads a pipeline from `source`. `options_json`:
|
|
174
|
+
* `{ format?: "f16" | "f32" | "bf16" | "q8" | ..., device?: "cpu" |
|
|
175
|
+
* "webgpu" | "auto" }` (defaults: f16 weights, `auto`). `decoder`,
|
|
176
|
+
* when given, serves a standalone autoencoder (`config.json` and
|
|
177
|
+
* `diffusion_pytorch_model.safetensors`, e.g. `madebyollin/taesd`)
|
|
178
|
+
* that replaces the pipeline's decoder.
|
|
179
|
+
* @param {JsSource} source
|
|
180
|
+
* @param {string} options_json
|
|
181
|
+
* @param {JsSource | null} [decoder]
|
|
182
|
+
* @returns {Promise<WasmImageModel>}
|
|
183
|
+
*/
|
|
184
|
+
static load(source, options_json, decoder) {
|
|
185
|
+
_assertClass(source, JsSource);
|
|
186
|
+
var ptr0 = source.__destroy_into_raw();
|
|
187
|
+
const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
188
|
+
const len1 = WASM_VECTOR_LEN;
|
|
189
|
+
let ptr2 = 0;
|
|
190
|
+
if (!isLikeNone(decoder)) {
|
|
191
|
+
_assertClass(decoder, JsSource);
|
|
192
|
+
ptr2 = decoder.__destroy_into_raw();
|
|
193
|
+
}
|
|
194
|
+
const ret = wasm.wasmimagemodel_load(ptr0, ptr1, len1, ptr2);
|
|
195
|
+
return ret;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (Symbol.dispose) WasmImageModel.prototype[Symbol.dispose] = WasmImageModel.prototype.free;
|
|
199
|
+
|
|
120
200
|
/**
|
|
121
201
|
* A loaded checkpoint, with a default session used by `chat` and
|
|
122
|
-
* `generate`.
|
|
202
|
+
* `generate` (language models), or an encoder answering `embed`.
|
|
123
203
|
*/
|
|
124
204
|
export class WasmModel {
|
|
125
205
|
static __wrap(ptr) {
|
|
@@ -234,6 +314,27 @@ export class WasmModel {
|
|
|
234
314
|
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
235
315
|
}
|
|
236
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Embeds texts with an encoder. `texts_json` is a JSON array of
|
|
319
|
+
* strings; `options_json`: `{ pooling?: "cls" | "mean" | "max" |
|
|
320
|
+
* "mean_sqrt_len_tokens" | "weightedmean" | "lasttoken", normalize?:
|
|
321
|
+
* boolean }` (defaults: the model's sentence-transformers settings).
|
|
322
|
+
* Resolves to `{ data: Float32Array, dimensions: number, tokens:
|
|
323
|
+
* number[] }`: the vectors one after the other, and the number of
|
|
324
|
+
* tokens read from each text (texts longer than the model's limit are
|
|
325
|
+
* cut). Rejects with `UNSUPPORTED_TASK` on a language model.
|
|
326
|
+
* @param {string} texts_json
|
|
327
|
+
* @param {string} options_json
|
|
328
|
+
* @returns {Promise<any>}
|
|
329
|
+
*/
|
|
330
|
+
embed(texts_json, options_json) {
|
|
331
|
+
const ptr0 = passStringToWasm0(texts_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
332
|
+
const len0 = WASM_VECTOR_LEN;
|
|
333
|
+
const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
334
|
+
const len1 = WASM_VECTOR_LEN;
|
|
335
|
+
const ret = wasm.wasmmodel_embed(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
336
|
+
return ret;
|
|
337
|
+
}
|
|
237
338
|
/**
|
|
238
339
|
* Completes raw text in the default session; see
|
|
239
340
|
* [`WasmSession::generate`].
|
|
@@ -262,13 +363,22 @@ export class WasmModel {
|
|
|
262
363
|
}
|
|
263
364
|
return takeFromExternrefTable0(ret[0]);
|
|
264
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Whether the model is an encoder (it answers `embed`, not `chat`).
|
|
368
|
+
* @returns {boolean}
|
|
369
|
+
*/
|
|
370
|
+
get isEncoder() {
|
|
371
|
+
const ret = wasm.wasmmodel_isEncoder(this.__wbg_ptr);
|
|
372
|
+
return ret !== 0;
|
|
373
|
+
}
|
|
265
374
|
/**
|
|
266
375
|
* Loads a checkpoint from `source`. `options_json` is a JSON object:
|
|
267
376
|
* `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
|
|
268
377
|
* contextLength?: number, deterministic?: boolean,
|
|
269
378
|
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto",
|
|
270
379
|
* adapterScale?: number, adapterMode?: "unmerged" | "merged",
|
|
271
|
-
* vision?: boolean
|
|
380
|
+
* vision?: boolean, kvCache?: "f32" | "int8", kvResidual?: number,
|
|
381
|
+
* kvBudget?: number }` (`vision: false` skips the vision encoder of a
|
|
272
382
|
* vision-language checkpoint).
|
|
273
383
|
*
|
|
274
384
|
* `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
|
|
@@ -294,6 +404,9 @@ export class WasmModel {
|
|
|
294
404
|
* `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
|
|
295
405
|
* `webslm export` checkpoint) loads in its own format, its blocks
|
|
296
406
|
* unchanged; weights already in the load format skip `weightCache`.
|
|
407
|
+
*
|
|
408
|
+
* An encoder loads in f32 unless `format` says otherwise, and takes
|
|
409
|
+
* no `lora`.
|
|
297
410
|
* @param {JsSource} source
|
|
298
411
|
* @param {string} options_json
|
|
299
412
|
* @param {JsSource | null} [lora]
|
|
@@ -360,7 +473,7 @@ export class WasmModel {
|
|
|
360
473
|
}
|
|
361
474
|
}
|
|
362
475
|
/**
|
|
363
|
-
* Clears the default session.
|
|
476
|
+
* Clears the default session (nothing to clear for an encoder).
|
|
364
477
|
*/
|
|
365
478
|
reset() {
|
|
366
479
|
const ret = wasm.wasmmodel_reset(this.__wbg_ptr);
|
|
@@ -369,7 +482,8 @@ export class WasmModel {
|
|
|
369
482
|
}
|
|
370
483
|
}
|
|
371
484
|
/**
|
|
372
|
-
* Encodes text into token ids
|
|
485
|
+
* Encodes text into token ids (an encoder's tokenizer cuts texts at
|
|
486
|
+
* its limit, as `embed` does).
|
|
373
487
|
* @param {string} text
|
|
374
488
|
* @param {boolean} add_special_tokens
|
|
375
489
|
* @returns {Uint32Array}
|
|
@@ -668,6 +782,18 @@ export function parseSafetensorsHeader(bytes) {
|
|
|
668
782
|
return takeFromExternrefTable0(ret[0]);
|
|
669
783
|
}
|
|
670
784
|
|
|
785
|
+
/**
|
|
786
|
+
* `model_type` values of the encoders this build embeds with (models
|
|
787
|
+
* whose `WasmModel` answers `embed`).
|
|
788
|
+
* @returns {string[]}
|
|
789
|
+
*/
|
|
790
|
+
export function supportedEncoderTypes() {
|
|
791
|
+
const ret = wasm.supportedEncoderTypes();
|
|
792
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
|
|
793
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
794
|
+
return v1;
|
|
795
|
+
}
|
|
796
|
+
|
|
671
797
|
/**
|
|
672
798
|
* `model_type` values (from `config.json`) of the architectures this build
|
|
673
799
|
* can run.
|
|
@@ -718,6 +844,11 @@ function __wbg_get_imports() {
|
|
|
718
844
|
const ret = arg0.WorkerGlobalScope;
|
|
719
845
|
return ret;
|
|
720
846
|
},
|
|
847
|
+
__wbg___wbindgen_boolean_get_7a12af2b3f899c5a: function(arg0) {
|
|
848
|
+
const v = arg0;
|
|
849
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
850
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
851
|
+
},
|
|
721
852
|
__wbg___wbindgen_debug_string_0e68cf47c9cbd9b0: function(arg0, arg1) {
|
|
722
853
|
const ret = debugString(arg1);
|
|
723
854
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -1147,6 +1278,10 @@ function __wbg_get_imports() {
|
|
|
1147
1278
|
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
1148
1279
|
return ret;
|
|
1149
1280
|
},
|
|
1281
|
+
__wbg_new_from_slice_a500ec81601be48f: function(arg0, arg1) {
|
|
1282
|
+
const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
|
|
1283
|
+
return ret;
|
|
1284
|
+
},
|
|
1150
1285
|
__wbg_new_typed_6f8b0d724fe26c07: function(arg0, arg1) {
|
|
1151
1286
|
try {
|
|
1152
1287
|
var state0 = {a: arg0, b: arg1};
|
|
@@ -1210,6 +1345,10 @@ function __wbg_get_imports() {
|
|
|
1210
1345
|
const ret = arg0.reason;
|
|
1211
1346
|
return (__wbindgen_enum_GpuDeviceLostReason.indexOf(ret) + 1 || 3) - 1;
|
|
1212
1347
|
},
|
|
1348
|
+
__wbg_reject_bea6d825081bd4d7: function(arg0) {
|
|
1349
|
+
const ret = Promise.reject(arg0);
|
|
1350
|
+
return ret;
|
|
1351
|
+
},
|
|
1213
1352
|
__wbg_requestAdapter_2cb1006baf7abd60: function(arg0) {
|
|
1214
1353
|
const ret = arg0.requestAdapter();
|
|
1215
1354
|
return ret;
|
|
@@ -1475,6 +1614,10 @@ function __wbg_get_imports() {
|
|
|
1475
1614
|
const ret = arg0.valueOf();
|
|
1476
1615
|
return ret;
|
|
1477
1616
|
},
|
|
1617
|
+
__wbg_wasmimagemodel_new: function(arg0) {
|
|
1618
|
+
const ret = WasmImageModel.__wrap(arg0);
|
|
1619
|
+
return ret;
|
|
1620
|
+
},
|
|
1478
1621
|
__wbg_wasmmodel_new: function(arg0) {
|
|
1479
1622
|
const ret = WasmModel.__wrap(arg0);
|
|
1480
1623
|
return ret;
|
|
@@ -1483,33 +1626,33 @@ function __wbg_get_imports() {
|
|
|
1483
1626
|
arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
|
|
1484
1627
|
}, arguments); },
|
|
1485
1628
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
1486
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
1629
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 352, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1487
1630
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_);
|
|
1488
1631
|
return ret;
|
|
1489
1632
|
},
|
|
1490
1633
|
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
1491
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx:
|
|
1634
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDevice")], shim_idx: 281, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1492
1635
|
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_);
|
|
1493
1636
|
return ret;
|
|
1494
1637
|
},
|
|
1495
1638
|
__wbindgen_generic_0000000000000003: function(arg0, arg1) {
|
|
1496
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx:
|
|
1639
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUDeviceLostInfo")], shim_idx: 285, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1497
1640
|
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_);
|
|
1498
1641
|
return ret;
|
|
1499
1642
|
},
|
|
1500
1643
|
__wbindgen_generic_0000000000000004: function(arg0, arg1) {
|
|
1501
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx:
|
|
1502
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1644
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("GPUUncapturedErrorEvent")], shim_idx: 285, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1645
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__45);
|
|
1503
1646
|
return ret;
|
|
1504
1647
|
},
|
|
1505
1648
|
__wbindgen_generic_0000000000000005: function(arg0, arg1) {
|
|
1506
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx:
|
|
1507
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1649
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("any")], shim_idx: 281, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1650
|
+
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__46);
|
|
1508
1651
|
return ret;
|
|
1509
1652
|
},
|
|
1510
1653
|
__wbindgen_generic_0000000000000006: function(arg0, arg1) {
|
|
1511
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx:
|
|
1512
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1654
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("undefined")], shim_idx: 281, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1655
|
+
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__47);
|
|
1513
1656
|
return ret;
|
|
1514
1657
|
},
|
|
1515
1658
|
__wbindgen_generic_0000000000000007: function(arg0) {
|
|
@@ -1552,8 +1695,8 @@ function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_549
|
|
|
1552
1695
|
wasm.wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_(arg0, arg1, arg2);
|
|
1553
1696
|
}
|
|
1554
1697
|
|
|
1555
|
-
function
|
|
1556
|
-
wasm.
|
|
1698
|
+
function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__45(arg0, arg1, arg2) {
|
|
1699
|
+
wasm.wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__45(arg0, arg1, arg2);
|
|
1557
1700
|
}
|
|
1558
1701
|
|
|
1559
1702
|
function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_(arg0, arg1, arg2) {
|
|
@@ -1570,15 +1713,15 @@ function wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bin
|
|
|
1570
1713
|
}
|
|
1571
1714
|
}
|
|
1572
1715
|
|
|
1573
|
-
function
|
|
1574
|
-
const ret = wasm.
|
|
1716
|
+
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__46(arg0, arg1, arg2) {
|
|
1717
|
+
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__46(arg0, arg1, arg2);
|
|
1575
1718
|
if (ret[1]) {
|
|
1576
1719
|
throw takeFromExternrefTable0(ret[0]);
|
|
1577
1720
|
}
|
|
1578
1721
|
}
|
|
1579
1722
|
|
|
1580
|
-
function
|
|
1581
|
-
const ret = wasm.
|
|
1723
|
+
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__47(arg0, arg1, arg2) {
|
|
1724
|
+
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__47(arg0, arg1, arg2);
|
|
1582
1725
|
if (ret[1]) {
|
|
1583
1726
|
throw takeFromExternrefTable0(ret[0]);
|
|
1584
1727
|
}
|
|
@@ -1626,6 +1769,9 @@ const JsWeightCacheFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
1626
1769
|
const Sha256HasherFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1627
1770
|
? { register: () => {}, unregister: () => {} }
|
|
1628
1771
|
: new FinalizationRegistry(ptr => wasm.__wbg_sha256hasher_free(ptr, 1));
|
|
1772
|
+
const WasmImageModelFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1773
|
+
? { register: () => {}, unregister: () => {} }
|
|
1774
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmimagemodel_free(ptr, 1));
|
|
1629
1775
|
const WasmModelFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1630
1776
|
? { register: () => {}, unregister: () => {} }
|
|
1631
1777
|
: new FinalizationRegistry(ptr => wasm.__wbg_wasmmodel_free(ptr, 1));
|
|
Binary file
|
|
@@ -4,6 +4,7 @@ export const memory: WebAssembly.Memory;
|
|
|
4
4
|
export const __wbg_jssource_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_jsweightcache_free: (a: number, b: number) => void;
|
|
6
6
|
export const __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_wasmimagemodel_free: (a: number, b: number) => void;
|
|
7
8
|
export const __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
8
9
|
export const __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
9
10
|
export const buildInfo: () => [number, number, number];
|
|
@@ -13,15 +14,21 @@ export const parseSafetensorsHeader: (a: number, b: number) => [number, number,
|
|
|
13
14
|
export const sha256hasher_finish: (a: number) => [number, number];
|
|
14
15
|
export const sha256hasher_new: () => number;
|
|
15
16
|
export const sha256hasher_update: (a: number, b: number, c: number) => void;
|
|
17
|
+
export const supportedEncoderTypes: () => [number, number];
|
|
16
18
|
export const supportedModelTypes: () => [number, number];
|
|
17
19
|
export const version: () => [number, number];
|
|
20
|
+
export const wasmimagemodel_generate: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
|
|
21
|
+
export const wasmimagemodel_info: (a: number) => [number, number, number];
|
|
22
|
+
export const wasmimagemodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
18
23
|
export const wasmmodel_applyAdapter: (a: number, b: number, c: number, d: number) => any;
|
|
19
24
|
export const wasmmodel_chat: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
20
25
|
export const wasmmodel_chatWithMedia: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: any, k: number) => any;
|
|
21
26
|
export const wasmmodel_createSession: (a: number) => [number, number, number];
|
|
22
27
|
export const wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
28
|
+
export const wasmmodel_embed: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
23
29
|
export const wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
24
30
|
export const wasmmodel_info: (a: number) => [number, number, number];
|
|
31
|
+
export const wasmmodel_isEncoder: (a: number) => number;
|
|
25
32
|
export const wasmmodel_load: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
26
33
|
export const wasmmodel_removeAdapter: (a: number) => any;
|
|
27
34
|
export const wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
@@ -44,10 +51,10 @@ export const wasmsession_truncate: (a: number, b: number) => [number, number];
|
|
|
44
51
|
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;
|
|
45
52
|
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];
|
|
46
53
|
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];
|
|
47
|
-
export const
|
|
48
|
-
export const
|
|
54
|
+
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__46: (a: number, b: number, c: any) => [number, number];
|
|
55
|
+
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__47: (a: number, b: number, c: any) => [number, number];
|
|
49
56
|
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;
|
|
50
|
-
export const
|
|
57
|
+
export const wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__45: (a: number, b: number, c: any) => void;
|
|
51
58
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
52
59
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
53
60
|
export const __wbindgen_exn_store: (a: number) => void;
|