Skip to content

fix(transformers): enforce the launch context_length on Gemma 3 and MiniCPM-V 4.6 - #5734

Merged
qinxuye merged 1 commit into
xorbitsai:mainfrom
Jackmeson1:fix/mm-context-budget-2
Oct 18, 2026
Merged

qinxuye merged 1 commit into
xorbitsai:mainfrom
Jackmeson1:fix/mm-context-budget-2

Conversation

@Jackmeson1

Copy link
Copy Markdown
Contributor

Follow-up to #5729, which enforced the launch context_length on four Transformers multimodal direct-chat adapters.

Change

Gemma3ChatModel.build_streaming_iter and MiniCPMV46Model.build_streaming_iter now call _cap_context_max_new_tokens with the prepared input_ids width, after the generation kwargs are final and before the generation thread starts, as the other four adapters do. This covers streaming and non-streaming direct chat. With no launch context_length, nothing changes; otherwise max_new_tokens is capped to the remaining budget, and a prompt that leaves no room raises ContextLengthExceeded. The existing REST handling returns HTTP 400 for non-streaming chat, Responses and Anthropic requests; errors during streaming are sent over SSE. #5727's greedy decoding at temperature 0 is unchanged.

Tests

xinference/model/llm/tests/test_multimodal_context_length.py now covers Gemma 3 and MiniCPM-V 4.6 with the same text-only budget cases in both streaming modes, plus a one-token-remaining image case in each mode. Prepared inputs and generation are mocked for these adapters.

I ran these outside the sandbox on 6498bcd (base cb925dc, Linux under WSL, CPU torch, transformers 5.17.0):

  • PYTHONPATH=. python -m pytest xinference/model/llm/tests/test_multimodal_context_length.py xinference/model/llm/tests/test_qwen2_vl.py xinference/model/llm/tests/test_minicpmv47.py -q --timeout=300: 500 passed on Python 3.12.15 and on Python 3.10.12.
  • With the extended test file and production files from cb925dc, test_multimodal_context_length.py gives 28 failed and 396 passed (only the new Gemma 3 and MiniCPM-V 4.6 cap/rejection cases fail; the controls pass). With the fix, all 424 pass.
  • PYTHONPATH=. python -m pytest xinference/model/llm/tests/test_transformers_temperature.py -q --timeout=300 (from fix(transformers): use greedy decoding at temperature 0 for Gemma 3, Gemma 4, GLM-4V and MiniCPM-V 4.6 #5727): 40 passed.
  • uvx pre-commit run --files xinference/model/llm/tests/test_multimodal_context_length.py xinference/model/llm/transformers/multimodal/gemma3.py xinference/model/llm/transformers/multimodal/minicpmv46.py: black, ruff, isort, mypy and codespell pass.

These tests do not load model weights or run GPU inference.

AI-assisted: I used Claude Code to help write this change and its tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_019TTGAv6fe859ebbCLLfLHP

…iniCPM-V 4.6

xorbitsai#5729 added the context-budget helper for multimodal direct chat but left
Gemma 3 and MiniCPM-V 4.6 out. Call the helper in both before the generation
thread starts: max_new_tokens is capped to the remaining budget, and a
prompt with no room raises ContextLengthExceeded. Existing REST handling
returns HTTP 400 for non-streaming chat, Responses and Anthropic requests;
errors during streaming are sent over SSE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TTGAv6fe859ebbCLLfLHP
@XprobeBot XprobeBot added bug Something isn't working gpu labels Oct 18, 2026
@XprobeBot XprobeBot added this to the v4.x milestone Oct 18, 2026

@qinxuye qinxuye left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gpu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants