Skip to content

feat(agents): multi-device support — CPU, GPU, NPU per-agent selection - #1252

Merged
kovtcharov-amd merged 2 commits into
mainfrom
kalin/npu-flm-profile
May 29, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
kalin/npu-flm-profile

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

GAIA agents couldn't leverage AMD Ryzen AI NPU hardware — inference defaulted to GPU via llamacpp with no way to select an alternative device. Users with XDNA2 NPUs had no path to power-efficient local inference, and there was no framework for per-agent device selection across CPU, GPU, and NPU.

Now each agent declares which devices it supports via DeviceConfig tuples. Users pick a device per-agent — dropdown in Agent UI, --device {cpu,gpu,npu} on CLI. GPU remains the default. NPU uses the FLM backend (gemma4-it-e2b-FLM); CPU falls back automatically with a latency warning. gaia init --profile npu handles NPU detection, FLM backend installation, and model download. Eval-verified on Ryzen AI MAX+ PRO 395: NPU matches or exceeds GPU quality (personality 3/3 @ 9.5/10, context_retention 4/4 @ 9.8/10) at ~24 tok/s.

Test plan

  • python -m pytest tests/unit/test_npu_device_support.py -xvs — 25 tests
  • gaia chat --device gpu — announces device, loads correct model
  • gaia chat --device npu — loads FLM model on NPU hardware
  • gaia chat --device cpu — warns about slow response times
  • gaia init --profile npu — detects NPU, installs FLM backend, downloads model
  • gaia init --profile npu on non-NPU hardware — fails loudly
  • gaia eval agent --device npu --category personality — all scenarios pass
  • Agent UI: device dropdown visible on agent cards, filtered by detected hardware

#1220)

Agents now declare which (device, model, recipe, backend) tuples they support
via DeviceConfig. Users pick a device per-agent in the Agent UI dropdown or
via `--device {cpu,gpu,npu}` on CLI. GPU is the default. NPU uses the FLM
backend on Ryzen AI XDNA2 hardware; CPU falls back with a latency warning.

Backend: DeviceConfig dataclass, GaiaConfig persistence (~/.gaia/config.json),
LemonadeClient.install_backend/uninstall_backend/get_recipe_status,
LemonadeManager device parameter, session-level device column + migration.

CLI: `gaia init --profile npu` (NPU detection, FLM backend install, recipe-
aware model download), `gaia chat --device npu`, `gaia eval agent --device npu`.

Frontend: DeviceConfig type, activeDevice/detectedDevices store state,
per-agent device dropdown with verified/unverified badges.

Eval-verified on Ryzen AI MAX+ PRO 395: NPU matches or exceeds GPU quality
(personality 3/3 9.5avg, context_retention 4/4 9.8avg) at ~24 tok/s.
@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes cli CLI changes tests Test changes electron Electron app changes performance Performance-critical changes agents labels May 29, 2026
@kovtcharov-amd
kovtcharov-amd requested a review from itomek-amd May 29, 2026 07:33
@kovtcharov-amd kovtcharov-amd self-assigned this May 29, 2026
- Black: reformat cli.py
- Pylint: remove reimport of LemonadeClient (already at module level)
- Flake8: remove unused imports (tempfile, Path) in test file
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

@itomek-amd, this feature requires manual testing.

@itomek itomek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid, well-layered feature: the device abstraction threads cleanly from DeviceConfig/DEFAULT_DEVICE_CONFIGS in registry.py through the CLI --device, the sessions DB migration, the agents API response, and the UI dropdown, with docs (npu.mdx + docs.json) and a 382-line test file. GPU stays the default and explicit-device requests fail loudly when hardware is missing — the right shape. One process note: this is an LLM-affecting change (it swaps the model per device), and CLAUDE.md asks for a gaia eval agent run compared to the committed baseline. The description cites strong NPU numbers but no baseline scorecard / --compare output is included — worth attaching so a reviewer can see GPU-vs-NPU parity rather than take the numbers on faith, especially since the NPU path runs at a much smaller ctx (4096 vs 32768). Two small inline notes on the device-probe except: pass and the _DEVICE_TO_MIN cpu omission. Approving on the understanding the eval evidence gets attached.


Generated by Claude Code

