{#- Training variant of the Llama 3 chat template (see llama3.jinja for the original). Modifications vs the original: - Added {% generation %} / {% endgeneration %} around assistant message output to support assistant-only loss masking in SFT training. -#} {%- for message in messages %} {%- if loop.index0 == 0 %}{{- bos_token }}{%- endif %} {%- if message['role'] == 'assistant' %} {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }} {%- generation %} {{- message['content'] | trim + '<|eot_id|>' }} {%- endgeneration %} {%- else %} {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }} {%- endif %}