mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-12 12:40:20 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6bc203f05 | ||
|
|
12352f1949 | ||
|
|
f881bf6750 | ||
|
|
0637d8e7a5 | ||
|
|
2514f62913 | ||
|
|
95aee7ff96 | ||
|
|
ffd6dc678c | ||
|
|
1961a6abb2 | ||
|
|
676d76d839 | ||
|
|
b625b293f4 |
@@ -195,6 +195,7 @@ class Trainer(TrainerIO):
|
|||||||
# -----------------------------
|
# -----------------------------
|
||||||
def fit(self, model):
|
def fit(self, model):
|
||||||
self.model = model
|
self.model = model
|
||||||
|
model.trainer = self
|
||||||
|
|
||||||
# transfer data loaders from model
|
# transfer data loaders from model
|
||||||
self.__get_dataloaders(model)
|
self.__get_dataloaders(model)
|
||||||
@@ -269,21 +270,22 @@ class Trainer(TrainerIO):
|
|||||||
# ---------------
|
# ---------------
|
||||||
# RUN TRAIN STEP
|
# RUN TRAIN STEP
|
||||||
# ---------------
|
# ---------------
|
||||||
self.__run_tng_batch(data_batch)
|
batch_result = self.__run_tng_batch(data_batch)
|
||||||
|
early_stop_epoch = batch_result == -1
|
||||||
|
|
||||||
# ---------------
|
# ---------------
|
||||||
# RUN VAL STEP
|
# RUN VAL STEP
|
||||||
# ---------------
|
# ---------------
|
||||||
is_val_check_batch = (batch_nb + 1) % self.val_check_batch == 0
|
is_val_check_batch = (batch_nb + 1) % self.val_check_batch == 0
|
||||||
if self.fast_dev_run or is_val_check_batch:
|
if self.fast_dev_run or is_val_check_batch or early_stop_epoch:
|
||||||
self.__run_validation()
|
self.__run_validation()
|
||||||
|
|
||||||
# when batch should be saved
|
# when batch should be saved
|
||||||
if (batch_nb + 1) % self.log_save_interval == 0:
|
if (batch_nb + 1) % self.log_save_interval == 0 or early_stop_epoch:
|
||||||
self.experiment.save()
|
self.experiment.save()
|
||||||
|
|
||||||
# when metrics should be logged
|
# when metrics should be logged
|
||||||
if batch_nb % self.add_log_row_interval == 0:
|
if batch_nb % self.add_log_row_interval == 0 or early_stop_epoch:
|
||||||
# count items in memory
|
# count items in memory
|
||||||
# nb_params, nb_tensors = count_mem_items()
|
# nb_params, nb_tensors = count_mem_items()
|
||||||
|
|
||||||
@@ -307,6 +309,10 @@ class Trainer(TrainerIO):
|
|||||||
if self.__is_function_implemented('on_batch_end'):
|
if self.__is_function_implemented('on_batch_end'):
|
||||||
self.model.on_batch_end()
|
self.model.on_batch_end()
|
||||||
|
|
||||||
|
# end epoch early
|
||||||
|
if early_stop_epoch:
|
||||||
|
break
|
||||||
|
|
||||||
# hook
|
# hook
|
||||||
if self.__is_function_implemented('on_epoch_end'):
|
if self.__is_function_implemented('on_epoch_end'):
|
||||||
self.model.on_epoch_end()
|
self.model.on_epoch_end()
|
||||||
@@ -321,15 +327,16 @@ class Trainer(TrainerIO):
|
|||||||
if stop:
|
if stop:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def __run_tng_batch(self, data_batch):
|
def __run_tng_batch(self, data_batch):
|
||||||
if data_batch is None:
|
if data_batch is None:
|
||||||
return
|
return 0
|
||||||
|
|
||||||
# hook
|
# hook
|
||||||
if self.__is_function_implemented('on_batch_start'):
|
if self.__is_function_implemented('on_batch_start'):
|
||||||
response = self.model.on_batch_start(data_batch)
|
response = self.model.on_batch_start(data_batch)
|
||||||
if response == -1:
|
if response == -1:
|
||||||
return
|
return -1
|
||||||
|
|
||||||
if self.enable_tqdm:
|
if self.enable_tqdm:
|
||||||
self.prog_bar.update(1)
|
self.prog_bar.update(1)
|
||||||
@@ -371,6 +378,8 @@ class Trainer(TrainerIO):
|
|||||||
if self.__is_function_implemented('on_batch_end'):
|
if self.__is_function_implemented('on_batch_end'):
|
||||||
self.model.on_batch_end()
|
self.model.on_batch_end()
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
def __run_validation(self):
|
def __run_validation(self):
|
||||||
# decide if can check epochs
|
# decide if can check epochs
|
||||||
can_check_epoch = (self.current_epoch + 1) % self.check_val_every_n_epoch == 0
|
can_check_epoch = (self.current_epoch + 1) % self.check_val_every_n_epoch == 0
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ class TrainerIO(object):
|
|||||||
self.early_stop_callback.wait = checkpoint['early_stop_callback_wait']
|
self.early_stop_callback.wait = checkpoint['early_stop_callback_wait']
|
||||||
self.early_stop_callback.patience = checkpoint['early_stop_callback_patience']
|
self.early_stop_callback.patience = checkpoint['early_stop_callback_patience']
|
||||||
self.global_step = checkpoint['global_step']
|
self.global_step = checkpoint['global_step']
|
||||||
|
self.current_epoch = checkpoint['epoch']
|
||||||
|
|
||||||
# restore the optimizers
|
# restore the optimizers
|
||||||
optimizer_states = checkpoint['optimizer_states']
|
optimizer_states = checkpoint['optimizer_states']
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class RootModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
|
|||||||
self.overfit = hparams.overfit
|
self.overfit = hparams.overfit
|
||||||
self.gradient_clip = hparams.gradient_clip
|
self.gradient_clip = hparams.gradient_clip
|
||||||
self.num = 2
|
self.num = 2
|
||||||
|
self.trainer = None
|
||||||
|
|
||||||
# track if gpu was requested for checkpointing
|
# track if gpu was requested for checkpointing
|
||||||
self.on_gpu = False
|
self.on_gpu = False
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from setuptools import setup, find_packages
|
|||||||
# http://blog.ionelmc.ro/2014/05/25/python-packaging/
|
# http://blog.ionelmc.ro/2014/05/25/python-packaging/
|
||||||
setup(
|
setup(
|
||||||
name="pytorch-lightning",
|
name="pytorch-lightning",
|
||||||
version='0.1.dev12',
|
version='0.1.dev16',
|
||||||
description="The Keras for ML researchers using PyTorch",
|
description="The Keras for ML researchers using PyTorch",
|
||||||
author="William Falcon",
|
author="William Falcon",
|
||||||
author_email="waf2107@columbia.edu",
|
author_email="waf2107@columbia.edu",
|
||||||
|
|||||||
Reference in New Issue
Block a user