Repository navigation
fix(transformers): use greedy decoding at temperature 0 for Gemma 3, Gemma 4, GLM-4V and MiniCPM-V 4.6 - #5727
Merged
qinxuye merged 1 commit intoOct 18, 2026
Conversation
…Gemma 4, GLM-4V and MiniCPM-V 4.6
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.
What happens
#5708 made the Qwen2-VL adapter decode greedily at
temperature: 0. Four other direct-chat Transformers adapters still pass the request's temperature straight togenerate(): Gemma 3 (multimodal/gemma3.py), Gemma 4 (gemma4.py), GLM-4V (multimodal/glm4v.py, which also forcesdo_sample=True) and MiniCPM-V 4.6 (multimodal/minicpmv46.py). The generation configs of their built-in checkpoints all set"do_sample": true(google/gemma-3-*-it,google/gemma-4-*-it,zai-org/glm-4v-9b,openbmb/MiniCPM-V-4.6). With sampling on, transformers 5.17 rejects zero:The error is raised in the generation thread, so the request never gets it:
temperature: 0one4b24a9equeue.Emptycontent: ""build_generate_kwargs)I drove each adapter's
build_direct_chat_result()on CPU with a stub model whosegenerate()applies transformers' own temperature check, as a sampling-enabled checkpoint does. Positive temperatures answer on all five.Change
do_sample=False, no temperature), and any positive temperature samples with its value. An omitted temperature keeps its default (1 for Gemma, 0.7 for GLM-4V).temperature,top_pandtop_k) moves from its override intoMiniCPMV46Model.build_generate_kwargs, which 4.7 inherits. 4.6 now decodes greedily at 0, and 4.7's kwargs don't change.1e-5as greedy. The adapters' handling of other generation errors is not changed either.Tests
New
xinference/model/llm/tests/test_transformers_temperature.pyrunsbuild_direct_chat_result()for the five adapters at temperatures 0,1e-6, 0.7 and omitted, streaming and not (40 cases), with the stub model above. It checks the answer and the kwargs passed togenerate(). With the five source files restored frome4b24a9e, the 8 temperature-0 cases for Gemma 3, Gemma 4, GLM-4V and MiniCPM-V 4.6 fail; with this change all 40 pass. The existing MiniCPM-V 4.7 tests intest_minicpmv47.pypass unchanged.I ran these on Linux (Python 3.12, CPU torch 2.14.1, transformers 5.17.0):
pytest xinference/model/llm/tests xinference/model/llm/transformers/tests, withouttest_llm_model.pyandtest_tensorizer.pyas in CI: 972 passed, 50 skipped, 1 failed. The failure istest_llm_family.py::test_query_engine_general, which expects the llama.cpp engine. It isn't installed here, and the test fails the same way one4b24a9e.pre-commit run --fileson the changed files: all hooks pass.I did not run a real model.