Comment thread src/gaia/cli.py Resolved
Comment thread src/gaia/llm/lemonade_manager.py Resolved
@kovtcharov-amd
kovtcharov-amd enabled auto-merge May 29, 2026 16:26
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue May 29, 2026
Merged via the queue into main with commit d12c79f May 29, 2026
48 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/npu-flm-profile branch May 29, 2026 16:26
kovtcharov-amd pushed a commit that referenced this pull request Jun 2, 2026
…untime

Multi-device support (#1252) shipped non-functional: the Agent UI device
dropdown and CLI --device flag never changed the model, and an unavailable
device degraded silently. Fixes v0.20.0 release-review blockers B1/B2/H1
plus a GPU-tier validation bug.

B1: resolve the device's DeviceConfig.model (and ctx_size) at every UI
agent-build site instead of always using the session/GPU model; rewrite the
session model on a device switch so eviction/recreation picks it up. A guard
keeps an agent's own pinned model from being clobbered on the default GPU.

B2: add a device field to ChatAgentConfig, thread it through the base Agent
into LemonadeManager.ensure_ready(device=...), and fail loudly with an
actionable HardwareRequirementError when the requested device is absent.

H1: narrow the CLI device-probe except clause to only swallow connection/
timeout errors; a reachable-but-broken Lemonade now surfaces. Make the
GPU->CPU fallback state its reason.

Medium: map the gpu selector to amd_dgpu (lowest GPU tier) so a discrete-
Radeon-only host satisfies an explicit GPU requirement.
kovtcharov-amd pushed a commit that referenced this pull request Jun 3, 2026
19 PRs merged to main after the v0.20.0 notes were drafted; merge main into
the release branch and update the notes to match.

- Multi-Device: note #1338 wired the selector end-to-end (it was a no-op
  after #1252 alone) and added loud runtime validation for unavailable devices.
- PowerPoint RAG: note #1366 unblocked .pptx in the Agent UI file picker
  (backend already accepted it; the frontend rejected it pre-upload).
- Activations: note #1310 widened the "Active for" panel to MCP-consuming
  agents (e.g. the chat agent), not just static REQUIRED_CONNECTORS.
- New bug fixes: RAG embedding reuse (#1306), overlapping-chat-turn 409
  (#1304), Memory/Settings mutual exclusivity (#1368).
- Tooling/CI: doc-vs-code realignment (#1298/#1337/#1340), gaia-testing
  skill (#1372), Claude CI + Codecov hardening.
- Full Changelog regenerated: 44 -> 63 commits.
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Jun 3, 2026
…untime (amd#1338)

## Why this matters

Multi-device support shipped in amd#1252 but the device selector never
actually changed anything. Before: picking **NPU** in the Agent UI
dropdown (or passing `--device npu`) silently rebuilt the agent on the
**GPU** model — the choice was a no-op, and a request for hardware the
host didn't have ran somewhere else without warning. After: selecting a
device switches the model (and context window) to that device's
registered config, and an unavailable device fails loudly with an
actionable remedy instead of degrading silently.

This addresses the v0.20.0 release-review blockers **B1**, **B2**, and
**H1**, plus one medium GPU-tier bug:

- **B1 — UI dropdown was a silent no-op.** The UI wrote `session.device`
and evicted the agent, but every build site resolved the model from
`session["model"]`, never the device's `DeviceConfig.model`. Now the
device's model/ctx drive the rebuilt agent, and a device switch rewrites
the session model so eviction/recreation picks it up. A guard keeps an
agent's own pinned model from being clobbered on the default GPU device.
- **B2 — runtime never validated the chosen device.** `ChatAgentConfig`
gained a `device` field that threads through the base `Agent` into
`LemonadeManager.ensure_ready(device=...)`. An NPU request on a host
without an NPU now raises an actionable `HardwareRequirementError` ("NPU
not available… run `gaia init --profile npu`, or choose --device gpu")
instead of silently running elsewhere.
- **H1 — CLI swallowed all device-probe errors.** `except Exception:
pass` is narrowed to only treat genuine "server not reachable yet"
(connection refused / timeout) as a soft pass; a reachable-but-broken
Lemonade (HTTP 5xx, 401) now surfaces. The default GPU→CPU fallback says
*why* ("No GPU detected; falling back to CPU (slower). Run `gaia
init`…").
- **Medium — `gpu` rejected discrete Radeon.** `_DEVICE_TO_MIN` mapped
`gpu`→`amd_igpu`, so an explicit GPU requirement misvalidated on a
dGPU-only box. It now maps to the lowest GPU tier (`amd_dgpu`),
accepting integrated **or** discrete graphics.

> **NPU quality eval is out of scope here and must be run by a
maintainer on Ryzen AI hardware before tag:**
> `gaia eval agent --device npu --category
context_retention,rag_quality`
> NPU runs a 2B FLM model at 4K ctx vs GPU's 4B at 32K, so a quality
delta is expected and needs hardware to measure — it can't run in CI.

## Test plan

- [x] `python util/lint.py --black --isort --flake8` — all pass
- [x] `python -m pytest tests/unit/ -k "device or chat or agent"` — 1519
passed (2 failures are pre-existing on `main` and unrelated: a
Windows-only `read_text()`/cp1252 quirk over an existing ❌ emoji, and an
unrelated memory-reconcile test)
- [x] New `tests/unit/test_multi_device_wiring.py` — device→model
resolution (UI + CLI), `gpu` accepts igpu **and** dgpu, unavailable
device raises an actionable error, `device` threaded base Agent →
`ensure_ready`
- [x] New cases in
`tests/unit/chat/ui/test_chat_helpers_model_resolution.py` — full
`_get_chat_response` flow: NPU switches the model + threads
`device`/`min_context_size`; explicit non-GPU device overrides a pinned
model; default GPU does **not** clobber a pinned model; `custom_model`
still wins
- [x] `tests/unit/chat/ui/test_database.py` —
`update_session(model=...)` device-switch rewrite
- [ ] Maintainer: NPU quality eval on Ryzen AI hardware (see note above)

---------

Co-authored-by: Ovtcharov <[email protected]>
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Jun 15, 2026
…amd#1658)

## Why this matters

`gaia init --profile npu` was dead on arrival: it failed at the
model-download step with `HTTP 400` before any NPU user could get set up
(amd#1655). The init flow pulled `gemma4-it-e2b-FLM` with `recipe=flm`, but
Lemonade only allows a `recipe`/`checkpoint` on `/pull` when
*registering a new user model* (which must carry a `user.` prefix).
`gemma4-it-e2b-FLM` is a **built-in** Lemonade model, so it must be
pulled by name only. After this fix the NPU profile downloads, verifies,
and runs inference on the NPU.

Root cause was a wrong assumption added in amd#1252 that FLM models need
their recipe at pull time. They don't — the recipe is baked into the
built-in model and applied at load time. The fix routes the download
through `ensure_model_downloaded` (pull by name, with an
already-downloaded pre-check), same as every other profile.

This PR also adds a CLAUDE.md testing rule so the *class* of bug can't
recur silently: amd#1655 passed every test only because they ran against a
warm model cache and a mocked client, so the fresh-pull 400 never
surfaced. The rule requires (1) testing setup/download paths from a cold
state — runtime-verified ≠ setup-verified — and (2) asserting
external-API call *shape* rather than trusting a mocked `200`.

## Test plan

Validated on real XDNA2 hardware (AMD Ryzen AI MAX+ PRO 395, FLM npu
backend v0.9.39, Lemonade 10.4.0):

- [x] **Reproduced** the bug: `POST /pull
{"model_name":"gemma4-it-e2b-FLM","recipe":"flm"}` → `400 ... must
include the user. prefix`; without `recipe` → `200
{"status":"success"}`.
- [x] **CLI cold path:** `gaia init --profile npu --yes --force-models`
— model is *deleted* then re-pulled successfully (no 400) and passes
inference verification (`gemma4-it-e2b-FLM - OK (ctx: 4096)`).
- [x] **Agent UI / NPU inference:** chat completion on
`gemma4-it-e2b-FLM` returns correctly with the model loaded on `device:
npu, recipe: flm`; the UI device resolver maps `npu → gemma4-it-e2b-FLM
(ctx 4096)`.
- [x] **Unit test** added
(`test_npu_profile_pulls_builtin_model_without_recipe`) — regression
guard that the npu profile pulls by name and never calls
`pull_model(recipe=...)`. Full `TestDownloadModels` suite green.

Fixes amd#1655

---------

Co-authored-by: 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 documentation Documentation changes electron Electron app changes llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants