-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathmaestro_early_stopping_example.py
More file actions
64 lines (52 loc) · 2.67 KB
/
Copy pathmaestro_early_stopping_example.py
File metadata and controls
64 lines (52 loc) · 2.67 KB
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
"""
Example script demonstrating how to enable early stopping in Maestro models.
This is useful to prevent overfitting and reduce training time when model
performance on the validation set has stopped improving.
"""
from maestro.trainer.models.florence_2.core import Florence2Configuration
from maestro.trainer.models.florence_2.core import train as train_florence
from maestro.trainer.models.paligemma_2.core import PaliGemma2Configuration
from maestro.trainer.models.paligemma_2.core import train as train_paligemma
from maestro.trainer.models.qwen_2_5_vl.core import Qwen25VLConfiguration
from maestro.trainer.models.qwen_2_5_vl.core import train as train_qwen
# Example with Florence-2 model
def train_florence_with_early_stopping():
"""Train a Florence-2 model with early stopping enabled"""
config = Florence2Configuration(
dataset="path/to/your/dataset", # Replace with your dataset path
epochs=20, # Set a larger number of epochs
early_stopping=True, # Enable early stopping
early_stopping_patience=3, # Stop after 3 epochs without improvement
early_stopping_threshold=0.01, # Minimum change to be considered as improvement
early_stopping_monitor="val_loss", # Metric to monitor (default: val_loss)
)
train_florence(config)
# Example with PaliGemma-2 model
def train_paligemma_with_early_stopping():
"""Train a PaliGemma-2 model with early stopping enabled"""
config = PaliGemma2Configuration(
dataset="path/to/your/dataset", # Replace with your dataset path
epochs=20, # Set a larger number of epochs
early_stopping=True, # Enable early stopping
early_stopping_patience=5, # Stop after 5 epochs without improvement
early_stopping_threshold=0.001, # More sensitive to small improvements
early_stopping_monitor="val_loss", # Metric to monitor
)
train_paligemma(config)
# Example with Qwen2.5-VL model
def train_qwen_with_early_stopping():
"""Train a Qwen2.5-VL model with early stopping enabled"""
config = Qwen25VLConfiguration(
dataset="path/to/your/dataset", # Replace with your dataset path
epochs=20, # Set a larger number of epochs
early_stopping=True, # Enable early stopping
early_stopping_patience=3, # Stop after 3 epochs without improvement
early_stopping_threshold=0.01, # Minimum change to be considered as improvement
early_stopping_monitor="val_loss", # Metric to monitor
)
train_qwen(config)
if __name__ == "__main__":
# Choose one of the training functions to run
train_florence_with_early_stopping()
# train_paligemma_with_early_stopping()
# train_qwen_with_early_stopping()