Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add start_epoch variable to base trainer train() #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/pythae/trainers/base_trainer/base_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,27 @@ def prepare_training(self):
set_seed(self.training_config.seed)

# set optimizer
self.set_optimizer()
if not hasattr(self,'optimizer'):
self.set_optimizer()

# set scheduler
self.set_scheduler()
if not hasattr(self,'scheduler'):
self.set_scheduler()

# create folder for saving
self._set_output_dir()
if not hasattr(self,'training_dir'):
self._set_output_dir()

# set callbacks
self._setup_callbacks()
if not hasattr(self,'callback_handler'):
self._setup_callbacks()

def train(self, log_output_dir: str = None):
def train(self, log_output_dir: str = None, start_epoch: int = 1):
"""This function is the main training function

Args:
log_output_dir (str): The path in which the log will be stored
start_epoch (int): The starting epoch for training. Useful to continue at correct epoch if resuming training
"""

self.prepare_training()
Expand Down Expand Up @@ -434,7 +439,7 @@ def train(self, log_output_dir: str = None):
best_train_loss = 1e10
best_eval_loss = 1e10

for epoch in range(1, self.training_config.num_epochs + 1):
for epoch in range(start_epoch, self.training_config.num_epochs + start_epoch):

self.callback_handler.on_epoch_begin(
training_config=self.training_config,
Expand Down