Skip to content

fix(npu): make FastFlowLM models reachable on Ryzen AI PCs - #6341

Merged
kovtcharov-amd merged 7 commits into
amd:mainfrom
kovtcharov:kalin/flm-models-reachable
Nov 2, 2026
Merged

kovtcharov-amd merged 7 commits into
amd:mainfrom
kovtcharov:kalin/flm-models-reachable

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Pasting a FastFlowLM link failed with "has no GGUF files", a Download of an FLM model failed on any PC that had not run setup since #5892, and FLM models were stuck at a fixed context size. Now a pasted link resolves to the matching model or says where it already is, Download installs the NPU backend first, and an FLM model's window is the smaller of what the model supports and what memory holds, with a manual override that is no longer shrunk.

Measured on the NPU: Gemma 4 E4B read a 79,233-token prompt at a 128K window and answered from its first line. With 13.8 GB free it loaded at 96K on its own; with plenty free, at 128K.

Builds on #5892 and keeps its model list, feature tiers and native tool calls. Refs #5519, #5215.

🔍 Technical details
  • Window: E4B declares a 128K maximum (what Lemonade reports) and a measured 22 KiB/token, so the existing scaling and free-memory fit apply against system RAM. Lower-memory PCs stay at the 64K floor, and free memory can still take it to 32K. The 32K clamp in resolve_ctx_size and the FLM cap are gone; npu_ctx_ceiling is now npu_default_ctx.
  • E2B: it has no size_gb on record because a size would add memory refusals for the email agent, so Automatic stays at FastFlowLM's 32K default. Settings offers it up to 128K, marked as unchecked against memory.
  • Measurements: E2B and E4B both loaded and answered at 32K, 64K, 128K and 256K. A 40K prompt at a 32K window is refused loudly with "Max length reached".
  • Reload bug: ensure_ready compared a resident FLM model to the device profile's window. It now asks the model for its own window, and does not reload an outgoing model at the incoming model's window.
  • Repo-to-model lookup reads src/model_list.json from the exact FastFlowLM release Lemonade reports, cached per release. Gemma4-E4B-IT-NPU2 backs both gemma4-it:e4b and the single-turn gemma4e-flash:e4b; single-turn, embedding and transcription builds are not chat models.
  • Backend install sits in pull_model, pull_model_stream, the Settings download and the TUI's Pull. The TUI row is now downloadable rather than a "run gaia init" dead end.
  • Saved models: custom_models entries may be a built-in *-FLM id as well as user.*. An older build reading such a config rejects it until the entry is removed.
  • is_tool_calling_model reads an added model's saved flag, so a tool-less added GGUF model leaves the native tools path.
  • Eval: E4B on the NPU can now load above 64K on large PCs, which feat(npu): offer GAIA's Gemma on the Ryzen AI NPU, GPU stays default #5892's numbers did not cover. GPU models are unchanged. Watch tool_selection and gaia_core on the NPU when that baseline exists (feat(models): validate every model GAIA offers, then add NPU (FLM) builds like Gemma 4 E4B #5519).

Test plan

  • python -m pytest tests/unit: 34,036 passed before the last 3 expectation fixes, which then pass. Remaining failures are not from this change: 10 need pypdfium2, missing here; test_chat_system_prompt_budget fails on the base commit; one test_lemonade_embedded archive test fails under parallel load and skips alone. 20 more failed only in the parallel run on a shared machine and pass when run alone
  • cd tui && go test ./internal/...
  • python util/lint.py --black --isort --flake8, and pylint on the changed Python files
  • Cold private Lemonade 2026.43.3 on a Ryzen AI MAX+ 395: add by link, Download installs the backend, pulls and loads on the NPU (before the merge with feat(npu): offer GAIA's Gemma on the Ryzen AI NPU, GPU stays default #5892)
  • Agent UI on real NPU after the merge: Automatic loaded E4B at 131,072 tokens, and at 98,304 with 13.8 GB free. A manual 64K loaded at 65,536 and answered
  • Agent UI: the reported link passes every check and points at the model list
  • TUI against a real server after the merge. Go tests only
  • On a PC without an NPU: neither list shows an FLM model, and a FastFlowLM link says why (unit tests only)
  • On a 16 GB Ryzen AI PC: E4B loads and answers. Tested only on 128 GB

Ryzen AI users could not run FLM models from the Agent UI or TUI: the model
lists offered none, and pasting a FastFlowLM Hugging Face link failed with "no
GGUF files". Until its flm:npu backend is installed, Lemonade lists no FLM
model and refuses to pull one by name, and only `gaia init --profile npu`
installed it.

A download of an FLM model now installs the backend first. Both lists offer
Gemma 4 E4B and E2B on a PC with an NPU they fit, and a pasted FastFlowLM link
resolves through that FastFlowLM release's model list to the Lemonade built-in.
FLM models are judged against system RAM rather than the GPU pool, and capped
at the NPU window, so a GPU profile no longer reloads one at 64K on every start.
@github-actions github-actions Bot added documentation Documentation changes devops DevOps/infrastructure changes llm LLM backend changes cli CLI changes tests Test changes performance Performance-critical changes tui Go terminal UI (gaia-tui) labels Nov 1, 2026
A real agent turn on E2B shows its reply as raw JSON, because E2B still uses
the embedded-JSON tool path, so the lists offer E4B alone. E2B's registry
entry is unchanged, so the email agent keeps its behaviour, and its link can
still be added.

The backend install now sits in pull_model and pull_model_stream, so every
pull path gets it and a failure reaches the progress stream. The TUI install
is bound by ctx rather than the 45 second client, gaia init and setup judge an
FLM model on system RAM, a failed Settings download can be retried, and an
added FLM row stays removable on a PC without an NPU.
FLM models are judged on the NPU's system RAM now, so a fake PC that picks one
has to report an NPU.
@kovtcharov
kovtcharov marked this pull request as ready for review November 1, 2026 19:13
Brings amd#5892 in and keeps what it does not cover: a pasted FastFlowLM link
resolves to its built-in, and a download installs the NPU backend for anyone
who has not re-run setup.

FLM models no longer stop at a fixed 32K. E4B gets the smaller of its 128K
maximum and what memory holds; on a real NPU it read a 79,233-token prompt at
128K. E2B stays at FastFlowLM's default on Automatic because it has no size on
record, and offers up to 128K by hand. A size picked in Settings or set with
GAIA_CTX_SIZE is no longer shrunk.

Startup now asks an FLM chat model for its own window instead of the device
profile's, which is what reloaded it on every start. The outgoing model is not
reloaded at the incoming model's window.
@github-actions github-actions Bot added agents daemon Daemon supervisor / sidecar control plane labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

I found no blocking problems. The FastFlowLM link lookup refuses loudly at every step. It checks for an NPU before fetching anything, validates the release tag before it goes into a URL, and drops model-list entries it can't trust. The backend install runs before both Python pull paths, the Settings download, and the TUI Pull. Removing the 32K NPU clamp is backed by real-NPU measurements, and the new tests start from a cold Lemonade, which is the state that matters here.

Three small suggestions:

  • 🟢 Settings download looks stalled while the NPU backend installs. That install can take up to 10 minutes, and the whole time the row shows "starting" with no message. A short "Installing Lemonade's NPU backend…" message would tell the user it is still working.
  • 🟢 Saved -FLM entries break older builds. Once a user adds an FLM model, an older GAIA or TUI rejects the whole custom_models list. The PR body mentions this. It should also go in the release notes so a user who downgrades knows to run gaia model remove.
  • 🟢 Evidence: the Agent UI Settings flow (add by link, then Download installs the backend) has text evidence but no screenshot. One before/after screenshot of the model row would close that gap. The TUI-against-a-real-server item is still unchecked; finish it before merge or note it as deferred.
🔍 Technical details
  • src/gaia/ui/routers/system.py _stream_lemonade_pull: await asyncio.to_thread(_install_npu_backend, model_name) runs after progress is set to {"state": "starting", "message": None}. install_backend waits up to NPU_BACKEND_INSTALL_TIMEOUT (600 s). Calling _set_download_progress(..., message="Installing Lemonade's NPU backend…") before the to_thread call would cover it.
  • custom_models.validate_entries now accepts _FLM_ID_RE ids, and tui/internal/lemonade/custom.go accepts any -FLM suffix. Builds before this one raise GaiaConfigError or a ReadCustomModels error for the whole list.
  • Checked and fine:
    • context_choice.context_range: the new max_ctx_size-without-memory-figures branch only affects gemma4-it-e2b-FLM. Every GPU entry with max_ctx_size also has size_gb and kv_bytes_per_token, so GPU behaviour is unchanged as claimed.
    • is_tool_calling_model now reads find_custom_model, which is mtime-cached. A corrupt config raises instead of silently falling back, which matches fail-loudly.
    • _try_reload_with_ctx(own_window_of=...) returns ready when a different model is resident. The incoming FLM load then sets its own window.

A first FLM download can spend minutes installing Lemonade's NPU backend, and the row sat at 0% with no explanation. Settings and the connection banner now show what it is waiting on.
@kovtcharov-amd kovtcharov-amd added this to the v0.25.4 milestone Nov 2, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 2, 2026
Merged via the queue into amd:main with commit d2c3728 Nov 2, 2026
98 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/flm-models-reachable branch November 2, 2026 18:12
kovtcharov-amd added a commit to huong8373tt-beep/gaia that referenced this pull request Nov 3, 2026
Running Gemma-4-E4B on the Ryzen AI NPU through the agent evals turned
up bugs that ended turns badly. Asked to total eight short regional
reports, the agent summed only five, because search returned at most
five chunks even when the whole index was smaller than that. A model
reply with zero tokens ended the turn on "I received an empty response,
please try again". This happens on about 1 in 250 NPU calls after a long
prompt. Told to "Index <folder>", the model asked "Should I index it?".
It also treated an instruction planted in a PDF as a possibly valid
override, and gave in when pushed on a correct fact. Each case now
recovers: a small index comes back whole, an empty reply or a needless
permission question costs one bounded re-prompt, and the prompt names
injection and fact-holding rules.

Follows amd#6341, which made the FastFlowLM models reachable.

- **Prompt changes reach every model, not just the NPU.** Duplicate
rules were merged to pay for the new ones. The full profile is 11,925
chars on Linux, under its 12K budget (11,844 before). The GPU eval on
the next RC covers `gaia_core`, `gaia_rag` and `tool_selection`.
- **Results on the NPU (Gemma-4-E4B FLM, 128K window):** document Q&A
went from 14/19 to 17/19 and core from 10/15 to 11/15 before the last
round of fixes. The rerun on this branch is still going; results will be
added here.

## Test plan
- [x] `python -m pytest tests/unit hub/agents/gaia/python/tests` —
passes, except three tests that need Playwright, which isn't installed
on the test machine
- [x] Prompt goldens recaptured against an empty `GAIA_CONFIG_FILE` (no
local default model)
- [ ] `gaia_rag` and `gaia_core` evals on the NPU on this branch's final
commit
- [ ] GPU eval on the next RC: `gaia_core`, `gaia_rag`, `tool_selection`

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents cli CLI changes daemon Daemon supervisor / sidecar control plane devops DevOps/infrastructure changes documentation Documentation 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