File size: 1,322 Bytes
1d2f792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# /// script
# dependencies = [
#     "trl>=0.12.0",
#     "peft>=0.7.0",
#     "transformers>=4.36.0",
#     "accelerate>=0.24.0",
#     "datasets",
#     "torch",
# ]
# ///

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

print("Loading dataset...")
dataset = load_dataset("trl-lib/Capybara", split="train")
dataset = dataset.shuffle(seed=42).select(range(500))
print(f"Using {len(dataset)} examples")

dataset_split = dataset.train_test_split(test_size=0.1, seed=42)

config = SFTConfig(
    output_dir="qwen25-test",
    push_to_hub=True,
    hub_model_id="luiscosio/qwen25-test",
    num_train_epochs=1,
    per_device_train_batch_size=2,
    gradient_accumulation_steps=4,
    learning_rate=2e-4,
    logging_steps=10,
    save_strategy="epoch",
    bf16=True,
    report_to="none",
)

peft_config = LoraConfig(
    r=16,
    lora_alpha=32,
    bias="none",
    task_type="CAUSAL_LM",
    target_modules=["q_proj", "v_proj"],
)

print("Initializing trainer with Qwen2.5-0.5B...")
trainer = SFTTrainer(
    model="Qwen/Qwen2.5-0.5B",
    train_dataset=dataset_split["train"],
    args=config,
    peft_config=peft_config,
)

print("Starting training...")
trainer.train()
trainer.push_to_hub()
print("Done!")