Skip to main content
Conversations are formatted using special tokens:
  • <|startoftext|> β€” Start of the conversation.
  • <|im_start|> β€” Start of the message. Always followed by the role name (system, user, assistant, or tool) and a line break.
  • <|im_end|> β€” End end of the message.
LFM2 supports four conversation roles:
  • system β€” (Optional) Defines who the assistant is and how it should respond.
  • user β€” Messages from the user containing questions and instructions.
  • assistant β€” Responses from the model.
  • tool β€” Results from tool/function execution. Used for tool use workflows.
The complete chat template definition can be found in the chat_template.jinja file in each model’s Hugging Face repository.

Text Models

We recommend storing your conversation as a list of dictionaries as follows:
You can then apply LFM2’s chat template using the .apply_chat_template() method from Transformers:
Output:

Vision Models

LFM2-VL models follow the same chat template with additional support for images. When formatted, images are represented with a sentinel token (<image>), which is automatically replaced with image tokens by the processor. When creating conversations for vision models, use a structured format with content as a list containing image and text entries:
You can then apply the chat template using the processor’s .apply_chat_template() method:
Output: