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
8 changes: 7 additions & 1 deletion quant.h
Original file line number Diff line number Diff line change
Expand Up @@ -15461,9 +15461,15 @@ int tq_generate(tq_model_t* model, tq_tokenizer_t* tokenizer,
fprintf(stderr, "\n");
}

/* Prefill: process all prompt tokens */
/* Prefill: process all prompt tokens.
* On Emscripten with ASYNCIFY, yield every 2 tokens so the browser
* can repaint (shows "Thinking..." and avoids "page unresponsive"). */
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
5 changes: 5 additions & 0 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ <h2>LLM in Your Browser</h2>
};

const chatPrompt = getChatPrompt(text);

// Ensure "Thinking..." paints before WASM blocks the thread.
// Double-rAF guarantees the browser completes one paint cycle.
await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));

const promptPtr = Module.allocateUTF8(chatPrompt);
try {
await Module._wasm_generate_async(promptPtr, 0.7, 256);
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