Skip to content

fix(llm): size each model's context to the model, not the device profile - #4670

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:kalin/ctx-scales-with-memory
Oct 4, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:kalin/ctx-scales-with-memory

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

GAIA loaded models at 32K on machines with room for far more. Any PC whose config said default_device: npu capped every model at the NPU's 32,768 tokens, including GPU models that never touch the NPU, so long tasks overflowed. On the CI pool all four TheRock tasks failed this way with Qwen3.6. After this change the NPU limit applies only to NPU models, and a model can declare its native context so GAIA gives it the largest window that fits the machine's memory. No model on main opts in yet, so Gemma stays at 64K; #4479 opts Qwen3.6 in.

How CI got there: a cold gaia init --profile npu job runs under its own GAIA_HOME, but config.json ignored GAIA_HOME and was written to the runner's real home. The next job on that box read npu. config.json now follows GAIA_HOME.

Test plan

  • pytest tests/unit/test_ctx_scales_with_memory.py tests/unit/test_context_size_resolution.py tests/unit/test_base_agent_lemonade_api_key.py tests/unit/test_gaia_home.py
  • On an NPU-profile machine (gaia config set default_device npu), gaia llm "hi" loads Gemma at 65536, not 32768 (lemond.log: Ensuring model loaded: Gemma-4-E4B-it-GGUF ctx_size=65536)
  • Re-run the flagship eval workflow (eval_flagship.yml, scenario lanes and the outcomes/TheRock lane). This changes the context Lemonade loads on NPU-profile runners, so it affects LLM behaviour.
  • Clear default_device from C:\Users\Administrator\.gaia\config.json on the strix-halo boxes that ran the NPU init job (d01, d04, d07), so they stop carrying the leaked setting
🔍 Technical details
  • resolve_ctx_size(model) no longer reads the device when given a model. -FLM models keep the 32768 ceiling, unregistered models get GPU_CTX_SIZE, and registered models get context_for_capacity. Model-less calls still use the device profile.
  • ModelRequirement gains size_gb, max_ctx_size and kv_bytes_per_token. model_fit.largest_context subtracts the weights (size*1.05 + 1) from 90% of the pool Lemonade reports, plus the CPU-backend embedder on unified memory (iGPU, Apple, RAM-only), then rounds the KV room down to an 8192 step within [min_ctx_size, max_ctx_size]. Capacity is read once per server per process. If it can't be read, the model loads at its floor and GAIA logs a warning.
  • Agent.__init__ passes min_context_size=None to LemonadeManager.ensure_ready unless the caller pinned one or GAIA_CTX_SIZE is set. ensure_ready(None) seeds an idle server with DEFAULT_MODEL_NAME at resolve_ctx_size(model=DEFAULT_MODEL_NAME). Before this, ChatAgent's hard-coded 32768 made every cold start seed Gemma at 32K, which also appears in the CI log.
  • _classify_lemonade_response(response, model) and Agent._is_loaded_ctx_too_small compare n_ctx with each model's own window. A GGUF model at 32K on an NPU profile now counts as a wrong load and gets retried.
  • Left on the device profile on purpose: the per-tool-result truncation budget, which stays conservative, and request_budget_seconds. The server's global_timeout is written before Lemonade starts, so it can't know the model. At its 64K-derived 2048 s it covers a 256K prefill at 128 tok/s or faster. Strix Halo measured about 500 tok/s.
  • CLAUDE.md → Default Models still says "pinned per device profile … fixed machine-wide". It needs a follow-up edit. I didn't change it here because that file also holds the assistant's own instructions.

An NPU device setting capped every model at the NPU's 32,768 tokens, so a GGUF
model on an NPU-profile machine ran at half its window. CI's Qwen3.6 TheRock
tasks died this way: the runner's ~/.gaia/config.json said default_device=npu,
written there by a cold `gaia init --profile npu` job that ran under its own
GAIA_HOME, because config.json ignored GAIA_HOME.

- The NPU ceiling now binds -FLM models (and model-less NPU requests) only.
- config.json follows GAIA_HOME, so an isolated run cannot change the device
  every later run on the machine sees.
- A MODELS entry can declare its native max ctx, KV bytes per token and size;
  its window is then the largest 8K step that fits the memory Lemonade reports,
  after the weights, the embedder on unified memory and 10% headroom. Gemma
  does not opt in and stays at 65536.
- Agents no longer push their model's window onto LemonadeManager, which would
  resize whatever model is resident; an idle server is seeded with the default
  model at its own window. ChatAgent drops its hard-coded 32768 floor.
- The overflow classifier and the loaded-ctx probe judge each model against
  its own window.
@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes cli CLI changes tests Test changes performance Performance-critical changes agents labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes (one small, mechanical fix)

The core fix is right. A machine set to default_device: npu was loading every model at 32K, including GPU models that never touch the NPU. Now the NPU limit applies only to NPU models, and a model can opt in to a window sized to the machine's memory. The sizing math, the retry-on-undersized-load logic and the tests are solid.

What to fix before merge:

  • The terminal UI still reads the old settings file. This PR moves Python's config.json under GAIA_HOME. The Go TUI has its own copy of that lookup (documented as matching the Python "exactly"), and it still reads ~/.gaia/config.json. So in any GAIA_HOME run, which is the isolated setup this PR targets, the TUI and Python read different files. They disagree on default_device, the last-chosen model and full_access. For example, gaia config set full_access true would have no effect in the TUI. Add the GAIA_HOME step to the Go lookup in the same PR.

Real-world evidence

N/A: no evidence bundle was produced for this run, and the PR description's test plan is all unchecked. The verdict rests on static review alone. The change that matters (Gemma loading at 65,536 instead of 32,768 on an NPU-profile machine) needs real hardware, and the PR correctly lists the eval_flagship.yml re-run because it changes the context Lemonade loads. Please attach the lemond.log line and the eval comparison once they've run.

🔍 Technical details

🟡 Go TUI config lookup no longer mirrors gaia.config (src/gaia/config.py:42-52 vs tui/internal/ui/preflight/ctxsize.go:106-118)
configPath resolves GAIA_CONFIG_FILE → GAIA_CONFIG_DIR → ~/.gaia, and its comment says it mirrors gaia.config exactly. Python now inserts gaia_home() (i.e. GAIA_HOME) before the ~/.gaia fallback. Three things depend on that path:

  • readDefaultDevice: the TUI's start command picks LEMONADE_CTX_SIZE from it
  • fullaccess.go (ReadFullAccess/WriteFullAccess via writeConfigKeys): TUI writes land in a file Python no longer reads, and the reverse
  • lastmodel.go

The fix is to add a GAIA_HOME step between configDirEnv and the home fallback, with a test beside lemonade_test.go:609. tui/internal/daemon/client.go:346 hard-codes the same path for install detection and is worth aligning too.

🟡 No real-world evidence for a model-load change. The test plan items (NPU-profile gaia llm "hi" → ctx_size=65536 in lemond.log, flagship eval re-run) are unchecked, and nothing is linked. Not blocking on its own, since the eval needs the Strix Halo pool, but it should land before merge.

🟢 GAIA_CONFIG_DIR expansion differs from gaia_home() (src/gaia/config.py:45-47). gaia_home() applies expandvars(expanduser(...)), but the new GAIA_CONFIG_DIR branch only applies expanduser, so GAIA_CONFIG_DIR=$XDG_CONFIG_HOME/gaia resolves differently in the two places.

GAIA_CONFIG_DIR = (
    Path(os.path.expandvars(os.path.expanduser(os.environ["GAIA_CONFIG_DIR"].strip())))
    if os.environ.get("GAIA_CONFIG_DIR", "").strip()
    else gaia_home()
)

🟢 Stale ~/.gaia/config.json wording in CLI help (src/gaia/cli.py:1114, :3302, :6007, :6423). Under GAIA_HOME that is no longer where the file lives. Consider naming GaiaConfig.config_path() in the error at :6423.

🟢 _is_loaded_ctx_too_small can now leak GaiaConfigError (src/gaia/agents/base/agent.py:5983). Narrowing the old bare except is right. But if a health entry has no model_name and self.device is None, resolve_ctx_size falls back to GaiaConfig.load(), and a corrupt config would raise out of an overflow-recovery path. providers/lemonade.py guards the same case explicitly (_loaded_below_profile). Adding GaiaConfigError to the tuple keeps the two consistent.

Strengths

  • Keying the NPU ceiling on the model (runs_on_npu) instead of the device profile is the right fix. The undersized-load retry is now judged per model, so a GGUF model at 32K on an NPU box is correctly treated as a wrong load.
  • model_fit fails loudly when Lemonade reports a GPU without its memory, instead of guessing from system RAM, and the warning when capacity can't be read names what happened and what window was used.
  • The tests pin the real /load body (_load_bodies()), not just that a load was called, and they cover the cold idle-server seeding path.

CLAUDE.md still said the context window was pinned per device profile and fixed machine-wide, which this PR changes: models that declare a native maximum and per-token KV cost get the largest window the GPU memory allows, and the NPU ceiling applies only to NPU models.
auto-merge was automatically disabled October 4, 2026 19:59

Head branch was pushed to by a user without write access

@github-actions github-actions Bot added the devops DevOps/infrastructure changes label Oct 4, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 4, 2026
Merged via the queue into amd:main with commit 6ffc752 Oct 4, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/ctx-scales-with-memory branch October 4, 2026 20:08
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 6, 2026
5 of 10 tasks
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 6, 2026
# GAIA v0.25.0 Release Notes

## Breaking Changes

- **`gaia chat` runs the flagship GAIA agent**, the same agent as the
TUI and Agent UI, instead of the retired ChatAgent. `gaia chat -q "…"`
queries it once. (PR [amd#4520](amd#4520))
- **`gaia talk` transcribes and speaks through Lemonade** — it uses
Lemonade's Whisper and `kokoro-v1`, and stops with the reason if
Lemonade is down. The `[audio]` extra is gone; `pip install
amd-gaia[audio]` only warns. (PR
[amd#4665](amd#4665))
- **The Agent UI runs only the GAIA agent** — the Agent Hub home, agent
picker, and custom-agent export/import are removed from the UI. The CLI
and eval harness can still run other agents. (PR
[amd#4509](amd#4509))
- **The retired nomic embedder is removed** — memory saved with it is
re-embedded on first start. (PR
[amd#4489](amd#4489))
- **Indexed documents are re-indexed once** — the document cache is now
keyed on chunking settings, so the first query after upgrading rebuilds
it. (PR [amd#4624](amd#4624))
- **A skill that asks for more than its tier allows no longer loads** —
the permission ceiling is checked at every load, so a skill already on
disk that exceeds it is refused with the reason. (PR
[amd#4849](amd#4849))

## What's New

- **A larger local model where the GPU holds it** — `gaia init` picks
Qwen3.6-35B-A3B on a 64 GB+ Strix Halo or a 32 GB GPU and keeps
Gemma-4-E4B elsewhere, with each context window sized to available
memory. Qwen3.8 Flash Next is opt-in on 128 GB Strix Halo. (PRs
[amd#4479](amd#4479),
[amd#4670](amd#4670),
[amd#4671](amd#4671),
[amd#4658](amd#4658),
[amd#4655](amd#4655))
- **The Agent UI opens straight to a chat and sets itself up** — a fresh
install runs the same setup steps as the TUI in the window, with
provider, key and model settings, permission modes, and revocable
"always allow" grants. (PR
[amd#4509](amd#4509))
- **A much smaller install** — PyTorch, transformers and accelerate are
gone from the core, `[ui]` and `[talk]` installs; the desktop app's
Python environment drops from ~0.9 GB to ~0.1 GB on Windows. (PRs
[amd#4666](amd#4666),
[amd#4621](amd#4621),
[amd#4665](amd#4665))
- **One Windows installer for the desktop app and the terminal**, with a
GAIA Windows Terminal profile. (PRs
[amd#4720](amd#4720),
[amd#4707](amd#4707))
- **A "no" holds** — a declined action isn't retried through another
tool; the agent asks again with the exact command. The TUI gains
Shift+Tab permission modes. (PRs
[amd#4460](amd#4460),
[amd#4461](amd#4461))
- **Answers are checked against what the tools actually did** — the
agent looks at files you name before answering about them, and a short
plain-English note appears only when work isn't confirmed. (PRs
[amd#4532](amd#4532),
[amd#4501](amd#4501),
[amd#4508](amd#4508))
- **One shell session** — commands share a persistent shell, risky ones
ask instead of being refused, and "full access" is one setting
everywhere. (PR [amd#4408](amd#4408))
- **Memory surfaces what's relevant to each request, with its age**,
keeps what fixed a failure as a lesson for that workspace, and extracts
after the answer instead of before it. (PRs
[amd#4061](amd#4061),
[amd#4066](amd#4066),
[amd#4406](amd#4406))
- **`gaia.log` stays bounded** — it rotates at 10 MB with three backups
(`GAIA_LOG_MAX_MB`, `GAIA_LOG_BACKUPS`). (PRs
[amd#4668](amd#4668),
[amd#4760](amd#4760))
- **Child processes get a trimmed environment** — shell, MCP and skill
children no longer inherit GAIA's internal credentials; `GAIA_NO_DOTENV`
skips loading `.env`. (PRs
[amd#4635](amd#4635),
[amd#4659](amd#4659))
- **Every file tool checks the allowed-folders rule**, and paths inside
an inline shell script are checked one by one. (PRs
[amd#4656](amd#4656),
[amd#4758](amd#4758))

## Bug Fixes

A selection of the user-visible fixes; the full list is in the changelog
below.

- **Local Qwen models no longer loop on repeated tool calls** — they run
with their model card's sampling instead of near-greedy settings. (PR
[amd#4655](amd#4655))
- **Qwen3.6 runs on a Strix Halo with an older AMD driver** — it used to
crash on its first token, so `gaia init` failed; GAIA now turns off the
Vulkan path that crashes on those drivers only, and newer drivers keep
the faster path. (PR [amd#4674](amd#4674))
- **A long PDF no longer hangs or times out while indexing** — big
documents index in the background, and PDFs that only carry
owner-password restrictions now index. (PRs
[amd#4754](amd#4754),
[amd#4679](amd#4679),
[amd#4734](amd#4734))
- **Document answers cite the right document and page**, and every chunk
is embedded whole instead of its first 1,200 characters. (PRs
[amd#4688](amd#4688),
[amd#4723](amd#4723))
- **`gaia init` fails when model verification fails**, shows downloads
live, and no longer hangs while Lemonade hashes a large model. (PRs
[amd#4620](amd#4620),
[amd#4564](amd#4564),
[amd#4673](amd#4673))
- **`gaia init` adds a profile's extras without reinstalling GAIA**,
which failed on Windows while `gaia.exe` was running. (PR
[amd#4672](amd#4672))
- **Every SDK and CLI entry point starts GAIA's own Lemonade**, and
every call goes to the resolved URL with its API key. (PRs
[amd#4657](amd#4657),
[amd#4627](amd#4627))
- **Local chat stays cached across turns** — the system prompt is fixed
and side requests no longer evict the conversation. (PRs
[amd#4698](amd#4698),
[amd#4543](amd#4543))
- **A cloud model selection never preloads a local model**, and cloud
models no longer get llama.cpp-only fields. (PRs
[amd#4757](amd#4757),
[amd#4709](amd#4709))
- **The Agent UI stops claiming "100% local" while chat goes to a cloud
model**, and the chat header names the session's real model. (PRs
[amd#4711](amd#4711),
[amd#4550](amd#4550))
- **Enter can't approve a permission prompt**, and prompts wait 10
minutes before timing out. (PRs
[amd#4700](amd#4700),
[amd#4699](amd#4699))
- **Stopping a run keeps the turn and its steps visible.** (PR
[amd#4743](amd#4743))
- **A file edit keeps the file's line endings** — a one-line edit on
Windows used to rewrite every line ending, so a small change showed up
as the whole file changed. (PR
[amd#4864](amd#4864))
- **A broken agent install is reported as broken, not as missing** — the
error names both package versions and the real import error, and
suggests a reinstall that works. (PR
[amd#4588](amd#4588))
- **A meeting or document summary is never cut off mid-sentence** — a
thinking model used to spend the summary's output budget reasoning, so a
long meeting lost its second half. (PR
[amd#4827](amd#4827))
- **"What can you do?" gets an answer** instead of an attempt to
generate an image of the question. (PR
[amd#4809](amd#4809))
- **Writes and approved edits can't reach credential folders**
(`~/.ssh`, `~/.aws`, `~/.kube` and others), and shell option values and
script arguments get the same path check as plain paths. (PRs
[amd#4848](amd#4848),
[amd#4847](amd#4847))
- **`gaia connectors connect google --grant-agent installed:gaia`
works** — it used to fail with no sign-in link for the shipped agent; it
now asks for read-only Gmail and grants exactly that. (PR
[amd#4859](amd#4859))
- **A "no" to creating a folder also covers writing into it** — GAIA no
longer asks again to create the same folder a different way. (PR
[amd#4857](amd#4857))
- **`gaia skill import` runs the same checks as a hub install** — https
only, the audit, the permission ceiling, and an explicit opt-in for
skills that ship code. (PR
[amd#4849](amd#4849))
- **Memory off and private chats apply to scheduled and background runs
too.** (PRs [amd#4842](amd#4842),
[amd#4821](amd#4821))
- **Memory stops false apologies and reusing deleted values**, saves
"remember this" requests, and skips loading the embedder when memory is
off. (PRs [amd#4708](amd#4708),
[amd#4756](amd#4756))
- **A reply cut off by the token limit is continued** instead of ending
mid-sentence, and a tool call cut off at the output cap is retried
shorter. (PRs [amd#4054](amd#4054),
[amd#4556](amd#4556))
- **The TUI remembers the chosen model** across restarts and
agent-process restarts. (PRs
[amd#4497](amd#4497),
[amd#4710](amd#4710))
- **`gaia uninstall --purge` removes installer binaries, PATH edits and
daemon state.** (PR [amd#4413](amd#4413))

## Contributors

Thanks to the community members who contributed to this release:

- [@itomek](https://github.com/itomek) — the flagship's browser and tool
picker, one shell session, memory extraction off the answer path, stale
tool-result eviction, the TUI's sourced Fireworks rankings, and
`--purge` cleanup (PRs [amd#4407](amd#4407),
[amd#4408](amd#4408),
[amd#4406](amd#4406),
[amd#4465](amd#4465),
[amd#4414](amd#4414),
[amd#4413](amd#4413))
- [@mikemikimike](https://github.com/mikemikimike) — chained shell
command timeouts, bundled skills in frozen builds, and sidecar cleanup
reporting (PRs [amd#4463](amd#4463),
[amd#4467](amd#4467),
[amd#4419](amd#4419))
- [@Hashim1999164](https://github.com/Hashim1999164) — honoring
`GAIA_HOME` for cache, chat and index paths (PR
[amd#4381](amd#4381))
- [@krtadev](https://github.com/krtadev) — `~` expansion in file and
document tool paths (PR [amd#4576](amd#4576))
- [@aksh8b](https://github.com/aksh8b) — telling a broken agent install
apart from a missing one, with a reinstall hint that works (PR
[amd#4588](amd#4588))
- [@Dev-next-gen](https://github.com/Dev-next-gen) — numeric prerelease
ordering in the hub (PR [amd#4517](amd#4517))
- [@vianmangal](https://github.com/vianmangal) — recording denied tool
calls as unsuccessful in memory (PR
[amd#4412](amd#4412))
- [@GaetanVDB07](https://github.com/GaetanVDB07) — links to upstream
credential setup guides for connectors (PR
[amd#4669](amd#4669))
- [@rradjabi](https://github.com/rradjabi) — moving self-hosted CI jobs
to the xsj-dispatch runner pool (PR
[amd#4534](amd#4534))




## Also in this PR

- **Hub floors raised to core 0.25.0** — the chat agent imports the
allowed-folders check that only 0.25.0 ships (amd#4656), so
`gaia-agent-chat` goes to 0.2.0 with `amd-gaia>=0.25.0`, and the
flagship requires `amd-gaia>=0.25.0` and `gaia-agent-chat>=0.2.0`.
- **Two follow-ups held back until that floor could rise** —
`~/.gaia/logs/gaia-agent.log` now rotates like `gaia.log` (amd#4668), and
the chat agent's Python runners and Windows notification start their
children without GAIA's internal credentials (amd#4659).

The full changelog (300 commits) is in `docs/releases/v0.25.0.mdx`.

## Test plan

- [x] `util/validate_release_notes.py docs/releases/v0.25.0.mdx --tag
v0.25.0` passes; narrative is 590 words (cap 600)
- [x] `util/check_component_core_api.py --release-version 0.25.0` passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
hub/agents/chat/python/tests/test_chat_dependency_floor.py
hub/agents/chat/python/tests/test_dependency_floor.py
hub/agents/gaia/python/tests/test_gen_binaries_lock.py` (72 passed)
- [x] `pytest hub/agents/gaia/python/tests/test_stdio.py` (91 passed,
incl. the new rotation test); `pytest
tests/unit/test_execute_python_file_cwd.py
tests/unit/test_run_python_tool.py` (42 passed)
- [ ] `mintlify validate` (docs CI job) — timed out locally, relying on
CI
- [x] Full flagship eval on main 9ce6598
(https://github.com/amd/gaia/actions/runs/37436249503): 181/308
scenarios pass vs 100/183 for the same categories in the baseline, 39
FAIL→PASS, 13 PASS→FAIL (two fixed in amd#4878, held until after rc1);
retrieval lane still finishing at merge time
- [ ] CI green

## Release checklist

- [ ] Publish `gaia-agent-chat` 0.2.0 only after core 0.25.0 is on PyPI
— it fails at import on an older core
- [ ] Build Installers on the merged SHA (pre-tag verification) before
pushing `v0.25.0`
- [ ] terminal-hub 0.25.0 published before the flagship npm release
consumes `binaries.lock.json`

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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 devops DevOps/infrastructure changes documentation Documentation 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