Skip to content

Offline AI: performance settings, thinking mode, speed display and real cancel (for plugin 1.1.0) - #994

Open
4di-hello wants to merge 2 commits into
LeanBitLab:mainfrom
4di-hello:pr/offline-ai-stage2
Open

4di-hello wants to merge 2 commits into
LeanBitLab:mainfrom
4di-hello:pr/offline-ai-stage2

Conversation

@4di-hello

Copy link
Copy Markdown
Contributor

Goes with the plugin PR LeanBitLab/LeanType-Offline-AI-Plugin#3 (current llama.cpp, about twice as fast).

What changes

  • Chat messages to the plugin: besides the prompt, the keyboard passes chat_system and chat_user. Plugin 1.1.0 puts them into the chat format stored in the model, which works for every model family (Gemma, Qwen, Llama, …). Older plugins ignore them and use the prompt as before.
  • "Thinking mode" is its own switch (default off). "Show thinking" only shows the thoughts of a model that thinks, it doesn't make it think. With thinking on, the answer gets 1024 more tokens. Behaviour change: until now "Show thinking" also let Qwen3 think. Who wants that keeps it by switching on "Thinking mode".
  • New section "Performance" in the offline AI settings:
    • Threads: Automatic (the fast cores, at most 4) or 2 (saves battery). More threads than fast cores are slower: all threads wait for the slowest core at every token.
    • Context size: 4096 (default, as now), 2048, 1024 tokens. Less memory for short texts.
    • Show speed (default off): after each answer a toast with tokens, seconds, tokens/s, time to read the text and total time since the key, plus the loading time when the model was loaded. The numbers come from the plugin's lastStats() (plugin 1.1.0, only numbers, called by name like cancelGeneration()); with an older plugin only the total time is shown.
    • A changed setting loads the model again with the next request.
  • max_tokens is limited so that prompt and answer fit into the context.
  • Cancel really stops: cancelling a request (X on the key, keyboard hidden) calls cancelGeneration() in the plugin if it has it. Before, the plugin kept computing in the background and the next request waited for it.
  • "Keep model loaded" now says what it does: without it the model is unloaded after 10 minutes, with it it uses 2–5 GB of memory.
  • Strings in English and German.

How we tested

Same phone and test text as in the plugin PR (German paragraph, 11 built-in mistakes, Dimensity 9400+). The speed display was built first because hand-stopped times were up to a third too low; with it every change could be measured.

  • Threads: 4 (automatic) vs. 8 in the comparison apps Offline LLM and PocketPal: 4 more than twice as fast. That's why "automatic" means at most 4.
  • Context size: 2048 tokens were too few for a long text (about 5000 characters of German), the model then generated nothing. 4096 stays the default.
  • Cancel: the speed display showed the numbers of an earlier, cancelled request about 3 s after a new one: the cancelled one had kept computing. With cancelGeneration() the next request starts at once, and cancelled requests show no display.
  • Result with this PR, plugin 1.1.0 and Gemma 4 E2B QAT: 139 tokens at 17.5 tokens/s, text read in 1.2 s, 9.2 s from the key to the corrected text (old plugin with Qwen3-4B: about 18 s). 11/11 mistakes fixed. Cancel with the X and a new request right after: the new one starts at once.

It was a lot of testing, many builds and measurement series on the phone, but I think the effort was worth it: from the key to the corrected text it's now about half the time it was.

All work and measurements were done with Claude Code; I tested every version on the phone.

🤖 Generated with Claude Code

4di-hello and others added 2 commits November 28, 2026 17:53
…ing mode, speed display), cancel a running generation

- The chat messages are passed to the plugin as well (chat_system, chat_user): plugin 1.1.0 puts them
  into the chat format stored in the model, which works for every model family. Older plugins keep
  using the prompt as before.
- Thinking mode is its own switch, "Show thinking" only shows the thoughts.
- Performance: threads (automatic = the fast cores, at most 4), context size 4096/2048/1024, speed
  display after each answer (read from the numbers plugin 1.1.0 logs). A changed setting loads the
  model again with the next request.
- Cancelling a request (X, keyboard hidden) stops the generation in plugin 1.1.0 instead of letting it
  finish in the background.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g, answer limit by the prompt length

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant