Skip to content

Commit

Permalink
Created NaiveTrainer for test purposes advances #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pab1s committed Apr 22, 2024
1 parent 4adc165 commit 593a21d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions trainers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from trainers.basic_trainer import BasicTrainer
from trainers.naive_trainer import NaiveTrainer

def get_trainer(trainer_name, **kwargs):
"""
Expand All @@ -16,5 +17,7 @@ def get_trainer(trainer_name, **kwargs):
"""
if trainer_name == "BasicTrainer":
return BasicTrainer(**kwargs)
if trainer_name == "NaiveTrainer":
return NaiveTrainer(**kwargs)
else:
raise ValueError(f"Trainer {trainer_name} not recognized.")
34 changes: 34 additions & 0 deletions trainers/naive_trainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from trainers.base_trainer import BaseTrainer


class NaiveTrainer(BaseTrainer):
"""
A complete naive trainer class for training a model. It main purpose is to
be used as a boilerplate to test some functionalities of the trainer.
Args:
model (nn.Module): The model to be trained.
device (torch.device): The device to be used for training.
Attributes:
model (nn.Module): The model to be trained.
device (torch.device): The device to be used for training.
"""

def __init__(self, model, device):
super().__init__(model, device)

def _train_epoch(self, train_loader, epoch, num_epochs, verbose=True) -> float:
"""
Simulates training the model for one epoch. It actually does nothing.
Args:
train_loader (DataLoader): The data loader for training data.
epoch (int): The current epoch number.
num_epochs (int): The total number of epochs.
verbose (bool, optional): Whether to display progress bar. Defaults to True.
Returns:
float: A mock loss value for the epoch of 0.0.
"""
return 0.0

0 comments on commit 593a21d

Please sign in to comment.