Skip to content

fix(config): backend-gate the top_k=40 sampler default (#6632) - #10285

Merged
mudler merged 1 commit into
masterfrom
fix/6632-topk-default-backend-gated
Jun 13, 2026
Merged

fix(config): backend-gate the top_k=40 sampler default (#6632)#10285
mudler merged 1 commit into
masterfrom
fix/6632-topk-default-backend-gated

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Closes #6632

Problem

SetDefaults injected top_k = 40 (the llama.cpp default) into every model config regardless of backend. When a client omits top_k, that 40 was shipped to backends whose intended default differs - notably mlx, whose native default is top_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:

  • New UsesLlamaSamplerDefaults(backend) helper (reuses NormalizeBackendName): empty/unknown backend -> true (keeps the GGUF auto-detect path on the llama.cpp default), explicit deny-set {mlx, mlx-vlm, mlx-distributed} -> false.
  • SetDefaults only injects top_k = 40 when that helper returns true; mlx-family leaves TopK nil.
  • gRPCPredictOpts made nil-safe so a nil TopK goes to the wire as 0 - exactly the disabled value mlx wants.

Scope notes (maintainer review)

  • Only TopK is gated (the confirmed bug). TopP/Temperature/MinP left global to avoid new nil-deref surface and unvalidated mlx behavior changes - revisitable.
  • vllm/sglang/transformers still receive 40 (the issue only confirmed mlx); excluding them is a separate call.

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; scoped golangci-lint --new-from-merge-base clean.

Assisted-by: claude:claude-opus-4-8 [Claude Code]

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
mudler merged commit a906438 into master Jun 13, 2026
59 checks passed
@mudler
mudler deleted the fix/6632-topk-default-backend-gated branch June 13, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Certain model defaults globally align to llama.cpp backend

2 participants