Skip to content

Stop unsloth chat and unsloth inference ignoring the model's recommended settings - #11478

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:cli-recommended-sampling
Sep 22, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:cli-recommended-sampling

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

unsloth chat and unsloth inference always sent temperature 0.7, top_p 0.9, top_k 40 and repetition penalty 1.1. So the per-model settings added in #7335 never reached the CLI, and a Gemma 3 chat ran at 0.7/0.9/40/1.1 instead of 1.0/0.95/64/1.0.

These flags are now empty by default, so the model's recommended values are used, and any flag that is typed still wins. This works with a running Studio, with --no-server and on Mac. Tested with Gemma 3: the settings the model actually ran with now match what the Studio Chat page recommends.

@NilayYadav

NilayYadav commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + reproduction evidence

Pinned head: f3540293a02fd662055e4891c22d571c7fae3667. No blocking findings. Codex reviewed the staged copy (staging #144) and finished with 👍 and no suggestions.

This changes the CLI only, so nothing in the Studio UI changes and there are no screenshots. Instead I recorded the sampling values the backend actually generated with.

Setup: Modal L4, install.sh --local from the PR head, model unsloth/gemma-3-270m-it (plus -GGUF). "Before" swaps in the base versions of the 3 changed unsloth_cli files. Everything else is identical. Values were captured inside InferenceBackend.generate_chat_response / LlamaCppBackend.generate_chat_completion, so they are what the model really ran with.

Studio Chat recommendation (load_inference_config): temperature 1.0, top_p 0.95, top_k 64, min_p 0.0

Path Before (base b37bddb) After (PR head)
unsloth inference … --no-server (transformers) 0.7 / 0.9 / 40 / rep 1.1 1.0 / 0.95 / 64 / rep 1.0
unsloth inference … --no-server (GGUF, llama-server) 0.7 / 0.9 / 40 / rep 1.1 1.0 / 0.95 / 64 / rep 1.0, min_p 0.0
unsloth inference … via a running unsloth studio (server side) 0.7 / 0.9 / 40 / rep 1.1 1.0 / 0.95 / 64 / rep 1.0
--temperature 0.3 given explicitly 0.3 / 0.9 / 40 / rep 1.1 0.3 / 0.95 / 64 / rep 1.0 (typed flag still wins)

(temperature / top_p / top_k / repetition_penalty). All runs exited 0 and produced a reply.

Tests: the 4 new tests in unsloth_cli/tests/test_inference_chat.py fail on base (e.g. HTTP body was {'temperature': 0.7, 'top_p': 0.9, 'top_k': 40, 'repetition_penalty': 1.1} instead of {}) and pass on the head. The full file passes: 120 passed.

Checks: static safety scan and worktree checks (workflow perms/pins, skips, merge-aware revert) are clean. Staging CI on #144 finished: 14/16 workflows green, including Mac UI + API + Update + Inference, Unsloth API/UI/GGUF, and Windows API/UI/GGUF. The 2 reds do not come from this PR:

  • Backend CI / Shell installer tests: tests/sh/test_setup_gpu_summary_probe_sources.sh fails with _amd_prefer_discrete_gfx: command not found. The same failure is on upstream main Backend CI, including at this PR's base b37bddb (run).
  • Core zoo (all 3 cells): the same 3 GGUF tree-provenance tests (test_gguf_converter_child_env.py, test_gguf_readback_tree_provenance.py) also fail identically for the unrelated Fix push_to_hub_merged for full fine-tunes on transformers 5 #11482 staged on the same main.

Notes (non-blocking): the CLI now resolves sampling with the same resolve_effective_sampling and the same model-id choice as /v1/chat/completions, so an UNSLOTH_SAMPLING_* operator pin also applies to --no-server runs, and min_p/presence_penalty are now forwarded too. That matches Studio.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the CLI path in unsloth_cli/_inference.py was still sending the hardcoded 0.7/0.9/40/1.1 instead of the model recommendation from resolve_effective_sampling, and the before and after table matches what I would expect for Gemma 3. Will get this reviewed.

@Lyxot

Lyxot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Codex review on a staging copy (Lyxot#66, diff identical to this PR at f354029) converged on the first pass with no findings: Lyxot#66 (comment)

There were no review threads to address on this PR.

CI on the staging PR: 47 passed, 2 skipped, 2 failed. Neither failure touches unsloth_cli:

  • Repo tests (CPU, studio): 11502 passed, 4 failed, all frontend source-contract tests (test_chat_response_details_ui_contract.py x3, test_desktop_reliability_frontend_contract.py x1). This job also fails on current main.
  • Shell installer tests: ROCm GPU-name parsing cases (expected 'gfx1151|AMD Radeon Graphics', got ''), also failing on this PR's upstream run.

The upstream run's other failures are unrelated too: the Core zoo jobs fail the same way on main (gguf readback-tree provenance tests), and (Python 3.13, rest) has one test_video_gallery.py temp-file failure.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Unset sampling flags now fall through to the same resolve_effective_sampling path the server uses, both over HTTP and in-process. Codex review and CI results are in the comment above; the CI failures are unrelated to this change.

@Lyxot
Lyxot merged commit 5708db9 into unslothai:main Sep 22, 2026
47 of 52 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ded settings (unslothai#11478)

* CLI: let unset sampling flags fall back to the model's recommended values

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants