TRL setup_chat_format()

Creator
Creator
Seonglae Cho
Created
Created
2024 Mar 4 9:40
Editor
Edited
Edited
2025 Jun 7 16:37
Preparing models and tokenizers for chat-based fine-tuning
  • Adds essential tokens like mark conversation boundaries
  • Automatically resizes the model's embedding layer to accommodate the newly added special tokens
  • Sets up the tokenizer's chat_template to format input data into a chat-like structure, defaulting to OpenAI's
    ChatML
    format
from trl import setup_chat_format from transformers import AutoModelForCausalLM, AutoTokenizer model = AutoModelForCausalLM.from_pretrained(model_id) tokenizer = AutoTokenizer.from_pretrained(model_id) model, tokenizer = setup_chat_format(model, tokenizer)
 
 
 
 
 
 

Recommendations