fix(config): backend-gate the top_k=40 sampler default (#6632) - #10285
Merged
Conversation
SetDefaults injected top_k=40 (llama.cpp's sampling default) for every model config regardless of backend. That value is wrong for backends whose native default differs: mlx_lm's intended default is top_k=0 (disabled) and mlx does not remap 0->40, so a client that omits top_k silently got 40 shipped to mlx, changing sampling. The mlx backend's own getattr(request,'TopK',0) fallback is dead because proto3 int32 is always present. Gate the injection on backend family via UsesLlamaSamplerDefaults: keep top_k=40 for the llama.cpp family and for the empty/auto backend (the GGUF auto-detect path resolves to llama.cpp, so existing behavior is preserved), but leave TopK nil for the known non-llama backends (mlx, mlx-vlm, mlx-distributed). gRPCPredictOpts now sends 0 when TopK is nil, which is the value mlx actually wants. Only TopK is gated - the confirmed bug. The sibling sampler defaults (top_p, temperature, min_p) are left global to avoid widening scope and introducing nil-deref risk; revisit per-backend if needed. Assisted-by: claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
mudler
approved these changes
Jun 13, 2026
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.
Closes #6632
Problem
SetDefaultsinjectedtop_k = 40(the llama.cpp default) into every model config regardless of backend. When a client omitstop_k, that 40 was shipped to backends whose intended default differs - notably mlx, whose native default istop_k = 0(disabled) and which does not map 0 -> 40. Result: silently altered sampling on mlx-family backends (confirmed by the reporter in a debugger).Fix
Backend-gated default, preserving llama.cpp behavior:
UsesLlamaSamplerDefaults(backend)helper (reusesNormalizeBackendName): empty/unknown backend -> true (keeps the GGUF auto-detect path on the llama.cpp default), explicit deny-set{mlx, mlx-vlm, mlx-distributed}-> false.SetDefaultsonly injectstop_k = 40when that helper returns true; mlx-family leavesTopKnil.gRPCPredictOptsmade nil-safe so a nilTopKgoes to the wire as0- exactly the disabled value mlx wants.Scope notes (maintainer review)
TopKis gated (the confirmed bug).TopP/Temperature/MinPleft global to avoid new nil-deref surface and unvalidated mlx behavior changes - revisitable.Test plan
core/config/model_config_test.go:llama-cpp& empty backend -> 40 (regression guard);mlx-> nil (red on old code, green after).go test ./core/config/... ./core/backend/...green; scopedgolangci-lint --new-from-merge-baseclean.Assisted-by: claude:claude-opus-4-8 [Claude Code]