Repository navigation
fix(transformers): enforce the launch context_length on Gemma 3 and MiniCPM-V 4.6 - #5734
Merged
Merged
Conversation
…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
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.
Follow-up to #5729, which enforced the launch
context_lengthon four Transformers multimodal direct-chat adapters.Change
Gemma3ChatModel.build_streaming_iterandMiniCPMV46Model.build_streaming_iternow call_cap_context_max_new_tokenswith the preparedinput_idswidth, 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 launchcontext_length, nothing changes; otherwisemax_new_tokensis capped to the remaining budget, and a prompt that leaves no room raisesContextLengthExceeded. 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.pynow 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(basecb925dc, 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.cb925dc,test_multimodal_context_length.pygives 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