Compare commits

...
13 Commits
4 changed files with 23 additions and 18 deletions
+2 -2
View File
@@ -116,8 +116,8 @@ def validation_end(self, outputs):
return tqdm_dic return tqdm_dic
``` ```
## TensorboardX ## Tensorboard
Lightning is fully integrated with tensorboardX. Lightning is fully integrated with tensorboard.
<p align="center"> <p align="center">
<a href="https://williamfalcon.github.io/pytorch-lightning/"> <a href="https://williamfalcon.github.io/pytorch-lightning/">
+16 -11
View File
@@ -31,7 +31,8 @@ class Trainer(TrainerIO):
def __init__(self, def __init__(self,
experiment, experiment,
checkpoint_callback, early_stop_callback, early_stop_callback=None,
checkpoint_callback=None,
gradient_clip=0, gradient_clip=0,
cluster=None, cluster=None,
process_position=0, process_position=0,
@@ -44,12 +45,14 @@ class Trainer(TrainerIO):
check_val_every_n_epoch=1, check_val_every_n_epoch=1,
fast_dev_run=False, fast_dev_run=False,
accumulate_grad_batches=1, accumulate_grad_batches=1,
enable_early_stop=True, max_nb_epochs=1000, min_nb_epochs=1, max_nb_epochs=1000, min_nb_epochs=1,
train_percent_check=1.0, val_percent_check=1.0, test_percent_check=1.0, val_check_interval=0.95, train_percent_check=1.0, val_percent_check=1.0, test_percent_check=1.0,
val_check_interval=0.95,
log_save_interval=100, add_log_row_interval=10, log_save_interval=100, add_log_row_interval=10,
lr_scheduler_milestones=None, lr_scheduler_milestones=None,
use_amp=False, use_amp=False,
print_nan_grads=False, print_nan_grads=False,
print_weights_summary=True,
amp_level='O2', amp_level='O2',
nb_sanity_val_steps=5): nb_sanity_val_steps=5):
@@ -57,7 +60,7 @@ class Trainer(TrainerIO):
self.nb_gpu_nodes = nb_gpu_nodes self.nb_gpu_nodes = nb_gpu_nodes
self.gradient_clip = gradient_clip self.gradient_clip = gradient_clip
self.check_val_every_n_epoch = check_val_every_n_epoch self.check_val_every_n_epoch = check_val_every_n_epoch
self.enable_early_stop = enable_early_stop self.enable_early_stop = early_stop_callback is not None
self.track_grad_norm = track_grad_norm self.track_grad_norm = track_grad_norm
self.fast_dev_run = fast_dev_run self.fast_dev_run = fast_dev_run
self.on_gpu = gpus is not None and torch.cuda.is_available() self.on_gpu = gpus is not None and torch.cuda.is_available()
@@ -67,8 +70,12 @@ class Trainer(TrainerIO):
self.cluster = cluster self.cluster = cluster
self.process_position = process_position self.process_position = process_position
self.current_gpu_name = current_gpu_name self.current_gpu_name = current_gpu_name
self.print_weights_summary = print_weights_summary
self.checkpoint_callback = checkpoint_callback self.checkpoint_callback = checkpoint_callback
if self.checkpoint_callback is not None:
self.checkpoint_callback.save_function = self.save_checkpoint self.checkpoint_callback.save_function = self.save_checkpoint
self.early_stop = early_stop_callback self.early_stop = early_stop_callback
self.model = None self.model = None
self.max_nb_epochs = max_nb_epochs self.max_nb_epochs = max_nb_epochs
@@ -212,9 +219,6 @@ class Trainer(TrainerIO):
:param max_batches: Scalar :param max_batches: Scalar
:return: :return:
""" """
if self.proc_rank == 0:
print('validating...')
# enable eval mode # enable eval mode
model.zero_grad() model.zero_grad()
model.eval() model.eval()
@@ -300,7 +304,7 @@ class Trainer(TrainerIO):
mp.spawn(self.dp_train, nprocs=len(self.data_parallel_device_ids), args=(model, )) mp.spawn(self.dp_train, nprocs=len(self.data_parallel_device_ids), args=(model, ))
# treat 1 gpu as a different case to avoid nccl bugs # treat 1 gpu as a different case to avoid nccl bugs
elif len(self.data_parallel_device_ids) == 1: elif self.data_parallel_device_ids is not None and len(self.data_parallel_device_ids) == 1:
self.single_gpu_train(model) self.single_gpu_train(model)
else: else:
@@ -443,7 +447,7 @@ class Trainer(TrainerIO):
self.lr_schedulers.append(scheduler) self.lr_schedulers.append(scheduler)
# print model summary # print model summary
if self.proc_rank == 0: if self.proc_rank == 0 and self.print_weights_summary:
ref_model.summarize() ref_model.summarize()
# give model convenience properties # give model convenience properties
@@ -562,9 +566,9 @@ class Trainer(TrainerIO):
model.on_epoch_end() model.on_epoch_end()
# early stopping # early stopping
if self.enable_early_stop:
should_stop = self.early_stop_callback.on_epoch_end(epoch=epoch_nb, logs=self.__tng_tqdm_dic)
met_min_epochs = epoch_nb > self.min_nb_epochs met_min_epochs = epoch_nb > self.min_nb_epochs
if self.enable_early_stop and met_min_epochs:
should_stop = self.early_stop_callback.on_epoch_end(epoch=epoch_nb, logs=self.__tng_tqdm_dic)
# stop training # stop training
stop = should_stop and met_min_epochs stop = should_stop and met_min_epochs
@@ -720,5 +724,6 @@ class Trainer(TrainerIO):
# model checkpointing # model checkpointing
if self.proc_rank == 0: if self.proc_rank == 0:
if self.checkpoint_callback:
print('save callback...') print('save callback...')
self.checkpoint_callback.on_epoch_end(epoch=self.current_epoch, logs=self.__tng_tqdm_dic) self.checkpoint_callback.on_epoch_end(epoch=self.current_epoch, logs=self.__tng_tqdm_dic)
+1 -1
View File
@@ -78,7 +78,7 @@ class LightningModule(GradInformation, ModelIO, OptimizerConfig, ModelHooks):
:param logs: :param logs:
:return: :return:
""" """
raise NotImplementedError return logs
def loss(self, *args, **kwargs): def loss(self, *args, **kwargs):
""" """
+1 -1
View File
@@ -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.2.3', version='0.2.4',
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",