File size: 2,111 Bytes
e9aeabf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a21597
e9aeabf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# /// script
# dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio", "transformers>=4.36.0", "datasets>=2.16.0"]
# ///

from datasets import load_dataset
from peft import LoraConfig
from trl import SFTTrainer, SFTConfig
import trackio

# Load dataset
dataset = load_dataset("machina-sports/sportingbot-classification", split="train")

# Create train/eval split (10% eval)
dataset_split = dataset.train_test_split(test_size=0.1, seed=42)

print(f"✅ Dataset loaded: {len(dataset_split['train'])} train, {len(dataset_split['test'])} eval")

# Configure LoRA
peft_config = LoraConfig(
    r=32,
    lora_alpha=64,
    target_modules="all-linear",
    lora_dropout=0.05,
    bias="none",
    task_type="CAUSAL_LM"
)

# Configure training
training_args = SFTConfig(
    output_dir="sportingbot-gemma-classifier",

    # Hub settings (CRITICAL - saves results)
    push_to_hub=True,
    hub_model_id="fernando-machina/sportingbot-gemma-classifier",
    hub_strategy="every_save",
    hub_private_repo=False,

    # Training hyperparameters (from user's config)
    num_train_epochs=5,
    per_device_train_batch_size=2,
    gradient_accumulation_steps=4,
    learning_rate=0.0001,

    # Optimization (bf16 for Gemma)
    bf16=True,
    gradient_checkpointing=True,

    # Evaluation
    eval_strategy="steps",
    eval_steps=10,

    # Checkpointing
    save_strategy="steps",
    save_steps=50,
    save_total_limit=3,

    # Logging
    logging_steps=5,
    report_to="trackio",

    # Trackio monitoring
    project="sportingbot-classification",
    run_name="gemma-2-2b-it-v1",

    # Sequence length
    max_length=512,
)

print("🚀 Starting training with Gemma 2-2B-it...")

# Create trainer
trainer = SFTTrainer(
    model="google/gemma-2-2b-it",
    train_dataset=dataset_split["train"],
    eval_dataset=dataset_split["test"],
    peft_config=peft_config,
    args=training_args,
)

# Train
trainer.train()

print("✅ Training complete! Pushing to Hub...")

# Push final model
trainer.push_to_hub()

print(f"🎉 Model saved to: https://huggingface.co/fernando-machina/sportingbot-gemma-classifier")