Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions chapters/en/chapter11/3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Now that we understand the key components, let's implement the training with pro

```python
from datasets import load_dataset
from trl import SFTConfig, SFTTrainer
from trl import SFTConfig, SFTTrainer, clone_chat_template
import torch

# Set device
Expand All @@ -110,12 +110,19 @@ dataset = load_dataset("HuggingFaceTB/smoltalk", "all")

# Configure model and tokenizer
model_name = "HuggingFaceTB/SmolLM2-135M"
instruct_model_name = "HuggingFaceTB/SmolLM2-135M-Instruct"

model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path=model_name).to(
device
)
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_name)
# Setup chat template
model, tokenizer = setup_chat_format(model=model, tokenizer=tokenizer)

# Setup chat template by cloning it from the tokenizer used by the instruct version of the model
model, tokenizer, added_tokens = clone_chat_template(
model=model,
tokenizer=tokenizer,
source_tokenizer_path=instruct_model_name
)

# Configure trainer
training_args = SFTConfig(
Expand Down
Loading