Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sft fix #307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
34 changes: 34 additions & 0 deletions src/open_r1/sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import logging
import os
import sys
import json

import datasets
import torch
Expand All @@ -62,6 +63,32 @@

logger = logging.getLogger(__name__)

# Dataset processing specially customized for HuggingFaceH4/Bespoke-Stratos-17k
# Only when the dataset is in a non-standard sft format is it necessary to use it.
def convert_format(data):
"""
Convert dataset format by merging system prompt into conversations.

Args:
data: Dict containing 'system' and 'messages' fields
Returns:
Dict with merged conversations
"""
# Create a copy of the original data
converted = data.copy()

# Create system message
system_message = {
"role": "system",
"content": data["system"]
}

# Insert system message at the beginning of conversations
converted["messages"] = [system_message] + data["messages"]


return converted


def main(script_args, training_args, model_args):
# Set seed for reproducibility
Expand Down Expand Up @@ -105,6 +132,13 @@ def main(script_args, training_args, model_args):
# Load datasets
################
dataset = load_dataset(script_args.dataset_name, name=script_args.dataset_config)

# Check if it is not a standard data set and special treatment is required.
# Dataset processing specially customized for HuggingFaceH4/Bespoke-Stratos-17k
dataset_features = dataset[script_args.dataset_train_split].features
if "system" in dataset_features:
dataset =dataset.map(convert_format,remove_columns=['conversations','system'])


################
# Load tokenizer
Expand Down