Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions quant.h
Original file line number Diff line number Diff line change
Expand Up @@ -15462,14 +15462,13 @@ int tq_generate(tq_model_t* model, tq_tokenizer_t* tokenizer,
}

/* Prefill: process all prompt tokens.
* On Emscripten with ASYNCIFY, yield every 2 tokens so the browser
* can repaint (shows "Thinking..." and avoids "page unresponsive"). */
* NOTE: No emscripten_sleep() here — the call stack during tq_forward()
* is too deep for ASYNCIFY to unwind (matmul → SIMD kernels). Adding
* sleep here breaks ASYNCIFY for the entire generate call, including
* the token streaming callback. The browser shows "Thinking..." via
* requestAnimationFrame before entering this blocking prefill. */
for (int i = 0; i < n_prompt; i++) {
tq_forward(model, state, prompt_tokens[i], i);
#ifdef __EMSCRIPTEN__
extern void emscripten_sleep(unsigned int ms);
if (i % 2 == 1) emscripten_sleep(0);
#endif
}

/* Repetition penalty setup */
Expand Down
2 changes: 1 addition & 1 deletion wasm/quant.js

Large diffs are not rendered by default.

Binary file modified wasm/quant.wasm
Binary file not shown.
Loading