Skip to content

Tracking: Add {% generation %} chat templates for common model families #5471

@qgallouedec

Description

@qgallouedec

Context

SFT with assistant_only_loss=True requires the chat template to include {% generation %} / {% endgeneration %} markers so that return_assistant_tokens_mask=True can produce correct masks. Very few models ship these markers natively.

TRL should provide training chat templates with these markers for known model families (via get_training_chat_template()), and the SFT trainer auto-applies them when assistant_only_loss=True.

This issue tracks adding training templates for all model families with chat template support.

What needs to happen for each model

  1. Create <model>_training.jinja: the original template with {% generation %} / {% endgeneration %} added around assistant output (and prefix-preservation fixes if needed)
  2. Load it in chat_template_utils.py and add a branch in get_training_chat_template()
  3. Add a test verifying text output is identical to the original and masks are correct

Model families

Causal LMs with chat template

VLMs

No chat template (no action needed)

  • Bloom, GPT2, GPTNeoX, OPT, T5

Notes

  • VLMs currently don't support assistant_only_loss in SFT (blocked by a separate check). These should still be tracked so templates are ready when support lands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions