Repository navigation
Description
While trying to train Qwen3.6-27B I ran into an issue 1000/1000 samples (100.0%) were dropped after applying 'train on responses only' — only 0 remain.
After investigating, I discovered a problem with train_on_responses_only and the qwen3-thinking chat template.
The train_on_responses_only expects to find "<|im_start|>assistant\n<think>\n":
| "response": "<|im_start|>assistant\n<think>\n", |
However, the template generates: ...<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\nMY_ASSISTANT_CONTENT_HERE.
The double-newline \n\n (immediately after <think>) is its own token id 271, not the single-newline \n token id 198.
Therefore, train_on_responses_only (with the default force_match=True) fails to match it, and it masks all the tokens, entirely rejecting that training row.
The existing force_match argument might work if set to False. But the current studio code doesn't do that and just accepts the default:
unsloth/studio/backend/core/training/trainer.py
Lines 3534 to 3541 in c2a7b78
| from unsloth.chat_templates import train_on_responses_only | |
| self.trainer = train_on_responses_only( | |
| self.trainer, | |
| instruction_part = instruction_part, | |
| response_part = response_part, | |
| num_proc = config_args["dataset_num_proc"], | |
| ) |
Unsure what the cleanest fix here is, but I do think it's a real issue that anyone might hit if trying to train Qwen3.6-27B with SFT.
Minimal reproduction code:
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("unsloth/Qwen3.6-27B", trust_remote_code=True)
messages = [{"role": "user", "content": "x"}, {"role": "assistant", "content": "{}"}]
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=False)
ids = tok(text, add_special_tokens=False).input_ids
print(repr(text))
# '<|im_start|>user\nx<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n{}<|im_end|>\n'
print(repr(ids))
# [248045, 846, 198, 87, 248046, 198, 248045, 74455, 198, 248068, 271, 248069, 271, 6061, 248046, 198]
# Notice token 271 -- double newline- Did you update?
pip install --upgrade unsloth unsloth_zooYes. ColaborKaggleor local / cloud Local- Number GPUs used, use
nvidia-smiOne, RTX 3090 - Which notebook? Please link! N/A
- Which Unsloth version, TRL version, transformers version, PyTorch version? unsloth 2026.6.9
- Which trainer?
SFTTrainer,GRPOTraineretc SFTTrainer
Activity
InfoSage05 commentedon Jul 7, 2026
@compumike Could you look at #6926 ? It's a very small bug though
compumike commentedon Jul 7, 2026
@InfoSage05 The problem with that approach (changing to match "\n\n") is that it breaks if some non-blank
reasoning_contentis provided:In the example above, when
reasoning_contentis provided, then it should match on<|im_start|>assistant\n<think>\n(single newline).The double newline problem only appears when
reasoning_contentis empty.I think a safer approach would be to change it to
<|im_start|>assistant\n<think>with no newline. OR setforce_match = Falsein the call totrain_responses_only. But I'd want some feedback from the Unsloth team about whether that might break anything.fix: match qwen3-thinking double-newline in train_on_responses_only r…