Skip to content

Score unsloth eval datasets in the chat format the model was trained on - #19141

Merged
Lyxot merged 4 commits into
unslothai:mainfrom
NilayYadav:eval-dataset-chat-template
Nov 24, 2026
Merged

Lyxot merged 4 commits into
unslothai:mainfrom
NilayYadav:eval-dataset-chat-template

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Running unsloth eval on a chat fine-tune with a .jsonl, .json or .csv dataset gave a score near 0, even when the model answered correctly in chat. The questions were sent as plain text without the chat template, so the model just ended its turn. Dataset tasks now use the model's chat template when it has one. Built-in benchmarks like mmlu and gsm8k keep their usual prompts, so their scores still match published numbers, and --no-chat-template turns this off. A SmolLM2-135M chat fine-tune scored 0.00 on main and 0.25 with this change.

@NilayYadav NilayYadav self-assigned this Nov 23, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T08:14:45.530036Z e62c008 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 231f426f79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74153728e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/eval.py Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 74153728e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…, lm-eval versions and backends

Dataset tasks stop at the first newline, so a Qwen3-style template that opens a <think> block reduced every answer to "<think>" (Qwen3-0.6B: 0/16). Dataset-only runs now pass enable_thinking=False to lm-eval's HFLM / VLLM; built-in tasks keep lm-eval's default.

Auto mode now also requires lm-eval 0.4.10+ (the first release with enable_thinking and the BOS-prefix check that stops a doubled <bos> on Gemma templates), and prints an upgrade note otherwise.

On vLLM the template check probes the tokenizer lm-eval's vLLM wrapper loads, so Mistral repos that vLLM serves with its own tokenizer, which cannot re-encode rendered control tokens, stay off. An explicit --chat-template fails fast when that tokenizer cannot render one.

The tokenizer probe passes trust_remote_code=False like HFLM, so it never waits on a hidden consent prompt. Mixed dataset and built-in runs print why the template stays off, and results.json records the effective apply_chat_template.
@Lyxot

Lyxot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Pushed 93a7310 on top of this PR, plus a merge of latest main. What changed:

  • Thinking templates: dataset-only runs pass enable_thinking=False to lm-eval. With Qwen3-style templates the prompt otherwise opens a <think> block, and the dataset task's "\n" stop cut every answer to <think> (Qwen3-0.6B went from 0/16 to 6/16). Built-in tasks keep lm-eval's default.
  • lm-eval version: auto mode needs lm-eval 0.4.10+. Older versions can't turn thinking off and add a second <bos> on Gemma templates; there the CLI prints an upgrade note instead.
  • vLLM: the template check uses the same tokenizer lm-eval's vLLM wrapper loads. For Mistral repos that ship tekken.json, vLLM uses Mistral's own tokenizer, which can't re-encode the rendered [INST] tokens, so auto mode stays off there.
  • Explicit --chat-template now fails fast when the backend's tokenizer has no usable template, instead of crashing later or silently mis-encoding.
  • Tokenizer check passes trust_remote_code=False, like HFLM, so it can't wait on a hidden consent prompt.
  • Mixed dataset + built-in runs print why the template stays off.
  • results.json records config.apply_chat_template.

Checked locally on hf/MPS with lm-eval 0.4.13: Qwen2.5-0.5B-Instruct on a 16-question dataset scores 0.44 on main and 0.875 here. mmlu and gsm8k pass the same lm-eval arguments as main, apart from an explicit apply_chat_template=False, which is lm-eval's default. unsloth_cli/tests/test_eval.py has 167 tests passing.

@Lyxot

Lyxot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e62c00897a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/eval.py Resolved
@Lyxot

Lyxot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: e62c00897a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Lyxot

Lyxot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Review and CI wrap-up for head e62c00897a3:

@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. Dataset tasks now go through the chat template safely across thinking models, lm-eval versions and backends. Codex converged and CI is green apart from failures already on main.

@Lyxot
Lyxot merged commit 974fda1 into unslothai:main Nov 24, 2026
60 of 62 checks passed
danielhanchen added a commit that referenced this pull request Nov 24, 2026
## Problem


`tests/studio/test_chat_preset_load_config.py::test_apply_skips_missing_load_config`
fails on main in `Repo tests (CPU, studio)`. Open PRs inherit it, for
example #19141, which only touches the CLI:

```
assert 'selectedGpuIds: store.selectedGpuIds' in '// SPDX-License-Identifier: ...
```

## Cause

#19154 (keep the custom chat template when applying a chat preset) is
correct. `applyPresetLoadConfig` used to start from
`DEFAULT_PER_MODEL_CONFIG` and list the store fields a preset keeps
(`selectedGpuIds: store.selectedGpuIds`, the MLX and engram knobs). It
now starts from `currentRuntimePerModelConfig()`, so a preset changes
only its own fields. That config returns `selectedGpuIds:
s.selectedGpuIds`, so the GPU selection is still kept.

The test pinned the old spelling rather than the behavior.

The frontend test #19154 added, `preset-keeps-chat-template.test.ts`,
has a gap of its own. It checks that every non-preset field is
unchanged, but it sets `selectedGpuIds: null`, which is the default. A
preset that cleared the GPU selection still passed it.

## Fix

- `test_apply_skips_missing_load_config` now checks the mechanism:
  - `applyPresetLoadConfig` spreads `currentRuntimePerModelConfig()`;
  - that config carries the store's `selectedGpuIds`;
  - the preset body never names `selectedGpuIds` itself.
- `preset-keeps-chat-template.test.ts` sets a real selection (`[1, 0]`,
physical indexes), so its unchanged-fields loop actually covers the GPU
selection.

## Verification

- `test_chat_preset_load_config.py`: fails on main, 16 passed here.
- `preset-keeps-chat-template.test.ts`: 6 pass.
- Sabotage, both tests fail in each case:
  - starting the preset from `DEFAULT_PER_MODEL_CONFIG` again;
  - adding `selectedGpuIds: null` to the preset.
- With that second sabotage, the original frontend test still passes (6
pass, 0 fail). That shows the gap this closes.
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