Upload run_sft_job.py with huggingface_hub
Browse files- run_sft_job.py +26 -15
run_sft_job.py
CHANGED
|
@@ -39,25 +39,27 @@ from trl import SFTTrainer, SFTConfig
|
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
-
|
| 43 |
-
# This function is used to create a single string from the chat messages.
|
| 44 |
-
# It mimics the format used by the chat templates in the TRL library.
|
| 45 |
-
text = ""
|
| 46 |
-
for message in example["messages"]:
|
| 47 |
-
role = message["role"]
|
| 48 |
-
content = message["content"]
|
| 49 |
-
text += f"**{role.capitalize()}:** {content}\n\n"
|
| 50 |
-
return {"text": text}
|
| 51 |
|
| 52 |
# 1. Load Dataset
|
| 53 |
print("π¦ Loading dataset OliverSlivka/itemsety-real-training...")
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
# Apply the formatting function to create the 'text' column
|
| 57 |
-
dataset = dataset.map(format_chat_template)
|
| 58 |
-
|
| 59 |
-
train_dataset = dataset["train"]
|
| 60 |
-
eval_dataset = dataset["validation"]
|
| 61 |
print(f"β
Dataset loaded and formatted. Train: {len(train_dataset)}, Eval: {len(eval_dataset)}")
|
| 62 |
|
| 63 |
# 2. Training Configuration
|
|
@@ -113,6 +115,7 @@ trainer = SFTTrainer(
|
|
| 113 |
eval_dataset=eval_dataset, # CRITICAL: Must provide eval_dataset when eval_strategy is enabled
|
| 114 |
args=config,
|
| 115 |
peft_config=peft_config,
|
|
|
|
| 116 |
)
|
| 117 |
|
| 118 |
# 5. Start Training
|
|
@@ -122,3 +125,11 @@ trainer.train()
|
|
| 122 |
print("β
Training complete!")
|
| 123 |
print(f"πΎ Model pushed to Hub at: https://huggingface.co/{config.hub_model_id}")
|
| 124 |
print("π View metrics at: https://huggingface.co/spaces/OliverSlivka/trackio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
+
from datasets import Dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# 1. Load Dataset
|
| 45 |
print("π¦ Loading dataset OliverSlivka/itemsety-real-training...")
|
| 46 |
+
original_dataset = load_dataset("OliverSlivka/itemsety-real-training")
|
| 47 |
+
|
| 48 |
+
def format_dataset(dataset):
|
| 49 |
+
# Manually create a new dataset with a 'text' column.
|
| 50 |
+
new_data = {"text": []}
|
| 51 |
+
for example in dataset:
|
| 52 |
+
text = ""
|
| 53 |
+
for message in example["messages"]:
|
| 54 |
+
role = message["role"]
|
| 55 |
+
content = message["content"]
|
| 56 |
+
text += f"**{role.capitalize()}:** {content}\n\n"
|
| 57 |
+
new_data["text"].append(text)
|
| 58 |
+
return Dataset.from_dict(new_data)
|
| 59 |
+
|
| 60 |
+
train_dataset = format_dataset(original_dataset["train"])
|
| 61 |
+
eval_dataset = format_dataset(original_dataset["validation"])
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
print(f"β
Dataset loaded and formatted. Train: {len(train_dataset)}, Eval: {len(eval_dataset)}")
|
| 64 |
|
| 65 |
# 2. Training Configuration
|
|
|
|
| 115 |
eval_dataset=eval_dataset, # CRITICAL: Must provide eval_dataset when eval_strategy is enabled
|
| 116 |
args=config,
|
| 117 |
peft_config=peft_config,
|
| 118 |
+
dataset_text_field="text",
|
| 119 |
)
|
| 120 |
|
| 121 |
# 5. Start Training
|
|
|
|
| 125 |
print("β
Training complete!")
|
| 126 |
print(f"πΎ Model pushed to Hub at: https://huggingface.co/{config.hub_model_id}")
|
| 127 |
print("π View metrics at: https://huggingface.co/spaces/OliverSlivka/trackio")
|
| 128 |
+
|
| 129 |
+
# 5. Start Training
|
| 130 |
+
print("π Starting training...")
|
| 131 |
+
trainer.train()
|
| 132 |
+
|
| 133 |
+
print("β
Training complete!")
|
| 134 |
+
print(f"πΎ Model pushed to Hub at: https://huggingface.co/{config.hub_model_id}")
|
| 135 |
+
print("π View metrics at: https://huggingface.co/spaces/OliverSlivka/trackio")
|