unsloth/unsloth
Vineeth Sai d42256a5c5
Fix construct_chat_template leaking {INPUT}/{OUTPUT} sentinel into the chat template (#6531)
* Fix construct_chat_template leaking {INPUT}/{OUTPUT} sentinel into the template

In construct_chat_template's inner process() helper, the branch handling a
section that starts with the {INPUT}/{OUTPUT} sentinel sliced the part from
part.find(which) (which is 0 in that branch), so the literal sentinel was
re-included in the generated Jinja chat template. The endswith branch already
slices correctly with part[:part.find(which)]; this slices past the sentinel
with part[len(which):], so a template whose input or output section begins
with the sentinel (for example a user turn that starts with {INPUT}) renders
correctly instead of emitting a literal {INPUT}/{OUTPUT}.

Added a regression test covering {INPUT}-leading and {OUTPUT}-leading sections.

* [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>
2026-06-24 00:40:53 -07:00
..
dataprep Fix SyntheticDataKit.chunk_data dropping single-chunk documents (#6595) 2026-06-23 16:39:38 -03:00
kernels Windows installer: fix DiskPart UAC mid-install, drive-root cache, and spurious unsloth.exe rename warning (#6296) 2026-06-22 03:09:08 -07:00
models Fix CPOTrainer crash with multimodal processors (Gemma 4) (#6522) 2026-06-23 06:29:22 -07:00
optimizers Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
registry Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
utils Fix FlashAttention fp32 crash with DoRA (use_dora=True) (#6526) 2026-06-23 01:29:19 -07:00
__init__.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
_auto_install.py Upgrade setuptools and wheel in the auto-install command (#6282) 2026-06-13 03:59:15 -07:00
_gpu_init.py Shim removed vllm.transformers_utils.tokenizer so fast_inference works on vLLM >= 0.22 (#6390) 2026-06-17 17:25:41 -07:00
chat_templates.py Fix construct_chat_template leaking {INPUT}/{OUTPUT} sentinel into the chat template (#6531) 2026-06-24 00:40:53 -07:00
device_type.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
import_fixes.py Suppress only torchao's cosmetic cpp-extensions warning (#6506) 2026-06-22 02:28:30 -07:00
ollama_template_mappers.py Re-apply #4939: updated models template mappers (#4950) 2026-04-15 07:52:12 -07:00
save.py Fix save crash for legacy list-form _tied_weights_keys (NemotronH) (#6540) 2026-06-22 02:11:46 -07:00
tokenizer_utils.py Match IGNORED_TOKENIZER_NAMES case-insensitively (#6620) 2026-06-23 19:40:50 -03:00
trainer.py Reset torch.compile cache poisoned by a stray forward before trainer.train() (#6511) 2026-06-22 05:39:48 -07:00