{"record":{"id":"7a7d27e917faf0a3","repo":"hiyouga/LlamaFactory","slug":"current-template-does-not-support-train-on-prompt","errorCode":null,"errorMessage":"Current template does not support `train_on_prompt`.","messagePattern":"Current template does not support `train_on_prompt`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/data/template.py","lineNumber":688,"sourceCode":"\n\ndef get_template_and_fix_tokenizer(tokenizer: \"PreTrainedTokenizer\", data_args: \"DataArguments\") -> \"Template\":\n    r\"\"\"Get chat template and fixes the tokenizer.\"\"\"\n    if data_args.template is None:\n        if isinstance(tokenizer.chat_template, str):\n            logger.warning_rank0(\"`template` was not specified, try parsing the chat template from the tokenizer.\")\n            template = parse_template(tokenizer)\n        else:\n            logger.warning_rank0(\"`template` was not specified, use `empty` template.\")\n            template = TEMPLATES[\"empty\"]  # placeholder\n    else:\n        if data_args.template not in TEMPLATES:\n            raise ValueError(f\"Template {data_args.template} does not exist.\")\n\n        template = TEMPLATES[data_args.template]\n\n    if data_args.train_on_prompt and template.efficient_eos:\n        raise ValueError(\"Current template does not support `train_on_prompt`.\")\n\n    if data_args.tool_format is not None:\n        logger.info_rank0(f\"Using tool format: {data_args.tool_format}.\")\n        default_slots = [\"{{content}}\"] if template.efficient_eos else [\"{{content}}\", {\"eos_token\"}]\n        template.format_function = FunctionFormatter(slots=default_slots, tool_format=data_args.tool_format)\n        template.format_tools = ToolFormatter(tool_format=data_args.tool_format)\n\n    if data_args.default_system is not None:\n        logger.info_rank0(f\"Using default system message: {data_args.default_system}.\")\n        template.default_system = data_args.default_system\n\n    if isinstance(template, ReasoningTemplate):\n        logger.warning_rank0(\n            \"You are using reasoning template. \"\n            \"If the base model is NOT a reasoning model (i.e., it has a separate Instruct variant), \"\n            \"please add `_nothink` suffix to disable thinking. \"\n            \"For reasoning-only model families (e.g., Qwen3.6), the suffix is not needed. \"\n            \"e.g., qwen3_vl_nothink\"","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/data/template.py#L670-L706","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove train_on_prompt: true (set it to false or delete the line) — most common intent.","Switch to a non-efficient-eos template variant that matches your model (check TEMPLATES entry / register_template efficient_eos argument).","If you control the template, re-register it with efficient_eos=False and an explicit eos slot so per-turn EOS exists."],"exampleFix":"# before\ntemplate: qwen\ncutoff_len: 2048\ntrain_on_prompt: true\n\n# after\ntemplate: qwen\ncutoff_len: 2048\ntrain_on_prompt: false","handlingStrategy":"validation","validationCode":"from llamafactory.data.template import TEMPLATES\n\ntmpl = TEMPLATES[data_args.template]\nif data_args.train_on_prompt:\n    assert not tmpl.efficient_eos, f\"{data_args.template} is efficient_eos; disable train_on_prompt\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check template.efficient_eos before enabling train_on_prompt.","Default train_on_prompt to false; only enable with verified templates."],"tags":["template","config","train-on-prompt"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}