mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
Make default tqdm dict overridable (#749)
* overridable tqdm_dict * Slim down default tqdm_metrics * gpu fix
This commit is contained in:
@@ -1210,6 +1210,25 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
|
||||
"""
|
||||
|
||||
def get_tqdm_dict(self):
|
||||
r"""
|
||||
Additional items to be displayed in the progress bar.
|
||||
|
||||
Return:
|
||||
Dictionary with the items to be displayed in the progress bar.
|
||||
"""
|
||||
tqdm_dict = {
|
||||
'loss': '{:.3f}'.format(self.trainer.avg_loss)
|
||||
}
|
||||
|
||||
if self.trainer.truncated_bptt_steps is not None:
|
||||
tqdm_dict['split_idx'] = self.trainer.split_idx
|
||||
|
||||
if self.trainer.logger is not None and self.trainer.logger.version is not None:
|
||||
tqdm_dict['v_num'] = self.trainer.logger.version
|
||||
|
||||
return tqdm_dict
|
||||
|
||||
|
||||
def load_hparams_from_tags_csv(tags_csv):
|
||||
if not os.path.isfile(tags_csv):
|
||||
|
||||
@@ -295,7 +295,7 @@ class TrainerEvaluationLoopMixin(ABC):
|
||||
desc = 'Testing' if test else 'Validating'
|
||||
pbar = tqdm(desc=desc, total=max_batches, leave=test, position=position,
|
||||
disable=not self.show_progress_bar, dynamic_ncols=True,
|
||||
unit='batch', file=sys.stdout)
|
||||
file=sys.stdout)
|
||||
setattr(self, f'{"test" if test else "val"}_progress_bar', pbar)
|
||||
|
||||
# run evaluation
|
||||
@@ -319,9 +319,8 @@ class TrainerEvaluationLoopMixin(ABC):
|
||||
model.on_post_performance_check()
|
||||
|
||||
# add model specific metrics
|
||||
tqdm_metrics = self.training_tqdm_dict
|
||||
if not test:
|
||||
self.main_progress_bar.set_postfix(**tqdm_metrics)
|
||||
self.main_progress_bar.set_postfix(**self.training_tqdm_dict)
|
||||
|
||||
# close progress bar
|
||||
if test:
|
||||
|
||||
@@ -681,23 +681,9 @@ class Trainer(TrainerIOMixin,
|
||||
"""Read-only for tqdm metrics.
|
||||
:return:
|
||||
"""
|
||||
tqdm_dict = {
|
||||
'loss': '{0:.3f}'.format(self.avg_loss),
|
||||
'batch_idx': '{}'.format(self.batch_idx),
|
||||
}
|
||||
ref_model = self.model if not self.data_parallel else self.model.module
|
||||
|
||||
if self.truncated_bptt_steps is not None:
|
||||
tqdm_dict['split_idx'] = self.split_idx
|
||||
|
||||
if self.logger is not None and self.logger.version is not None:
|
||||
tqdm_dict['v_num'] = self.logger.version
|
||||
|
||||
tqdm_dict.update(self.tqdm_metrics)
|
||||
|
||||
if self.on_gpu:
|
||||
tqdm_dict['gpu'] = '{}'.format(torch.cuda.current_device())
|
||||
|
||||
return tqdm_dict
|
||||
return dict(**ref_model.get_tqdm_dict(), **self.tqdm_metrics)
|
||||
|
||||
@property
|
||||
def tng_tqdm_dic(self):
|
||||
@@ -855,7 +841,7 @@ class Trainer(TrainerIOMixin,
|
||||
pbar = tqdm(desc='Validation sanity check',
|
||||
total=self.num_sanity_val_steps * len(self.get_val_dataloaders()),
|
||||
leave=False, position=2 * self.process_position,
|
||||
disable=not self.show_progress_bar, dynamic_ncols=True, unit='batch')
|
||||
disable=not self.show_progress_bar, dynamic_ncols=True)
|
||||
self.main_progress_bar = pbar
|
||||
# dummy validation progress bar
|
||||
self.val_progress_bar = tqdm(disable=True)
|
||||
@@ -873,7 +859,7 @@ class Trainer(TrainerIOMixin,
|
||||
|
||||
# init progress bar
|
||||
pbar = tqdm(leave=True, position=2 * self.process_position,
|
||||
disable=not self.show_progress_bar, dynamic_ncols=True, unit='batch',
|
||||
disable=not self.show_progress_bar, dynamic_ncols=True,
|
||||
file=sys.stdout)
|
||||
self.main_progress_bar = pbar
|
||||
|
||||
|
||||
Reference in New Issue
Block a user