-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(vlm): default max_tokens=32768 exceeds gpt-4o-mini completion cap → silent 0-memory extraction (#2751) #2755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r266-tech
wants to merge
3
commits into
volcengine:main
Choose a base branch
from
r266-tech:fix/vlm-default-max-tokens-2751
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
7d35b7b
fix(vlm): default max_tokens fallback exceeds gpt-4o-mini completion …
r266-tech 5beabc5
test(vlm): regression for default max_tokens fallback within model ca…
r266-tech 3fc8380
fix(vlm): keep reasoning-model unset max_tokens at prior 32768 default
r266-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. | ||
| # SPDX-License-Identifier: AGPL-3.0 | ||
| """Regression tests for the OpenAI VLM default ``max_tokens`` fallback (issue #2751). | ||
|
|
||
| When ``max_tokens`` is not configured, the OpenAI VLM backend falls back to a default | ||
| that must not exceed the completion-token cap of the backend's own default model | ||
| (``gpt-4o-mini`` / ``gpt-4o``, capped at 16384 completion tokens). The previous | ||
| fallback of 32768 produced an HTTP 400 ("max_tokens is too large ... supports at most | ||
| 16384 completion tokens") that the memory-extraction path swallowed, silently yielding | ||
| 0 extracted memories for default-configured deployments. | ||
| """ | ||
|
|
||
| from openviking.models.vlm.backends.openai_vlm import ( | ||
| _DEFAULT_MAX_TOKENS, | ||
| _DEFAULT_REASONING_MAX_TOKENS, | ||
| OpenAIVLM, | ||
| ) | ||
|
|
||
| # gpt-4o / gpt-4o-mini (the backend default model) cap completion at 16384 tokens. | ||
| _GPT_4O_COMPLETION_CAP = 16384 | ||
|
|
||
|
|
||
| def _make_vlm(**overrides): | ||
| config = { | ||
| "api_key": "sk-test", | ||
| "api_base": "https://api.openai.com/v1", | ||
| } | ||
| config.update(overrides) | ||
| return OpenAIVLM(config) | ||
|
|
||
|
|
||
| class TestDefaultMaxTokensFallback: | ||
| """Unset ``max_tokens`` must fall back to a value the default model accepts.""" | ||
|
|
||
| def test_default_fallback_within_default_model_cap(self): | ||
| assert _DEFAULT_MAX_TOKENS <= _GPT_4O_COMPLETION_CAP | ||
|
|
||
| def test_text_kwargs_default_model_unset_max_tokens(self): | ||
| # No model -> backend default gpt-4o-mini; no max_tokens -> fallback default. | ||
| kwargs = _make_vlm()._build_text_kwargs(prompt="hi") | ||
| assert kwargs["model"] == "gpt-4o-mini" | ||
| assert kwargs["max_tokens"] == _DEFAULT_MAX_TOKENS | ||
| assert kwargs["max_tokens"] <= _GPT_4O_COMPLETION_CAP | ||
|
|
||
| def test_vision_kwargs_default_model_unset_max_tokens(self): | ||
| kwargs = _make_vlm()._build_vision_kwargs(prompt="describe this") | ||
| assert kwargs["model"] == "gpt-4o-mini" | ||
| assert kwargs["max_tokens"] == _DEFAULT_MAX_TOKENS | ||
| assert kwargs["max_tokens"] <= _GPT_4O_COMPLETION_CAP | ||
|
|
||
| def test_explicit_max_tokens_is_respected(self): | ||
| # An explicitly configured max_tokens must override the fallback unchanged. | ||
| vlm = _make_vlm(max_tokens=512) | ||
| assert vlm._build_text_kwargs(prompt="hi")["max_tokens"] == 512 | ||
| assert vlm._build_vision_kwargs(prompt="x")["max_tokens"] == 512 | ||
|
|
||
| def test_explicit_zero_max_tokens_not_replaced_by_default(self): | ||
| # The fallback fires only when max_tokens is unset (None); an explicit value | ||
| # is passed through unchanged, so the default never silently overrides config. | ||
| vlm = _make_vlm(max_tokens=0) | ||
| assert vlm._build_text_kwargs(prompt="hi")["max_tokens"] == 0 | ||
| assert vlm._build_vision_kwargs(prompt="x")["max_tokens"] == 0 | ||
|
|
||
|
|
||
| class TestReasoningModelDefaultUnchanged: | ||
| """Reasoning models keep their prior 32768 unset default (not lowered by #2751).""" | ||
|
|
||
| def test_reasoning_unset_keeps_prior_default(self): | ||
| # gpt-5 is a reasoning model: unset max_tokens -> prior 32768 via | ||
| # max_completion_tokens, NOT the lowered gpt-4o-family cap. Reasoning models | ||
| # advertise larger completion limits and spend hidden reasoning tokens from | ||
| # this budget, so the #2751 16384 cap must not apply to them. | ||
| for builder in ("_build_text_kwargs", "_build_vision_kwargs"): | ||
| kwargs = getattr(_make_vlm(model="gpt-5"), builder)(prompt="hi") | ||
| assert "max_tokens" not in kwargs | ||
| assert kwargs["max_completion_tokens"] == _DEFAULT_REASONING_MAX_TOKENS | ||
| assert _DEFAULT_REASONING_MAX_TOKENS > _DEFAULT_MAX_TOKENS | ||
|
|
||
| def test_reasoning_explicit_max_tokens_respected(self): | ||
| # An explicit budget on a reasoning model is still honored unchanged. | ||
| vlm = _make_vlm(model="o3", max_tokens=4096) | ||
| assert vlm._build_text_kwargs(prompt="hi")["max_completion_tokens"] == 4096 | ||
| assert vlm._build_vision_kwargs(prompt="x")["max_completion_tokens"] == 4096 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One concern: this now gives reasoning models a default
max_completion_tokenswhenmax_tokensis unset. Existing behavior intentionally omitted both token fields for reasoning models withoutmax_tokens(seetest_reasoning_model_without_max_tokens_omits_both), and this PR currently breaks that test. Could we keep the16384fallback only for non-reasoning models, and only setmax_completion_tokensfor reasoning models whenmax_tokensis explicitly configured?