Repository navigation
fix(claude): send the configured temperature in the request payload - #1796
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
Claude_Wrapper.__init__ declares `temperature: float = 0` and stores it
as self.temperature, but generate_inner never read it back:
self.temperature appears exactly once in the file, at the assignment.
Because temperature is a named __init__ parameter it never lands in
**kwargs either, so it could not reach the payload by that route.
Every Claude entry in vlmeval/config.py passes temperature=0, and the
Anthropic Messages API defaults to 1.0, so the whole benchmark ran
sampled instead of greedy and identical re-runs produced different
scores. Four sibling wrappers in this package already forward it
(gpt.py, gcp_vertex.py, bedrock.py, litellm_api.py); adopt gpt.py's
`kwargs.pop('temperature', self.temperature)` idiom so a per-call value
still wins. max_tokens gets the same treatment for symmetry -- its
effective behaviour is unchanged, since a kwargs entry already shadowed
the dict literal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defect
temperatureis accepted and stored by__init__(claude.py:40,:51) and then never used.grep -c 'self.temperature' vlmeval/api/claude.pyreturns 1 — the assignment. Becausetemperatureis a named__init__parameter it never falls into**kwargs, so it cannot reachBaseAPI.default_kwargsand cannot arrive throughgenerate_inner(**kwargs)either. There is no route by which the configured value reaches the request.Why this is a defect and not a convention
vlmeval/config.pysetstemperature=0for every Claude entry —Claude3V_Opus(config.py:548),Claude3V_Sonnet,Claude3-5V_Sonnet,Claude3-5V_Sonnet_20241022,Claude4_Sonnet, … The repo asks for greedy decoding and does not get it.gpt.pyis the house idiom:gcp_vertex.py:188,:201(which talks to the same Anthropic Messages API via Vertex),bedrock.py:138,:146andlitellm_api.py:120.max_tokens, declared on the adjacent line of the same__init__, is read back into the payload. Onlytemperatureis dropped.Reachability
The Anthropic Messages API default temperature is 1.0, so every Claude evaluation in this repo has been running sampled rather than greedy: re-running the same benchmark on the same model produces different scores, and the
temperature=0in the repo's own config is silently a no-op. Both backends (allesandofficial) are affected, since both go through this one payload.Fix
Adopt
gpt.py's idiom. A per-calltemperaturestill wins over the configured one, which matters becauseBaseAPI.generateforwardsdefault_kwargsand a few dataset evaluators vary temperature across retries.max_tokensgets the samekwargs.poptreatment for symmetry. That is not a behaviour change: amax_tokensentry in**kwargsalready shadowed the dict literal (a later**kwargskey overrides an earlier literal key), so the effective value is the same either way — the test suite pins both orderings.Tests
tests/test_claude_temperature.py— 10 cases, offline.requests.requestis monkeypatched on the module so the realgenerate_innerruns and the actual serialised payload is captured; the wrapper is built withobject.__new__so no key or env var is needed.At
4d0dc80, 5 cases fail by name:With this change:
10 passed, exit 0.The 5 that pass at base are the guards, and one of them is worth calling out:
test_per_call_temperature_overrides_the_configured_onealready passed, because an explicittemperature=kwarg did reach the payload via**kwargs. Only the configured default was being dropped, and the test pins that the kwargs route keeps working. The others pinmodel,max_tokens(configured and per-call),messages,system, an arbitrary passthrough kwarg (top_p), and the response parsing.Whole-suite check in the same selection shape, before and after: identical,
81 failed, 82 passed, 2 skipped, 21 errorseither way (local-environment failures — 13 test files need Python 3.10+ forstr | Noneinvlmeval/smp/dataset_alias.py, the rest needvlmevalinstalled).flake8 --max-line-length=120 --ignore=W503on both touched files: exit 0.git diff --check: exit 0. I have not run the GPU or mock-API CI jobs and have not made a live Anthropic API call.