@pie-project/server-web 0.6.1 → 0.6.3
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/dist/pie.mjs +24 -6
- package/dist/pie_browser_bg.wasm +2 -2
- package/dist/precompile.mjs +18 -18
- package/dist/worker.mjs +24 -22
- package/index.d.ts +9 -0
- package/package.json +1 -1
- package/src/pie.mjs +26 -6
- package/src/worker.mjs +2 -2
package/dist/pie.mjs
CHANGED
|
@@ -3238,8 +3238,9 @@ async function installLanguage(language, wasmBytes, precompiled) {
|
|
|
3238
3238
|
async function memoryBytes() {
|
|
3239
3239
|
return await ready().call("memoryBytes");
|
|
3240
3240
|
}
|
|
3241
|
-
async function bootLazy(url, config, onProgress) {
|
|
3242
|
-
|
|
3241
|
+
async function bootLazy(url, config, onProgress, packages = {}) {
|
|
3242
|
+
const files = JSON.stringify(packages);
|
|
3243
|
+
return await ready().call("bootLazy", [url, config, location.href, files], { onProgress });
|
|
3243
3244
|
}
|
|
3244
3245
|
async function awaitCache() {
|
|
3245
3246
|
return await ready().call("awaitCache", []);
|
|
@@ -3253,6 +3254,15 @@ async function bytesOf(source) {
|
|
|
3253
3254
|
if (!response.ok) throw new Error(`pie: ${source}: ${response.status} ${response.statusText}`);
|
|
3254
3255
|
return new Uint8Array(await response.arrayBuffer());
|
|
3255
3256
|
}
|
|
3257
|
+
async function packageTexts(packages) {
|
|
3258
|
+
const texts = await Promise.all(
|
|
3259
|
+
Object.entries(packages).map(async ([path, source]) => [
|
|
3260
|
+
path,
|
|
3261
|
+
source instanceof URL ? new TextDecoder().decode(await bytesOf(source)) : source
|
|
3262
|
+
])
|
|
3263
|
+
);
|
|
3264
|
+
return Object.fromEntries(texts);
|
|
3265
|
+
}
|
|
3256
3266
|
var Server = class _Server {
|
|
3257
3267
|
#summary;
|
|
3258
3268
|
#open = true;
|
|
@@ -3263,13 +3273,21 @@ var Server = class _Server {
|
|
|
3263
3273
|
/**
|
|
3264
3274
|
* Boot the runtime and the WebGPU engine. `model` is the URL of a
|
|
3265
3275
|
* `.wgpu.zt` artifact served with Range support; `config` the boot config
|
|
3266
|
-
* (an object, or TOML text).
|
|
3267
|
-
*
|
|
3276
|
+
* (an object, or TOML text). `packages` lays poem files over the ones this
|
|
3277
|
+
* build embeds, as editing `$PIE_HOME/models/` does for `pie serve`: a path
|
|
3278
|
+
* under that directory (`qwen_3.poem`) to its text or a URL, refused here if
|
|
3279
|
+
* it does not load. Resolves once the weights are on the device, with every
|
|
3280
|
+
* registered language component installed.
|
|
3268
3281
|
*/
|
|
3269
|
-
static async start({ model, config = {}, onProgress, worker = true, log, wasmUrl } = {}) {
|
|
3282
|
+
static async start({ model, config = {}, packages = {}, onProgress, worker = true, log, wasmUrl } = {}) {
|
|
3270
3283
|
if (typeof model !== "string") throw new Error("Server.start: `model` is the URL of the artifact to serve");
|
|
3271
3284
|
if (!backend) await load({ worker, log, wasmUrl });
|
|
3272
|
-
const summary = await bootLazy(
|
|
3285
|
+
const summary = await bootLazy(
|
|
3286
|
+
model,
|
|
3287
|
+
typeof config === "string" ? config : JSON.stringify(config),
|
|
3288
|
+
onProgress,
|
|
3289
|
+
await packageTexts(packages)
|
|
3290
|
+
);
|
|
3273
3291
|
const server = new _Server(summary);
|
|
3274
3292
|
server.#detach = await attachLanguages(server);
|
|
3275
3293
|
return server;
|
package/dist/pie_browser_bg.wasm
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/pie_browser_bg.wasm
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 34496820 bytes
|
|
4
|
+
sha256: d12e75a37ecce5ef4c85947c598213a0f23e4a6b5dae84aa0753d40b70d5e6bd
|
package/dist/precompile.mjs
CHANGED
|
@@ -509,7 +509,7 @@ function __wbg_get_imports() {
|
|
|
509
509
|
const a = state0.a;
|
|
510
510
|
state0.a = 0;
|
|
511
511
|
try {
|
|
512
|
-
return
|
|
512
|
+
return __wasm_bindgen_func_elem_55897(a, state0.b, arg02, arg12);
|
|
513
513
|
} finally {
|
|
514
514
|
state0.a = a;
|
|
515
515
|
}
|
|
@@ -850,23 +850,23 @@ function __wbg_get_imports() {
|
|
|
850
850
|
}, arguments);
|
|
851
851
|
},
|
|
852
852
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
853
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
853
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_55895);
|
|
854
854
|
return addHeapObject(ret);
|
|
855
855
|
},
|
|
856
856
|
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
857
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
857
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11564);
|
|
858
858
|
return addHeapObject(ret);
|
|
859
859
|
},
|
|
860
860
|
__wbindgen_generic_0000000000000003: function(arg0, arg1) {
|
|
861
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
861
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11565);
|
|
862
862
|
return addHeapObject(ret);
|
|
863
863
|
},
|
|
864
864
|
__wbindgen_generic_0000000000000004: function(arg0, arg1) {
|
|
865
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
865
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11564_15);
|
|
866
866
|
return addHeapObject(ret);
|
|
867
867
|
},
|
|
868
868
|
__wbindgen_generic_0000000000000005: function(arg0, arg1) {
|
|
869
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
869
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11564_16);
|
|
870
870
|
return addHeapObject(ret);
|
|
871
871
|
},
|
|
872
872
|
__wbindgen_generic_0000000000000006: function(arg0) {
|
|
@@ -898,16 +898,16 @@ function __wbg_get_imports() {
|
|
|
898
898
|
"./platform.mjs": platform_exports
|
|
899
899
|
};
|
|
900
900
|
}
|
|
901
|
-
function
|
|
902
|
-
wasm2.
|
|
901
|
+
function __wasm_bindgen_func_elem_11565(arg0, arg1, arg2) {
|
|
902
|
+
wasm2.__wasm_bindgen_func_elem_11565(arg0, arg1, addHeapObject(arg2));
|
|
903
903
|
}
|
|
904
|
-
function
|
|
905
|
-
wasm2.
|
|
904
|
+
function __wasm_bindgen_func_elem_55897(arg0, arg1, arg2, arg3) {
|
|
905
|
+
wasm2.__wasm_bindgen_func_elem_55897(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
906
906
|
}
|
|
907
|
-
function
|
|
907
|
+
function __wasm_bindgen_func_elem_55895(arg0, arg1, arg2) {
|
|
908
908
|
try {
|
|
909
909
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
910
|
-
wasm2.
|
|
910
|
+
wasm2.__wasm_bindgen_func_elem_55895(retptr, arg0, arg1, addHeapObject(arg2));
|
|
911
911
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
912
912
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
913
913
|
if (r1) {
|
|
@@ -917,10 +917,10 @@ function __wasm_bindgen_func_elem_55688(arg0, arg1, arg2) {
|
|
|
917
917
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
|
-
function
|
|
920
|
+
function __wasm_bindgen_func_elem_11564(arg0, arg1, arg2) {
|
|
921
921
|
try {
|
|
922
922
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
923
|
-
wasm2.
|
|
923
|
+
wasm2.__wasm_bindgen_func_elem_11564(retptr, arg0, arg1, addHeapObject(arg2));
|
|
924
924
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
925
925
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
926
926
|
if (r1) {
|
|
@@ -930,10 +930,10 @@ function __wasm_bindgen_func_elem_11414(arg0, arg1, arg2) {
|
|
|
930
930
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
931
931
|
}
|
|
932
932
|
}
|
|
933
|
-
function
|
|
933
|
+
function __wasm_bindgen_func_elem_11564_15(arg0, arg1, arg2) {
|
|
934
934
|
try {
|
|
935
935
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
936
|
-
wasm2.
|
|
936
|
+
wasm2.__wasm_bindgen_func_elem_11564_15(retptr, arg0, arg1, addHeapObject(arg2));
|
|
937
937
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
938
938
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
939
939
|
if (r1) {
|
|
@@ -943,10 +943,10 @@ function __wasm_bindgen_func_elem_11414_15(arg0, arg1, arg2) {
|
|
|
943
943
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
944
944
|
}
|
|
945
945
|
}
|
|
946
|
-
function
|
|
946
|
+
function __wasm_bindgen_func_elem_11564_16(arg0, arg1, arg2) {
|
|
947
947
|
try {
|
|
948
948
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
949
|
-
wasm2.
|
|
949
|
+
wasm2.__wasm_bindgen_func_elem_11564_16(retptr, arg0, arg1, addHeapObject(arg2));
|
|
950
950
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
951
951
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
952
952
|
if (r1) {
|
package/dist/worker.mjs
CHANGED
|
@@ -65,12 +65,14 @@ function pie_wake() {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// pkg/pie_browser.js
|
|
68
|
-
function pie_boot_lazy(config_toml, model_name, len) {
|
|
68
|
+
function pie_boot_lazy(config_toml, model_name, len, packages_json) {
|
|
69
69
|
const ptr0 = passStringToWasm0(config_toml, wasm2.__wbindgen_export, wasm2.__wbindgen_export2);
|
|
70
70
|
const len0 = WASM_VECTOR_LEN;
|
|
71
71
|
const ptr1 = passStringToWasm0(model_name, wasm2.__wbindgen_export, wasm2.__wbindgen_export2);
|
|
72
72
|
const len1 = WASM_VECTOR_LEN;
|
|
73
|
-
const
|
|
73
|
+
const ptr2 = passStringToWasm0(packages_json, wasm2.__wbindgen_export, wasm2.__wbindgen_export2);
|
|
74
|
+
const len2 = WASM_VECTOR_LEN;
|
|
75
|
+
const ret = wasm2.pie_boot_lazy(ptr0, len0, ptr1, len1, len, ptr2, len2);
|
|
74
76
|
return takeObject(ret);
|
|
75
77
|
}
|
|
76
78
|
function pie_close_session(session) {
|
|
@@ -561,7 +563,7 @@ function __wbg_get_imports() {
|
|
|
561
563
|
const a = state0.a;
|
|
562
564
|
state0.a = 0;
|
|
563
565
|
try {
|
|
564
|
-
return
|
|
566
|
+
return __wasm_bindgen_func_elem_55897(a, state0.b, arg02, arg12);
|
|
565
567
|
} finally {
|
|
566
568
|
state0.a = a;
|
|
567
569
|
}
|
|
@@ -902,23 +904,23 @@ function __wbg_get_imports() {
|
|
|
902
904
|
}, arguments);
|
|
903
905
|
},
|
|
904
906
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
905
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
907
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_55895);
|
|
906
908
|
return addHeapObject(ret);
|
|
907
909
|
},
|
|
908
910
|
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
909
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
911
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11564);
|
|
910
912
|
return addHeapObject(ret);
|
|
911
913
|
},
|
|
912
914
|
__wbindgen_generic_0000000000000003: function(arg0, arg1) {
|
|
913
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
915
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11565);
|
|
914
916
|
return addHeapObject(ret);
|
|
915
917
|
},
|
|
916
918
|
__wbindgen_generic_0000000000000004: function(arg0, arg1) {
|
|
917
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
919
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11564_15);
|
|
918
920
|
return addHeapObject(ret);
|
|
919
921
|
},
|
|
920
922
|
__wbindgen_generic_0000000000000005: function(arg0, arg1) {
|
|
921
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
923
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11564_16);
|
|
922
924
|
return addHeapObject(ret);
|
|
923
925
|
},
|
|
924
926
|
__wbindgen_generic_0000000000000006: function(arg0) {
|
|
@@ -950,16 +952,16 @@ function __wbg_get_imports() {
|
|
|
950
952
|
"./platform.mjs": platform_exports
|
|
951
953
|
};
|
|
952
954
|
}
|
|
953
|
-
function
|
|
954
|
-
wasm2.
|
|
955
|
+
function __wasm_bindgen_func_elem_11565(arg0, arg1, arg2) {
|
|
956
|
+
wasm2.__wasm_bindgen_func_elem_11565(arg0, arg1, addHeapObject(arg2));
|
|
955
957
|
}
|
|
956
|
-
function
|
|
957
|
-
wasm2.
|
|
958
|
+
function __wasm_bindgen_func_elem_55897(arg0, arg1, arg2, arg3) {
|
|
959
|
+
wasm2.__wasm_bindgen_func_elem_55897(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
958
960
|
}
|
|
959
|
-
function
|
|
961
|
+
function __wasm_bindgen_func_elem_55895(arg0, arg1, arg2) {
|
|
960
962
|
try {
|
|
961
963
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
962
|
-
wasm2.
|
|
964
|
+
wasm2.__wasm_bindgen_func_elem_55895(retptr, arg0, arg1, addHeapObject(arg2));
|
|
963
965
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
964
966
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
965
967
|
if (r1) {
|
|
@@ -969,10 +971,10 @@ function __wasm_bindgen_func_elem_55688(arg0, arg1, arg2) {
|
|
|
969
971
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
970
972
|
}
|
|
971
973
|
}
|
|
972
|
-
function
|
|
974
|
+
function __wasm_bindgen_func_elem_11564(arg0, arg1, arg2) {
|
|
973
975
|
try {
|
|
974
976
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
975
|
-
wasm2.
|
|
977
|
+
wasm2.__wasm_bindgen_func_elem_11564(retptr, arg0, arg1, addHeapObject(arg2));
|
|
976
978
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
977
979
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
978
980
|
if (r1) {
|
|
@@ -982,10 +984,10 @@ function __wasm_bindgen_func_elem_11414(arg0, arg1, arg2) {
|
|
|
982
984
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
983
985
|
}
|
|
984
986
|
}
|
|
985
|
-
function
|
|
987
|
+
function __wasm_bindgen_func_elem_11564_15(arg0, arg1, arg2) {
|
|
986
988
|
try {
|
|
987
989
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
988
|
-
wasm2.
|
|
990
|
+
wasm2.__wasm_bindgen_func_elem_11564_15(retptr, arg0, arg1, addHeapObject(arg2));
|
|
989
991
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
990
992
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
991
993
|
if (r1) {
|
|
@@ -995,10 +997,10 @@ function __wasm_bindgen_func_elem_11414_15(arg0, arg1, arg2) {
|
|
|
995
997
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
996
998
|
}
|
|
997
999
|
}
|
|
998
|
-
function
|
|
1000
|
+
function __wasm_bindgen_func_elem_11564_16(arg0, arg1, arg2) {
|
|
999
1001
|
try {
|
|
1000
1002
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
1001
|
-
wasm2.
|
|
1003
|
+
wasm2.__wasm_bindgen_func_elem_11564_16(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1002
1004
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1003
1005
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1004
1006
|
if (r1) {
|
|
@@ -1422,7 +1424,7 @@ var host = {
|
|
|
1422
1424
|
pie_init(logFilter);
|
|
1423
1425
|
return { worker: typeof WorkerGlobalScope !== "undefined" };
|
|
1424
1426
|
},
|
|
1425
|
-
async bootLazy(url, config, base, onProgress) {
|
|
1427
|
+
async bootLazy(url, config, base, packages, onProgress) {
|
|
1426
1428
|
cacheFill = null;
|
|
1427
1429
|
const href = new URL(url, base ?? location.href).href;
|
|
1428
1430
|
const { size, etag } = await describe(href);
|
|
@@ -1466,7 +1468,7 @@ var host = {
|
|
|
1466
1468
|
const t0 = performance.now();
|
|
1467
1469
|
let summary;
|
|
1468
1470
|
try {
|
|
1469
|
-
summary = JSON.parse(await driven(pie_boot_lazy(config, url.split("/").pop(), size)));
|
|
1471
|
+
summary = JSON.parse(await driven(pie_boot_lazy(config, url.split("/").pop(), size, packages)));
|
|
1470
1472
|
} finally {
|
|
1471
1473
|
globalThis.__pieHost.fetchRange = refuse;
|
|
1472
1474
|
console.log(`pie: lazy boot served ${requests} range request(s), ${(served / 1048576).toFixed(0)} MiB from ${from}, in ${(performance.now() - t0).toFixed(0)} ms`);
|
package/index.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export function bootLazy(
|
|
|
28
28
|
url: string,
|
|
29
29
|
config?: string,
|
|
30
30
|
onProgress?: (served: number, total: number, from: "network" | "cache") => void,
|
|
31
|
+
/** Paths under a models directory to their text. */
|
|
32
|
+
packages?: Record<string, string>,
|
|
31
33
|
): Promise<BootSummary>;
|
|
32
34
|
|
|
33
35
|
export function awaitCache(): Promise<void>;
|
|
@@ -47,6 +49,13 @@ export interface StartOptions extends LoadOptions {
|
|
|
47
49
|
model: string;
|
|
48
50
|
/** The boot config: an object, or TOML text. */
|
|
49
51
|
config?: Record<string, unknown> | string;
|
|
52
|
+
/**
|
|
53
|
+
* Poem files over the ones this build embeds, as editing `$PIE_HOME/models/`
|
|
54
|
+
* does for `pie serve`: a path under that directory (`qwen_3.poem`,
|
|
55
|
+
* `mimo_v2/model.poem`, `lib/nn.poem`) to its text, or a URL to fetch it
|
|
56
|
+
* from. The boot is refused if one does not load.
|
|
57
|
+
*/
|
|
58
|
+
packages?: Record<string, string | URL>;
|
|
50
59
|
onProgress?: (served: number, total: number, from: "network" | "cache") => void;
|
|
51
60
|
}
|
|
52
61
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-project/server-web",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "The browser half of @pie-project/server: the runtime and the WebGPU engine as wasm, reached through `import { Server } from \"@pie-project/server\"` under a bundler.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/pie.mjs",
|
package/src/pie.mjs
CHANGED
|
@@ -115,8 +115,9 @@ export async function memoryBytes() {
|
|
|
115
115
|
return await ready().call("memoryBytes");
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
export async function bootLazy(url, config, onProgress) {
|
|
119
|
-
|
|
118
|
+
export async function bootLazy(url, config, onProgress, packages = {}) {
|
|
119
|
+
const files = JSON.stringify(packages);
|
|
120
|
+
return await ready().call("bootLazy", [url, config, location.href, files], { onProgress });
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
export async function awaitCache() {
|
|
@@ -134,6 +135,17 @@ async function bytesOf(source) {
|
|
|
134
135
|
return new Uint8Array(await response.arrayBuffer());
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
/** Each package's text: a URL is fetched, a string is the text itself. */
|
|
139
|
+
async function packageTexts(packages) {
|
|
140
|
+
const texts = await Promise.all(
|
|
141
|
+
Object.entries(packages).map(async ([path, source]) => [
|
|
142
|
+
path,
|
|
143
|
+
source instanceof URL ? new TextDecoder().decode(await bytesOf(source)) : source,
|
|
144
|
+
]),
|
|
145
|
+
);
|
|
146
|
+
return Object.fromEntries(texts);
|
|
147
|
+
}
|
|
148
|
+
|
|
137
149
|
/** One running pie in this tab, with the surface of the Node host. */
|
|
138
150
|
export class Server {
|
|
139
151
|
#summary;
|
|
@@ -147,13 +159,21 @@ export class Server {
|
|
|
147
159
|
/**
|
|
148
160
|
* Boot the runtime and the WebGPU engine. `model` is the URL of a
|
|
149
161
|
* `.wgpu.zt` artifact served with Range support; `config` the boot config
|
|
150
|
-
* (an object, or TOML text).
|
|
151
|
-
*
|
|
162
|
+
* (an object, or TOML text). `packages` lays poem files over the ones this
|
|
163
|
+
* build embeds, as editing `$PIE_HOME/models/` does for `pie serve`: a path
|
|
164
|
+
* under that directory (`qwen_3.poem`) to its text or a URL, refused here if
|
|
165
|
+
* it does not load. Resolves once the weights are on the device, with every
|
|
166
|
+
* registered language component installed.
|
|
152
167
|
*/
|
|
153
|
-
static async start({ model, config = {}, onProgress, worker = true, log, wasmUrl } = {}) {
|
|
168
|
+
static async start({ model, config = {}, packages = {}, onProgress, worker = true, log, wasmUrl } = {}) {
|
|
154
169
|
if (typeof model !== "string") throw new Error("Server.start: `model` is the URL of the artifact to serve");
|
|
155
170
|
if (!backend) await load({ worker, log, wasmUrl });
|
|
156
|
-
const summary = await bootLazy(
|
|
171
|
+
const summary = await bootLazy(
|
|
172
|
+
model,
|
|
173
|
+
typeof config === "string" ? config : JSON.stringify(config),
|
|
174
|
+
onProgress,
|
|
175
|
+
await packageTexts(packages),
|
|
176
|
+
);
|
|
157
177
|
const server = new Server(summary);
|
|
158
178
|
server.#detach = await attachLanguages(server);
|
|
159
179
|
return server;
|
package/src/worker.mjs
CHANGED
|
@@ -119,7 +119,7 @@ export const host = {
|
|
|
119
119
|
return { worker: typeof WorkerGlobalScope !== "undefined" };
|
|
120
120
|
},
|
|
121
121
|
|
|
122
|
-
async bootLazy(url, config, base, onProgress) {
|
|
122
|
+
async bootLazy(url, config, base, packages, onProgress) {
|
|
123
123
|
cacheFill = null;
|
|
124
124
|
const href = new URL(url, base ?? location.href).href;
|
|
125
125
|
const { size, etag } = await describe(href);
|
|
@@ -163,7 +163,7 @@ export const host = {
|
|
|
163
163
|
const t0 = performance.now();
|
|
164
164
|
let summary;
|
|
165
165
|
try {
|
|
166
|
-
summary = JSON.parse(await driven(bindings.pie_boot_lazy(config, url.split("/").pop(), size)));
|
|
166
|
+
summary = JSON.parse(await driven(bindings.pie_boot_lazy(config, url.split("/").pop(), size, packages)));
|
|
167
167
|
} finally {
|
|
168
168
|
globalThis.__pieHost.fetchRange = refuse;
|
|
169
169
|
console.log(`pie: lazy boot served ${requests} range request(s), ${(served / 1048576).toFixed(0)} MiB from ${from}, in ${(performance.now() - t0).toFixed(0)} ms`);
|