Local models: set the model server's sampling per model (greedy decoding made Qwen loop) #37

Merged
dario merged 1 commit from dario/mlx-sampling into main 2026-11-20 13:04:47 +01:00 AGit
Owner

mlx_lm.server samples greedily unless told otherwise. Its defaults are --temp 0.0, --top-p 1.0 and top-k off, and the oc-mlx profile set nothing else. With greedy decoding, once a model starts repeating a step it tends to keep repeating it.

Changes

  • Config: a provider model takes sampling (temperature, top_p, top_k). factory config check validates the ranges. The factory doesn't pass these values to the harness.
  • just mlx-serve:
    • passes sampling to mlx_lm.server as its defaults (--temp, --top-p, --top-k), so every request gets them;
    • warns when a model has no sampling;
    • reads the model's model_id. It used to read modelID, which isn't a config key.
  • factory.example.json and the factory-dev kit: Qwen's recommended values for Qwen3-Coder: temperature 0.7, top-p 0.8, top-k 20.
  • Docs:
    • ADR 0014 gets an update section with the finding;
    • deploy-microvm.md and the README explain the setting and why it matters.

Evidence

In an interactive run continuing #28 (OpenCode, Qwen3-Coder-Next-6bit via just mlx-serve), the model got into a loop. It sent the same edit to skills/refine-item/SKILL.md again and again, applying and reverting one line, or changing nothing ("No changes to apply: oldString and newString are identical"). Before every call it wrote the same sentence, "Now let me update the skill to clarify what the run prompt provides". It ran until it was stopped by hand.

mlx_lm.server --help on the host (mlx-lm installed with uv): --temp TEMP Default sampling temperature (default: 0.0), --top-p … (default: 1.0), --top-k … (default: 0, disables top-k).

Testing

  • just check passes. The tests include a new validation case, and the example config is still valid.
  • I checked the jq part of mlx-serve on both configs: it yields --temp 0.7 --top-p 0.8 --top-k 20.
  • Not tested: mlx-serve on a Mac. My environment is Linux, where the recipe refuses to run.

🤖 Generated with Claude Code

`mlx_lm.server` samples greedily unless told otherwise. Its defaults are `--temp 0.0`, `--top-p 1.0` and top-k off, and the `oc-mlx` profile set nothing else. With greedy decoding, once a model starts repeating a step it tends to keep repeating it. ## Changes - **Config:** a provider model takes `sampling` (`temperature`, `top_p`, `top_k`). `factory config check` validates the ranges. The factory doesn't pass these values to the harness. - **`just mlx-serve`:** - passes `sampling` to `mlx_lm.server` as its defaults (`--temp`, `--top-p`, `--top-k`), so every request gets them; - warns when a model has no `sampling`; - reads the model's `model_id`. It used to read `modelID`, which isn't a config key. - **`factory.example.json` and the factory-dev kit:** Qwen's recommended values for Qwen3-Coder: temperature 0.7, top-p 0.8, top-k 20. - **Docs:** - ADR 0014 gets an update section with the finding; - `deploy-microvm.md` and the README explain the setting and why it matters. ## Evidence In an interactive run continuing #28 (OpenCode, Qwen3-Coder-Next-6bit via `just mlx-serve`), the model got into a loop. It sent the same `edit` to `skills/refine-item/SKILL.md` again and again, applying and reverting one line, or changing nothing ("No changes to apply: oldString and newString are identical"). Before every call it wrote the same sentence, "Now let me update the skill to clarify what the run prompt provides". It ran until it was stopped by hand. `mlx_lm.server --help` on the host (mlx-lm installed with uv): `--temp TEMP Default sampling temperature (default: 0.0)`, `--top-p … (default: 1.0)`, `--top-k … (default: 0, disables top-k)`. ## Testing - `just check` passes. The tests include a new validation case, and the example config is still valid. - I checked the jq part of `mlx-serve` on both configs: it yields `--temp 0.7 --top-p 0.8 --top-k 20`. - **Not tested:** `mlx-serve` on a Mac. My environment is Linux, where the recipe refuses to run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mlx_lm.server samples greedily by default (temperature 0), and Qwen3-Coder
got stuck repeating the same edit. A provider model now takes sampling
(temperature, top_p, top_k), which just mlx-serve passes to the server as
its defaults. The example config and the factory-dev kit set Qwen's
recommended values. mlx-serve also read modelID instead of model_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dario merged commit 856bb4357e into main 2026-11-20 13:04:47 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dario/factory!37
No description provided.