hiyouga/LlamaFactory · error · ValueError

Current template does not support `train_on_prompt`.

Error message

Current template does not support `train_on_prompt`.

What it means

train_on_prompt keeps loss on prompt tokens, which requires every assistant response to carry its own EOS separator. Templates flagged efficient_eos (those that end responses without an explicit eos slot because the next prefix supplies it) cannot support this, so get_template_and_fix_tokenizer raises ValueError when both train_on_prompt=True and the template's efficient_eos flag are set.

Source

Thrown at src/llamafactory/data/template.py:688


def get_template_and_fix_tokenizer(tokenizer: "PreTrainedTokenizer", data_args: "DataArguments") -> "Template":
    r"""Get chat template and fixes the tokenizer."""
    if data_args.template is None:
        if isinstance(tokenizer.chat_template, str):
            logger.warning_rank0("`template` was not specified, try parsing the chat template from the tokenizer.")
            template = parse_template(tokenizer)
        else:
            logger.warning_rank0("`template` was not specified, use `empty` template.")
            template = TEMPLATES["empty"]  # placeholder
    else:
        if data_args.template not in TEMPLATES:
            raise ValueError(f"Template {data_args.template} does not exist.")

        template = TEMPLATES[data_args.template]

    if data_args.train_on_prompt and template.efficient_eos:
        raise ValueError("Current template does not support `train_on_prompt`.")

    if data_args.tool_format is not None:
        logger.info_rank0(f"Using tool format: {data_args.tool_format}.")
        default_slots = ["{{content}}"] if template.efficient_eos else ["{{content}}", {"eos_token"}]
        template.format_function = FunctionFormatter(slots=default_slots, tool_format=data_args.tool_format)
        template.format_tools = ToolFormatter(tool_format=data_args.tool_format)

    if data_args.default_system is not None:
        logger.info_rank0(f"Using default system message: {data_args.default_system}.")
        template.default_system = data_args.default_system

    if isinstance(template, ReasoningTemplate):
        logger.warning_rank0(
            "You are using reasoning template. "
            "If the base model is NOT a reasoning model (i.e., it has a separate Instruct variant), "
            "please add `_nothink` suffix to disable thinking. "
            "For reasoning-only model families (e.g., Qwen3.6), the suffix is not needed. "
            "e.g., qwen3_vl_nothink"

View on GitHub (pinned to f28afaf635)

Solutions

  1. Remove train_on_prompt: true (set it to false or delete the line) — most common intent.
  2. Switch to a non-efficient-eos template variant that matches your model (check TEMPLATES entry / register_template efficient_eos argument).
  3. If you control the template, re-register it with efficient_eos=False and an explicit eos slot so per-turn EOS exists.

Example fix

# before
template: qwen
cutoff_len: 2048
train_on_prompt: true

# after
template: qwen
cutoff_len: 2048
train_on_prompt: false
Defensive patterns

Strategy: validation

Validate before calling

from llamafactory.data.template import TEMPLATES

tmpl = TEMPLATES[data_args.template]
if data_args.train_on_prompt:
    assert not tmpl.efficient_eos, f"{data_args.template} is efficient_eos; disable train_on_prompt"

Prevention

When it happens

Trigger: Setting train_on_prompt: true in the YAML together with a template registered with efficient_eos=True (e.g. templates built on the efficient-eos default like qwen-style or glm-style variants); enabling train_on_prompt after switching templates.

Common situations: Users enabling train_on_prompt to learn prompt formatting without checking template compatibility; switching from a llama template (works) to an efficient-eos template (fails) with the same flag set.

Related errors


AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14). Data as JSON: /api/errors/7a7d27e917faf0a3. Report an issue: GitHub.