@pie-project/server-web 0.6.0 → 0.6.2
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_browser_bg.wasm +2 -2
- package/dist/precompile.mjs +18 -18
- package/dist/worker.mjs +18 -18
- package/package.json +1 -1
- package/README.md +0 -102
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: 34369844 bytes
|
|
4
|
+
sha256: f6fa739a0e669fa9d93c1dda3eb8a34f48f6141e9a0a12c50272ee12c6d0cd55
|
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_55752(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_55750);
|
|
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_11442);
|
|
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_11443);
|
|
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_11442_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_11442_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_11443(arg0, arg1, arg2) {
|
|
902
|
+
wasm2.__wasm_bindgen_func_elem_11443(arg0, arg1, addHeapObject(arg2));
|
|
903
903
|
}
|
|
904
|
-
function
|
|
905
|
-
wasm2.
|
|
904
|
+
function __wasm_bindgen_func_elem_55752(arg0, arg1, arg2, arg3) {
|
|
905
|
+
wasm2.__wasm_bindgen_func_elem_55752(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
906
906
|
}
|
|
907
|
-
function
|
|
907
|
+
function __wasm_bindgen_func_elem_55750(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_55750(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_55765(arg0, arg1, arg2) {
|
|
|
917
917
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
|
-
function
|
|
920
|
+
function __wasm_bindgen_func_elem_11442(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_11442(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_11488(arg0, arg1, arg2) {
|
|
|
930
930
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
931
931
|
}
|
|
932
932
|
}
|
|
933
|
-
function
|
|
933
|
+
function __wasm_bindgen_func_elem_11442_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_11442_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_11488_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_11442_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_11442_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
|
@@ -561,7 +561,7 @@ function __wbg_get_imports() {
|
|
|
561
561
|
const a = state0.a;
|
|
562
562
|
state0.a = 0;
|
|
563
563
|
try {
|
|
564
|
-
return
|
|
564
|
+
return __wasm_bindgen_func_elem_55752(a, state0.b, arg02, arg12);
|
|
565
565
|
} finally {
|
|
566
566
|
state0.a = a;
|
|
567
567
|
}
|
|
@@ -902,23 +902,23 @@ function __wbg_get_imports() {
|
|
|
902
902
|
}, arguments);
|
|
903
903
|
},
|
|
904
904
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
905
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
905
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_55750);
|
|
906
906
|
return addHeapObject(ret);
|
|
907
907
|
},
|
|
908
908
|
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
909
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
909
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11442);
|
|
910
910
|
return addHeapObject(ret);
|
|
911
911
|
},
|
|
912
912
|
__wbindgen_generic_0000000000000003: function(arg0, arg1) {
|
|
913
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
913
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11443);
|
|
914
914
|
return addHeapObject(ret);
|
|
915
915
|
},
|
|
916
916
|
__wbindgen_generic_0000000000000004: function(arg0, arg1) {
|
|
917
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
917
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11442_15);
|
|
918
918
|
return addHeapObject(ret);
|
|
919
919
|
},
|
|
920
920
|
__wbindgen_generic_0000000000000005: function(arg0, arg1) {
|
|
921
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
921
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11442_16);
|
|
922
922
|
return addHeapObject(ret);
|
|
923
923
|
},
|
|
924
924
|
__wbindgen_generic_0000000000000006: function(arg0) {
|
|
@@ -950,16 +950,16 @@ function __wbg_get_imports() {
|
|
|
950
950
|
"./platform.mjs": platform_exports
|
|
951
951
|
};
|
|
952
952
|
}
|
|
953
|
-
function
|
|
954
|
-
wasm2.
|
|
953
|
+
function __wasm_bindgen_func_elem_11443(arg0, arg1, arg2) {
|
|
954
|
+
wasm2.__wasm_bindgen_func_elem_11443(arg0, arg1, addHeapObject(arg2));
|
|
955
955
|
}
|
|
956
|
-
function
|
|
957
|
-
wasm2.
|
|
956
|
+
function __wasm_bindgen_func_elem_55752(arg0, arg1, arg2, arg3) {
|
|
957
|
+
wasm2.__wasm_bindgen_func_elem_55752(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
958
958
|
}
|
|
959
|
-
function
|
|
959
|
+
function __wasm_bindgen_func_elem_55750(arg0, arg1, arg2) {
|
|
960
960
|
try {
|
|
961
961
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
962
|
-
wasm2.
|
|
962
|
+
wasm2.__wasm_bindgen_func_elem_55750(retptr, arg0, arg1, addHeapObject(arg2));
|
|
963
963
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
964
964
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
965
965
|
if (r1) {
|
|
@@ -969,10 +969,10 @@ function __wasm_bindgen_func_elem_55765(arg0, arg1, arg2) {
|
|
|
969
969
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
970
970
|
}
|
|
971
971
|
}
|
|
972
|
-
function
|
|
972
|
+
function __wasm_bindgen_func_elem_11442(arg0, arg1, arg2) {
|
|
973
973
|
try {
|
|
974
974
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
975
|
-
wasm2.
|
|
975
|
+
wasm2.__wasm_bindgen_func_elem_11442(retptr, arg0, arg1, addHeapObject(arg2));
|
|
976
976
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
977
977
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
978
978
|
if (r1) {
|
|
@@ -982,10 +982,10 @@ function __wasm_bindgen_func_elem_11488(arg0, arg1, arg2) {
|
|
|
982
982
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
|
-
function
|
|
985
|
+
function __wasm_bindgen_func_elem_11442_15(arg0, arg1, arg2) {
|
|
986
986
|
try {
|
|
987
987
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
988
|
-
wasm2.
|
|
988
|
+
wasm2.__wasm_bindgen_func_elem_11442_15(retptr, arg0, arg1, addHeapObject(arg2));
|
|
989
989
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
990
990
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
991
991
|
if (r1) {
|
|
@@ -995,10 +995,10 @@ function __wasm_bindgen_func_elem_11488_15(arg0, arg1, arg2) {
|
|
|
995
995
|
wasm2.__wbindgen_add_to_stack_pointer(16);
|
|
996
996
|
}
|
|
997
997
|
}
|
|
998
|
-
function
|
|
998
|
+
function __wasm_bindgen_func_elem_11442_16(arg0, arg1, arg2) {
|
|
999
999
|
try {
|
|
1000
1000
|
const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
|
|
1001
|
-
wasm2.
|
|
1001
|
+
wasm2.__wasm_bindgen_func_elem_11442_16(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1002
1002
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1003
1003
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1004
1004
|
if (r1) {
|
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.2",
|
|
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/README.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# @pie-project/server-web
|
|
2
|
-
|
|
3
|
-
The browser half of `@pie-project/server`: the same runtime, WebGPU engine
|
|
4
|
-
and inferlet sandbox as `pie serve`, compiled to `wasm32-unknown-unknown`.
|
|
5
|
-
No server-side inference: the page fetches a `.wgpu.zt` artifact, the
|
|
6
|
-
weights land in WebGPU buffers, and inferlets run under wasmtime's Pulley
|
|
7
|
-
interpreter inside the same module. A bundler reaches it through
|
|
8
|
-
`@pie-project/server`'s `browser` export condition; nothing imports it by
|
|
9
|
-
name.
|
|
10
|
-
|
|
11
|
-
## Use
|
|
12
|
-
|
|
13
|
-
The package ships the wasm and a self-contained bundle (`dist/pie.mjs`,
|
|
14
|
-
`dist/worker.mjs`, `dist/pie_browser_bg.wasm`); the client
|
|
15
|
-
(`@pie-project/client`) is bundled in and re-exported. The worker and the
|
|
16
|
-
wasm are fetched relative to the module, so serve them from your own origin
|
|
17
|
-
(a bundler that understands `new URL(…, import.meta.url)` — Vite, webpack 5 —
|
|
18
|
-
does this by itself; without one, copy `dist/` next to your page).
|
|
19
|
-
|
|
20
|
-
```js
|
|
21
|
-
import { Server } from "@pie-project/server"; // resolves here under a bundler
|
|
22
|
-
import "@pie-project/language-python";
|
|
23
|
-
|
|
24
|
-
const server = await Server.start({ model: "/models/qwen3.5-0.8b.wgpu.zt" }); // served with Range support
|
|
25
|
-
const program = await server.install("/inferlets/beam_search.wasm"); // a URL, or bytes with a file name
|
|
26
|
-
const client = await server.connect(); // a PieClient, as for `pie serve`
|
|
27
|
-
const proc = await client.launchProcess(program, { prompt: "The capital of France is", max_tokens: 16 });
|
|
28
|
-
for (;;) {
|
|
29
|
-
const { event, value } = await proc.recv();
|
|
30
|
-
if (event === "return" || event === "error") break;
|
|
31
|
-
}
|
|
32
|
-
await server.shutdown();
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
The page-level functions behind the class (`load`, `bootLazy`, `install`,
|
|
36
|
-
`installLanguage`, `connect`, `awaitCache`, `memoryBytes`) are exported as
|
|
37
|
-
well; `tests/browser` drives them directly.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- The page must be cross-origin isolated (`Cross-Origin-Opener-Policy:
|
|
41
|
-
same-origin`, `Cross-Origin-Embedder-Policy: require-corp`), and the
|
|
42
|
-
browser needs WebGPU and JSPI: Chrome 137+, Firefox 153+ (Firefox on
|
|
43
|
-
Linux has no WebGPU, so the engine cannot boot there).
|
|
44
|
-
- `bootLazy` never holds the artifact in the tab: the loader's reads are
|
|
45
|
-
served as 8 MiB-aligned `Range` requests, and after a boot from the
|
|
46
|
-
network the artifact is copied into the origin's private file system
|
|
47
|
-
(files up to about 2 GB) so the next visit reads it from there;
|
|
48
|
-
`awaitCache()` waits for that copy. Peak wasm memory is a few times the
|
|
49
|
-
largest tensor: 0.8B boots in 285 MiB, 9B in 4 bits in 1.5 GiB.
|
|
50
|
-
- The engine cannot ask WebGPU how much device memory there is and assumes
|
|
51
|
-
8 GiB; a large model with the default pools is refused ("raise the device
|
|
52
|
-
weight budget") — pass `device_memory_mb = 20480` (or a smaller
|
|
53
|
-
`device_kv_budget`) in the boot config. `Settings` in
|
|
54
|
-
`crates/worker/src/embedded.rs` lists the keys, plus `device_memory_mb` and
|
|
55
|
-
`power_preference` for the WebGPU engine.
|
|
56
|
-
- A tab compiles a script language's component (Python's is 37 MB) on the
|
|
57
|
-
first inferlet in that language, about 8 s, and again after every reload.
|
|
58
|
-
Precompile it once at build time with this same build,
|
|
59
|
-
`node node_modules/@pie-project/server-web/dist/precompile.mjs python.wasm
|
|
60
|
-
python.pulley.cwasm` (or `precompileComponent` from
|
|
61
|
-
`@pie-project/server-web/precompile`; no GPU needed), serve the result
|
|
62
|
-
beside the source, and pass it as
|
|
63
|
-
`installLanguage("python", source, { precompiled })`. It fits only the
|
|
64
|
-
`pie_browser_bg.wasm` it was made with; one that does not is ignored with
|
|
65
|
-
a warning and the source compiled instead.
|
|
66
|
-
- Rust, JavaScript and Python inferlets run. Not available in a tab: MoE
|
|
67
|
-
host-tier expert streaming, Python inferlet snapshots, telemetry, and
|
|
68
|
-
outbound HTTP or files from inferlets (the WASI interfaces link, a call
|
|
69
|
-
fails).
|
|
70
|
-
- `index.d.ts` carries the types.
|
|
71
|
-
|
|
72
|
-
## Build
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
rustup target add wasm32-unknown-unknown
|
|
76
|
-
cargo install wasm-bindgen-cli --version 0.2.128 --locked # must match Cargo.lock
|
|
77
|
-
./packages/javascript/server-web/build.sh # release; `min` for the 23 MB shipping build, `dev` for debug
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
`build.sh` builds the crate in `rust/`, runs wasm-bindgen into `pkg/`, and bundles
|
|
81
|
-
`src/` with esbuild into `dist/` (`npm run bundle`). The package's own
|
|
82
|
-
dependencies are installed on the first run. Tests, benchmarks and CI gates
|
|
83
|
-
live under `tests/browser` (see its README).
|
|
84
|
-
|
|
85
|
-
## How it fits together
|
|
86
|
-
|
|
87
|
-
| piece | what it does |
|
|
88
|
-
|---|---|
|
|
89
|
-
| `rust/` (crate `pie-browser`) | The wasm-bindgen host: boot, install, sessions speaking the MessagePack frames `pie serve`'s WebSocket carries, `pie_tick`. |
|
|
90
|
-
| `crates/wasmtime-web` | wasmtime in a tab: heap-backed "virtual memory", TLS slots, fibers implemented by the page's JSPI glue (`src/platform.mjs`), and the WASI host for the inferlet's imports (cli, io, clocks, random; 0.2 linked by hand, the 0.3 clocks from `crates/inferlet/wit`). The 0.2 filesystem and http interfaces a JavaScript or Python guest runtime imports regardless are stubbed per component, so they link and only a call fails. |
|
|
91
|
-
| `crates/web-std` | The executor the page ticks, timers over `performance.now()`, crossbeam-shaped channels, and green threads on fibers. The runtime's scheduler and engine lanes run on those unchanged; `crates/runtime`'s `rt` facade names it on wasm32. |
|
|
92
|
-
| `crates/engine-wgpu` | The same engine on both hosts, written for the browser: no GPU wait blocks, every step lands by callback, guests run from the landing. What differs by host sits in `device/host.rs`. |
|
|
93
|
-
| `src/worker.mjs` | The host: wasm init, the tick loop, sessions, the artifact served by byte range. Runs in a Web Worker so the page stays responsive through the inferlet's in-browser compile and every forward pass; `load({ worker: false })` runs it on the page for debugging. |
|
|
94
|
-
| `src/pie.mjs` | The page-side API: the `Server` class over `load`, `bootLazy`, `install`, `connect`. |
|
|
95
|
-
| `src/languages.mjs` | The language registry `@pie-project/server/languages` re-exports: what a language package calls on import. |
|
|
96
|
-
| `src/platform.mjs` | Fibers (JSPI), the clock, the wake hook the wasm imports. |
|
|
97
|
-
| `src/transport.mjs` | The client's in-page socket over the runtime's frame API. |
|
|
98
|
-
|
|
99
|
-
The native wgpu server is the engine's test host rather than a production
|
|
100
|
-
backend: it runs the browser's code path over Vulkan, Metal or DX12 with a
|
|
101
|
-
poll thread standing in for the page's event loop, so what the browser suite
|
|
102
|
-
exercises is exercised natively too, and the two produce identical tokens.
|