Skip to content

train_on_responses_only breaks with qwen3-thinking template because \n\n is a different token than \n #6919

Closed

Description

@compumike

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:

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
  1. Did you update? pip install --upgrade unsloth unsloth_zoo Yes.
  2. Colab or Kaggle or local / cloud Local
  3. Number GPUs used, use nvidia-smi One, RTX 3090
  4. Which notebook? Please link! N/A
  5. Which Unsloth version, TRL version, transformers version, PyTorch version? unsloth 2026.6.9
  6. Which trainer? SFTTrainer, GRPOTrainer etc SFTTrainer

Activity

  1. InfoSage05 commented on Jul 7, 2026

    @InfoSage05
    Contributor

    @compumike Could you look at #6926 ? It's a very small bug though

  2. compumike commented on Jul 7, 2026

    @compumike
    Author

    @InfoSage05 The problem with that approach (changing to match "\n\n") is that it breaks if some non-blank reasoning_content is provided:

    from transformers import AutoTokenizer
    tok = AutoTokenizer.from_pretrained("unsloth/Qwen3.6-27B", trust_remote_code=True)
    messages = [{"role": "user", "content": "x"}, {"role": "assistant", "content": "{}", "reasoning_content": "Here's my thinking..."}]
    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>\nHere's my thinking...\n</think>\n\n{}<|im_end|>\n"
    
    print(repr(ids))
    # [248045, 846, 198, 87, 248046, 198, 248045, 74455, 198, 248068, 198, 8160, 579, 821, 7047, 1076, 198, 248069, 271, 6061, 248046, 198]

    In the example above, when reasoning_content is provided, then it should match on <|im_start|>assistant\n<think>\n (single newline).

    The double newline problem only appears when reasoning_content is empty.

    I think a safer approach would be to change it to <|im_start|>assistant\n<think> with no newline. OR set force_match = False in the call to train_responses_only. But I'd want some feedback from the Unsloth team about whether that might break anything.

  3. added a commit that references this issue on Jul 7, 2026
    304b8ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions