Repository navigation
fix(serve): tool requests sample without the preset's presence penalty; tools rendered as trained - #118
Merged
Conversation
…resence penalty The Qwen non-thinking preset's presence penalty of 1.5 subtracts from every token the answer already used, and a second tool call repeats the first call's markup and function name, so the model dropped calls it would otherwise make (issue #114: BFCL parallel_multiple 59.5 against 67.0 with --presence-penalty 0). A request with tools and a tool_choice other than none now resolves presence_penalty to 0 unless the request or --presence-penalty names a value; the same rule covers the post-thinking sampler.
… strict The rendered definition follows the member order the Qwen templates were trained on and leaves out strict, which only selects the server's output contract; the contract still reads it from the tool JSON.
…der MSVC MSVC declares no scalar _cvtsh_ss and no M_PI without _USE_MATH_DEFINES; the streamed rows use the vector F16C form the GGUF expert kernel already uses, and the test takes pi from <numbers>. Master's MSVC host-compile checks have failed on these two lines since 86dd954.
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.
Fixes the actionable part of #114: on Qwen3.8-Flash-Next (and every Qwen preset) a request that offers tools often got one tool call where two or three were needed.
Cause. The non-thinking preset's
presence_penalty 1.5(the model card's recommendation) subtracts 1.5 from the logit of every token the answer already used. A second tool call repeats<tool_call>,<function=, the function name and<parameter=, so near-greedy sampling turned the second call into the end of the turn or prose. The reporter measured BFCLparallel_multiple59.5 with the preset and 67.0 with--presence-penalty 0(llama.cpp, which applies no penalty, 70.5).Changes
src/serve/translate.cpp: a request withtoolsand atool_choiceother thannoneresolvespresence_penaltyto0unless the request or--presence-penaltynames a value; the post-thinking sampler follows the same rule. All three protocols go through this point. No tools, ortool_choice: none, keeps the preset.src/serve/translate.cpp,src/models/qwen3_5/frontend/chat_template.cpp: a tool definition is rendered as{"type":"function","function":{"name","description","parameters"}}in that order, the order the Qwen templates were trained on;strictstays in the tool JSON for the output contract (--structured-outputgrammar) and the frontend strips it from what the template renders. The reporter found NInfer renderingname, parameters, strict, description; the effect of that on the score was not isolated.test_openai_schemacovers the rendered member order and the penalty rule (tools → 0, no tools → preset,tool_choice: none→ preset, request value and--presence-penaltykept, post-thinking preset and request value);test_frontendrenders a strict tool through the Qwen3.6 and Qwen3.8 templates and checks the order, the absence ofstrictand that the contract still seesstrict.Verification.
ninfer_qwen3_5_frontend_testbuilt and run on the Mac through a scratch host-only CMake (passes; fails against the old renderer).translate.cppandtest_openai_schema.cpppassclang -fsyntax-only; the serve tests link the engine and were not run here. CTest, CUDA builds and CI were not run locally. BFCL was not re-run: the expected effect is the reporter's--presence-penalty 0result (59.5 → 67.0 onparallel_multiple,irrelevanceunchanged); the remaining gap to llama.cpp (~3.5 points, two cases answering in prose) is not addressed here.CI. The MSVC host-compile checks were red on master before this PR (since 86dd954:
_cvtsh_ssinsrc/ops/sparse_moe/streamed_cpu_avx2.cppandM_PIintests/ops/test_gguf_expert_cpu.cpp). The third commit fixes both with the vector F16C form the GGUF expert kernel already uses andstd::numbers::pi; both files pass a clang x86-64 cross syntax check with AVX2/FMA/F16C locally, MSVC itself runs only in CI.