File size: 1,652 Bytes
4dbdabc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341f4dc
4dbdabc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# /// script
# dependencies = ["trl>=0.12.0", "peft>=0.7.0", "trackio", "transformers", "datasets", "accelerate", "bitsandbytes"]
# ///

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

# Load the dataset
dataset = load_dataset("kingjux/ffmpeg-commands-cot", split="train")
print(f"Loaded {len(dataset)} training examples")

# LoRA config for efficient fine-tuning
peft_config = LoraConfig(
    r=16,
    lora_alpha=32,
    lora_dropout=0.05,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
    bias="none",
    task_type="CAUSAL_LM",
)

# Training config
training_args = SFTConfig(
    output_dir="ffmpeg-command-generator",

    # Training params
    num_train_epochs=3,
    per_device_train_batch_size=2,
    gradient_accumulation_steps=4,
    learning_rate=2e-4,
    warmup_ratio=0.1,

    # Logging and saving
    logging_steps=5,
    save_strategy="epoch",

    # Hub settings
    push_to_hub=True,
    hub_model_id="kingjux/ffmpeg-command-generator",
    hub_strategy="every_save",

    # Trackio monitoring
    report_to="trackio",
    run_name="ffmpeg-sft-30examples",

    # Memory optimization
    gradient_checkpointing=True,
    bf16=True,

    # Other
    seed=42,
    max_length=1024,
)

# Create trainer
trainer = SFTTrainer(
    model="Qwen/Qwen2.5-0.5B-Instruct",
    train_dataset=dataset,
    peft_config=peft_config,
    args=training_args,
)

# Train
print("Starting training...")
trainer.train()

# Save and push
print("Pushing to Hub...")
trainer.save_model()
trainer.push_to_hub()

print("Training complete!")