Skip to content

Studio: keep the custom chat template when applying a chat preset - #19154

Merged
Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:preset-keep-chat-template
Nov 24, 2026
Merged

Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:preset-keep-chat-template

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Applying a custom chat preset cleared the custom chat template, so the next GGUF reload started llama-server without it and the model went back to its default template. Presets never save a chat template, so applying one now keeps the current template, the same way it already keeps the engram, MLX and GPU settings. Picking the Default preset and the preset's other settings behave as before.

Before

before

After

after

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@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-24T06:23:45.167578Z 9ea10d3 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. Another round soon, please!

Reviewed commit: cdaeeb1209

ℹ️ 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".

… saves

A preset's load config now starts from the current model's settings instead of the defaults, so the custom chat template, the Transformers 4-bit choice, the vLLM/SGLang engine settings, the MLX drafter and the tensor split are no longer reset by applying a preset. The drafter and the split are still cleared when the preset's speculative mode or Auto GPU layers rule them out, as the settings controls do.
@Lyxot

Lyxot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Pushed 9ea10d3 on top of the original commit (plus a merge of main).

The PR's root cause is wider than the chat template: applyPresetLoadConfig rebuilt the load config from DEFAULT_PER_MODEL_CONFIG, so every load field a preset does not save was reset on apply, not only chatTemplateOverride. That also flipped a 16-bit Transformers load back to 4-bit and reset the vLLM/SGLang engine settings, the MLX drafter and the tensor split.

  • A preset now starts from the current model's settings (currentRuntimePerModelConfig()) and overlays only the fields it saves; the hand-kept exceptions (MLX toggles, Engram precision, GPU pick, template) are gone.
  • Settings the preset's own values rule out are still cleared, as the settings controls do: the drafter when the speculative mode doesn't use one, and the tensor split unless the preset is Manual with GPU layers > 0.
  • Tests cover non-preset fields staying unchanged, the GPU-layer reset, the split and drafter rules, and the template being dropped on a switch to another model.

Checked live in Unsloth Studio with a GGUF and a custom template: on main, applying a preset and reloading starts llama-server without --chat-template-file; on this branch the custom template is kept.

@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. You're on a roll.

Reviewed commit: 9ea10d3d32

ℹ️ 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

Codex converged on 9ea10d3: #19154 (comment)

CI (upstream jobs were stuck in queue, so it ran on a fork staging PR with the same head against current main, Lyxot#281): 38 pass, 6 fail, none from this PR.

  • Frontend unit tests (Windows) / Frontend build + bundle sanity: the same 4 tests (image decode/loopback src, URL handoff) fail identically on an unrelated staging PR against the same main. The new preset tests pass.
  • Backend Python 3.13 (a-f, m-r, diffusion) and Repo tests (CPU, studio): this PR changes no backend files; the same jobs fail on other staging PRs against the same main.

Changed during this round: one commit on top of the original (9ea10d3, plus a merge of main). Applying a preset now changes only the load settings it saves, instead of resetting every other load setting (chat template, Transformers 4-bit choice, vLLM/SGLang engine settings, MLX drafter, tensor split) to defaults.

@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. Applying a preset now changes only the load settings it saves; Codex converged and CI checked on staging.

@Lyxot
Lyxot merged commit 30193d5 into unslothai:main Nov 24, 2026
38 of 44 checks passed
danielhanchen added a commit that referenced this pull request Nov 24, 2026
#19230)

## Problem


`studio/backend/tests/test_diffusion_rocm_tag_detect.py::test_no_diffusion_or_video_gate_reads_version_hip_directly`
fails on main in the backend `(Python 3.13, diffusion)` shard, so open
PRs such as #19154 inherit it:

```
AssertionError: use core.inference.rocm_bf16.is_rocm_torch(torch): AMD SDK / Radeon wheels leave torch.version.hip unset. Raw reads: {'diffusion_krea2_prefix_kv.py': [170]}
```

## Cause

#19208 (Krea 2 valid key prefix without a mask) added a gate that can
swap auto's cuDNN pin for CUDA native flash on the mask-free prefix
call. It decided "not ROCm" with `getattr(torch.version, "hip", None) is
None`. AMD SDK / Radeon ROCm wheels leave `torch.version.hip` unset and
carry the tag in `torch.__version__` instead. On those builds, the gate
could treat a ROCm card as CUDA and force the CUDA flash backend.

The guard is right and this is a real bug in the new gate, not a stale
test.

## Fix

- The gate now uses `core.inference.rocm_bf16.is_rocm_torch(torch)`,
like every other diffusion and video gate.
- New test `test_a_rocm_build_keeps_the_pin` checks that a ROCm build
keeps the pin for both spellings: `torch.version.hip` set, and only a
`+rocm` tag in `torch.__version__`.

## Verification

- `test_diffusion_rocm_tag_detect.py` and
`test_diffusion_krea2_prefix_kv.py`: 32 passed.
- Main's `diffusion_krea2_prefix_kv.py` with this branch's tests fails
both the guard and
`test_a_rocm_build_keeps_the_pin[None-2.9.0+rocm7.1]`. The `version.hip`
case passes on both, because main already handled it.

I could not run this on real ROCm hardware. The check is the version-tag
detection, simulated by patching `torch.__version__`.
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