Skip to content

perf(lemonade): run the embedder on CPU instead of slowing every model - #4512

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/embedder-on-cpu
Oct 2, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:kalin/embedder-on-cpu

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

On Strix Halo, every chat model GAIA ran read prompts at about half speed. To stop the embedding model crashing on AMD Radeon GPUs (#1831), GAIA started Lemonade with a flag that turns off llama.cpp's fast matrix path for every model. Measured on a Radeon 8060S with Qwen3 30B A3B, prompt processing dropped from 1,293 to 683 tokens/s. Long agent turns pay that on every step, and the troubleshooting guide understated it as "about 12%". Now only the small embedder moves to the CPU backend, where it embeds a query in about 34 ms, and chat models get the full GPU path back.

Test plan

  • Reproduced on this 8060S: with the flag off, the embedder fails to start on Vulkan ("llama-server failed to start") and works on llamacpp_backend=cpu, including Lemonade's own on-demand load once the option is saved.
  • gaia lemonade embedded start from this branch: lemond has no GGML_VK_DISABLE_COOPMAT, recipe_options.json pins the embedder to CPU, and GAIA's client loads it and returns a 768-dimension embedding.
  • pytest tests/unit/test_embedder_cpu_backend.py tests/unit/test_lemonade_launcher.py tests/unit/test_lemonade_embedded.py tests/unit/test_memory_mixin.py tests/unit/test_ui_gpu_detection.py: no failures beyond those main has on Windows.
  • On a Strix Halo box: llama-bench or a Qwen3 30B chat shows prompt processing near 1,300 tokens/s on a GAIA-started Lemonade, and memory and document search work.

@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes tests Test changes performance Performance-critical changes labels Sep 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

Moving only the embedder to the CPU backend is the right fix: chat models get their GPU prompt speed back and the embedder still avoids the Vulkan crash. The change is incomplete in two places, though, so some users would lose the speedup and others would get the crash back.

  • The TUI and the Windows installer scripts still set the slow flag. A Lemonade started from the TUI (the flagship path) or by the installer's start/scheduled-task scripts still runs every model at about half prompt speed. The TUI's comment says it "matches" a Python constant this PR deletes. Drop the flag from those launchers too, or say in the PR that they're deliberately left out.
  • Memory can crash again on a user-installed Lemonade that GAIA starts. The CPU choice is saved to Lemonade only for the embedded server. On any other server GAIA starts, the flag is now gone but nothing saves that choice. Memory doesn't load the embedder explicitly; its first embedding request makes Lemonade load the model itself, which puts it back on Vulkan, the same crash as CI: Lemonade v10.7.0 breaks embedding-model jobs (nomic-embed-text-v2-moe / llama-server ≥ b6524) #1831. Save the choice when GAIA loads the embedder (save_options), or keep the flag on those launches until that's done.

Real-world evidence

N/A: no evidence bundle was produced for this run. The PR description reports manual runs on a Radeon 8060S (the embedder fails on Vulkan and works on CPU; gaia lemonade embedded start saves the CPU choice and returns a 768-dimension embedding), but it doesn't paste their output. The Strix Halo throughput check is still unchecked. This verdict rests on static review for the launch and auto-load paths.

🔍 Technical details

🟡 TUI and installer launchers still set GGML_VK_DISABLE_COOPMAT=1

  • tui/internal/ui/preflight/autostart.go:96 / :103-106: startEnv still appends vulkanCoopmatEnv, and its comment points at LLAMACPP_ENV, which this PR removes. ctxsize.go:130-148 still prints the flag in start hints, and lemonade_test.go / autostart_test.go assert it. The Python and Go start hints now disagree for the same machine.
  • installer/scripts/start-lemonade.ps1:164 and installer/scripts/ensure-lemonade-running.ps1:162-168 still set it. The second one's comment says "every OTHER way GAIA starts Lemonade sets it", which is no longer true.

Either update these in this PR, or state the scope in the PR and track the rest in an issue. As it stands, the headline claim ("chat models get the full GPU path back") holds only for the embedded server and the daemon's Python launch path.

🟡 Auto-loaded embedder falls back to Vulkan on non-embedded GAIA-started servers (lemonade_client.py:4647, lemonade_launcher.py:264-291)
llamacpp_backend_for only affects explicit /load calls, and _pin_llamacpp_backends only runs for EmbeddedLemonade. For build_start_command launches (Windows .exe --silent, the LEMONADE_SERVER_PATH override, legacy), the env flag is removed and no saved option replaces it. MemoryMixin validates by calling embeddings directly (memory.py:747-800), so on these servers Lemonade auto-loads the embedder with its default backend. The same thing happens after any eviction, even after RAG's explicit load (rag/sdk.py:536), because that load doesn't set save_options. One option is to persist the backend whenever it's forced:

        backend = llamacpp_backend_for(model_name)
        if backend:
            request_data["llamacpp_backend"] = backend
            # Persist so Lemonade's own auto-loads (/embeddings) use it too.
            save_options = True

That still needs one explicit load before the first embedding, so memory init would also have to load the embedder (or GAIA would have to pin it through /load at server start).

🟢 Inconsistent handling of unreadable files (lemonade_embedded.py:620-628)
write_config warns and replaces an unreadable config.json, but _pin_llamacpp_backends raises on an unreadable recipe_options.json, and a non-dict JSON value is silently replaced with {}. Raising is the better fit for the fail-loudly rule. For consistency, also raise (or at least log) when the JSON isn't an object, rather than discarding it silently.

🟢 Leftover string concatenation (test_lemonade_launcher.py:638, :665)
'"C:\\Program Files\\lemonade\\' 'lemonade-server.exe" serve --no-tray' and ("set LEMONADE_CTX_SIZE=32768 && " "C:\\lemonade\\lemond") are left over from the old multi-line strings. Join each into a single literal.

Strengths

  • A per-model backend choice replaces a global performance penalty, and it comes with a measured justification (1,293 → 683 tok/s).
  • _pin_llamacpp_backends merges into Lemonade's existing recipe_options.json instead of overwriting it, and test_embedded_lemonade_pins_the_embedder_for_auto_loads checks that other models' saved options survive.
  • The troubleshooting doc and backend_crash_remedy were updated together, and the doc now states the real cost of the flag instead of "about 12%".

Every Lemonade GAIA started carried GGML_VK_DISABLE_COOPMAT=1 to stop
llama.cpp's Vulkan cooperative-matrix crash when loading the embedding
model on AMD Radeon iGPUs (amd#1831). The flag also turned off the fast
matrix path for chat models: Qwen3 30B A3B on a Radeon 8060S dropped from
1,293 to 683 prompt tokens/s. Generation was unaffected.

The embedder now loads on llama.cpp's CPU backend instead: every load GAIA
makes asks for it, and GAIA's embedded Lemonade saves it in its recipe
options so Lemonade's own on-demand loads use it too. A query embeds in
about 34 ms and 60 document chunks in about 7 s on the CPU. The global flag
is gone from every launch path, and the troubleshooting guide and crash
remedy describe the new setup.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Rebased onto main (picks up the abstract-method pylint fix from d4bb243 — that's why Code Quality Checks was red; otherwise your changes applied clean, no conflicts). The Windows/macOS smoke-lane failures are the usual non-blocking flakes (continue-on-error: true): NTFS permission bits in test_store.py on Windows, and an unrelated mocked-embedding memory-recall test on macOS that doesn't touch Lemonade at all. The Strix Halo Agent SDK failure looks like the known Qwen3-thinking-exhausts-max_tokens flake (already called out in that test's own comment) — re-ran it, unrelated to this diff.

The perf fix itself is sound and worth landing: moving only the embedder to CPU is the right call, and 1,293→683 tok/s is a real, well-measured regression to undo.

But I can't merge yet — verified two gaps that mean the fix doesn't reach most users on a Radeon iGPU:

  • A user-installed or daemon-started Lemonade (the common Windows path, build_start_command in lemonade_launcher.py) now sets no Vulkan workaround and no backend pin. llamacpp_backend_for is only consulted by an explicit /load call, and _pin_llamacpp_backends only runs inside EmbeddedLemonade.write_config. MemoryMixin._embed_text → LemonadeClient.embeddings() hits /embeddings directly with no prior /load, so Lemonade auto-loads the embedder on its default (Vulkan) backend on first use — reintroducing the CI: Lemonade v10.7.0 breaks embedding-model jobs (nomic-embed-text-v2-moe / llama-server ≥ b6524) #1831 crash this PR exists to prevent, for everyone except GAIA's self-managed embedded server.
  • The TUI (tui/internal/ui/preflight/autostart.go) and the installer scripts (installer/scripts/start-lemonade.ps1, ensure-lemonade-running.ps1) still set GGML_VK_DISABLE_COOPMAT=1 globally, unchanged by this PR — so chat models started through those front doors keep paying the full 683 vs 1,293 tok/s penalty the PR's own commit message says is now fixed everywhere.

Pushed the rebase to unblock the stale pylint check, but leaving this open rather than merging until the backend pin covers the non-embedded auto-load path (or memory/RAG explicitly /loads the embedder with llamacpp_backend=cpu before first use) and the TUI/installer scope is either closed or called out explicitly as follow-up.

… own

Memory's first embedding made Lemonade load the embedder by itself, on its
default Vulkan backend, so any server other than GAIA's embedded one could hit
the amd#1831 crash again now that the global Vulkan flag is gone. GAIA now loads
the embedder on the CPU backend before its first embedding and saves that
choice in Lemonade, so later auto-loads use the CPU too.

The TUI no longer sets the flag when it starts Lemonade or prints a start
command, so chat models it launches get their full prompt speed back. The CI
runner scripts keep it. An options file that is not a JSON object now fails
loudly instead of being replaced.
@github-actions github-actions Bot added installer Installer changes tui Go terminal UI (gaia-tui) labels Oct 2, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 2, 2026
Merged via the queue into amd:main with commit a6c9c18 Oct 2, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/embedder-on-cpu branch October 2, 2026 08:58
kovtcharov-amd added a commit to aksh8b/gaia that referenced this pull request Oct 6, 2026
…sh Qwen3.6 (amd#4674)

On a Strix Halo with an older AMD driver, the new default model couldn't
answer at all: Qwen3.6-35B-A3B loaded, then llama-server died on its
first token, so `gaia init` failed its verification. llama.cpp's Vulkan
cooperative-matrix path is the cause. Turning it off fixes the crash but
halves prompt speed on drivers that don't crash (amd#4512 removed a blanket
version of this flag for that reason). GAIA's embedded Lemonade now
turns coopmat off only on a Strix Halo iGPU (8060S/8050S/8040S, Windows)
whose driver is at or below the version measured crashing. Newer drivers
keep the faster path, and a `GGML_VK_DISABLE_COOPMAT` the user set
always wins.

| Strix Halo, Vulkan, llama.cpp b10825 | coopmat on (default) | coopmat
off |
|---|---|---|
| Qwen3.6 on driver **32.0.12078.30** | crashes on first token | 273
tok/s prompt, 34.0 tok/s gen |
| Qwen3.6 on driver **32.0.31016.2** (May 2026) | loads and answers
(400-token reply in 23 s, no watchdog reset) | — |
| Qwen3-30B (from amd#4512) | 1,293 tok/s prompt | 683 tok/s prompt |

## Test plan
- [x] `pytest tests/unit/test_lemonade_embedded.py
tests/unit/test_embedder_cpu_backend.py` (86 passed): old driver turns
coopmat off on each Strix Halo name; driver 32.0.12078.31 and newer,
other GPUs, an unreadable version, non-Windows and a user-set value
leave it alone; the real registry reads without raising
- [x] On a Strix Halo with driver 32.0.31016.2 and no override, Qwen3.6
loads through the embedded Lemonade and answers
- [x] `python util/lint.py --black --isort --flake8`

<details>
<summary>🔍 Technical details</summary>

- `_windows_display_adapters()` returns `(DriverDesc, DriverVersion)`
from the display-adapter class key; `vulkan_workarounds()` compares the
parsed version to `_COOPMAT_BROKEN_THROUGH = (32, 0, 12078, 30)`.
- The first driver that fixes the crash is unknown — only these two
points are measured. A driver between them is treated as working; if one
crashes, raise `_COOPMAT_BROKEN_THROUGH` or set
`GGML_VK_DISABLE_COOPMAT=1`.
- An unreadable version logs at info with the remedy and leaves coopmat
on.
</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes installer Installer changes llm LLM backend changes performance Performance-critical changes tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants