Skip to content

fix(llm): stop sending repetition penalties to cloud models - #4068

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:fix/no-penalties-for-cloud-models
Sep 24, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:fix/no-penalties-for-cloud-models

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

GAIA sent its local anti-loop penalties to cloud models too, and they made cloud reasoning models think in circles. On the same 80-line prompt (fireworks.deepseek-v4p1-flash, 2 runs each):

Setting Time Answer
GAIA today (temp 0.1 + frequency 0.3 + presence 0.1) 105–128 s 0 and 2 of 80 lines; ran out of tokens thinking
temperature 0.1 only 20 s 80/80
provider defaults 20–37 s 80/80

On the TheRock coding benchmark this was the main reason GAIA was about 5× slower than Claude Code: half of its 2,916 s went to 15 runaway thinking bursts. Cloud models now get no penalties unless the caller sets them. Local models behave exactly as before, still with all four defaults. Temperature is unchanged.

Test plan

  • New tests check the actual request body on both the streaming and non-streaming paths. A cloud model gets no penalty fields, a local model gets all four, and a caller's explicit value on a cloud model is still sent. The cloud tests fail on main.
  • Lemonade/LLM provider unit tests pass. tests/test_lemonade_client.py shows the same 7 failures and 15 errors with and without this change; they need a live Lemonade server.
  • black and isort are clean on the changed files.
  • gaia eval agent --category tool_selection compared against the committed baseline

Cloud reasoning models ran away in their thinking under GAIA's local
anti-loop penalties: on fireworks.deepseek-v4p1-flash an 80-line list took
105-128 s and hit the length limit with 0-2 lines, versus 20 s and 80/80
lines without the penalties. The frequency/presence/repeat defaults now
apply only to local models; a caller's explicit values still go through.
@github-actions github-actions Bot added llm LLM backend changes tests Test changes performance Performance-critical changes labels Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions — merge-ready; the two notes below are non-blocking.

GAIA was applying its local anti-loop sampling penalties to cloud models as well, which made cloud reasoning models spiral in their thinking. This PR limits those defaults to local models only, leaves local behaviour byte-identical, and still honours a penalty a caller passes explicitly. The gate lives at the single place the defaults were injected, so there's no second path left to fix.

Two things worth a follow-up, neither blocking:

  • One of the pre-existing repetition tests wasn't updated alongside its sibling, so it now silently exercises the cloud branch instead of the local one. It still passes, but it no longer checks the behaviour its name promises — a one-line fix.
  • The fix only recognises cloud models from the two providers GAIA knows by name; any other cloud provider is only recognised after the model catalog has been fetched. That's an existing limitation of the shared helper rather than something this PR introduces, but it does bound how far the fix reaches.

The unchecked eval item in the test plan looks safe to close out: local models receive exactly the same four defaults as before, and the eval baseline runs locally, so there's no path for it to move.

Real-world evidence

N/A — no evidence bundle was produced for this run, so my verdict rests on static review plus the tests in the diff. The PR description does carry author-run measurements on a real cloud model (105–128 s with 0–2 of 80 lines, versus ~20 s and 80/80 without the penalties); I'm relaying those as reported by the author, not as something reproduced here. The new unit tests do assert on the actual serialized request body for both the streaming and non-streaming paths, which is stronger than the usual "we called the method" mock and directly covers the contract that broke.

🔍 Technical details

Issues Found

🟢 Sibling test not updated — now exercises the cloud branch (tests/unit/test_llamacpp_backend.py:756)

test_chat_sets_repeat_penalty_defaults gained provider._backend.cloud_model_provider.return_value = None, but test_chat_allows_override_of_repeat_penalty did not. With a bare MagicMock(spec=LemonadeClient), cloud_model_provider() returns a truthy Mock, so not ... is False and the defaults block at providers/lemonade.py:384 is skipped entirely. The assertion call_kwargs["repeat_penalty"] == 1.5 still holds because the caller passed it explicitly — the test passes for the wrong reason and no longer verifies that an explicit value overrides a default.

    def test_chat_allows_override_of_repeat_penalty(self):
        """Caller-specified repeat_penalty overrides the default."""
        provider = LemonadeProvider.__new__(LemonadeProvider)
        provider._backend = MagicMock(spec=LemonadeClient)
        provider._backend.cloud_model_provider.return_value = None
        provider._model = "Gemma-4-E4B-it-GGUF"
        provider._system_prompt = None

🟢 Detection is name-based for unknown providers (src/gaia/llm/providers/lemonade.py:384)

LemonadeClient.cloud_model_provider (lemonade_client.py:2706) resolves a provider without metadata only for {"fireworks", "amd"}; anything else needs a recipe == "cloud" entry in self._model_metadata, which is populated solely by the catalog fetch at lemonade_client.py:2703. On a client instance that hasn't fetched the catalog, a cloud model from some other provider still gets frequency_penalty / presence_penalty. repeat_penalty / repeat_last_n are covered by the existing pop at lemonade_client.py:1982, which shares the same gate and the same gap. Pre-existing and consistent — flagging only so the blast radius of the fix is on record, not as something to change here.

Strengths

  • Fixed at the single injection point. providers/lemonade.py is the only place in src/ or hub/ that sets these four kwargs (the VS Code extension passes through caller-supplied values and is unaffected), so there's no second path to keep in sync.
  • The tests assert the wire body, not the call. _sent_body drives a real LemonadeProvider.chat through httpx.MockTransport for streaming and responses for non-streaming, then parses the serialized JSON. That catches the extra_body merge on the streaming path — a mock asserting on chat_completions kwargs would not have. This matches CLAUDE.md's "mocks prove we called it, not that the call is valid".
  • setdefault semantics preserved for the cloud branch, and test_cloud_model_request_keeps_explicit_caller_penalty pins it: an explicit frequency_penalty=0.5 still reaches a cloud model.
  • Comment replaced, not deleted. The 16-line explanatory block became three lines stating the invariant — in line with CLAUDE.md's "short or skip" rule, while keeping the non-obvious extra_body detail.
  • Single logical commit, conventional-commits title, body leads with the user-visible symptom and the measured numbers.

Ovtcharov added 2 commits September 21, 2026 12:53
…odel

The repeat-penalty override test was passing for the wrong reason: its bare
mock backend made every model look like a cloud model, so the defaults block
never ran and the test asserted an explicit value against nothing. It now
pins a local model and checks a sibling default came through, so the test
fails if the override ever stops overriding.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Refreshed this branch against current main so it can merge again — the branch had fallen far enough behind that GitHub could no longer compute a merge.

The update was a clean merge: nothing was resolved by hand, and no commit on this branch was rewritten. CI now runs against an up-to-date base.

# Conflicts:
#	tests/unit/test_lemonade_cloud_models.py
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 24, 2026
Merged via the queue into amd:main with commit 9e149c6 Sep 24, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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