Skip to content

Commit

Permalink
new: replace max epochs with early stopping callback #113
Browse files Browse the repository at this point in the history
  • Loading branch information
joein committed May 31, 2022
1 parent d1a215c commit db8dc14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions quaterion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch
import pytorch_lightning as pl
from torch.utils.data import Dataset
from pytorch_lightning.callbacks import ModelSummary
from pytorch_lightning.callbacks import ModelSummary, EarlyStopping
from quaterion_models import SimilarityModel

from quaterion.dataset.similarity_data_loader import (
Expand All @@ -14,8 +14,9 @@
from quaterion.eval.evaluator import Evaluator
from quaterion.loss import GroupLoss, PairwiseLoss
from quaterion.train.trainable_model import TrainableModel
from quaterion.utils.progress_bar import QuaterionProgressBar
from quaterion.train.callbacks import CleanupCallback, MetricsCallback
from quaterion.utils.enums import TrainStage
from quaterion.utils.progress_bar import QuaterionProgressBar


class Quaterion:
Expand Down Expand Up @@ -110,8 +111,11 @@ def evaluate(
def trainer_defaults():
use_gpu = torch.cuda.is_available()
defaults = {
"callbacks": [QuaterionProgressBar(), ModelSummary(max_depth=3)],
"max_epochs": 1000,
"callbacks": [
QuaterionProgressBar(),
EarlyStopping(f"{TrainStage.VALIDATION}_loss"),
ModelSummary(max_depth=3),
],
"gpus": int(use_gpu),
"auto_select_gpus": use_gpu,
"log_every_n_steps": 10,
Expand Down
2 changes: 1 addition & 1 deletion quaterion/utils/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
theme=theme,
console_kwargs=console_kwargs,
)
self.predict_progress_bar_id: Optional[int] = None
self.predict_progress_bar_id = None
self._caching = False

def on_predict_batch_start(
Expand Down

0 comments on commit db8dc14

Please sign in to comment.