Commit 6089212
wasm: fix generation hang — add ChatML template + async generate
Two bugs causing WASM demo to hang after model loads:
1. **Missing chat template**: user prompt sent raw ("hello?") without
ChatML wrapping. SmolLM2-Instruct generates 0 tokens without the
<|im_start|>user/assistant template. Same bug we fixed in Python
bindings (v0.8.3). Fix: JS wraps prompt with ChatML before calling
wasm_generate.
2. **UI freeze**: wasm_generate is synchronous (blocks main thread).
The browser can't update the UI while inference runs. Fix: wrap the
WASM call in setTimeout(50ms) to yield one frame for the spinner.
Also fixed: free(result) → quant_free_string(result) for consistency
with the cross-heap safety pattern, and better empty-result handling.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 618845b commit 6089212
2 files changed
+19
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
| 303 | + | |
| 304 | + | |
307 | 305 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
313 | 318 | | |
314 | 319 | | |
315 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
0 commit comments