Repository: Lightning-AI/pytorch-lightning

Issue:
slim down progress bar default printing
## 🚀 Feature
The progress bar is cluttered, too many prints by default. Let's remove some of them.

### Pitch
Hi guys,
I feel the progress bar contains some uninformative prints and leaves little space for user customization. 

This is the progress bar print before validation, with empty tqdm_dict (so no user addition to the progress bar metrics):
```
Epoch 1:  39%|███▉      | 343/875 [00:07<00:10, 48.46batch/s, batch_nb=342, gpu=0, loss=0.408, v_nb=18]  
```

This is after a validation step where I add to the tqdm_dict validation accuracy and loss:
```
Epoch 2:  20%|█████████████████▏                                                                      | 171/875 [00:03<00:11, 58.99batch/s, batch_nb=170, gpu=0, loss=0.267, v_nb=21, val_acc=91.8, val_loss=0.278]
```                                                
To avoid more clutter and make some room for user-defined metrics, I propose to **remove** the following outputs from the progress bar:
- **batch_nb**: this is redundant, essentially the same number is printed on the left
- **loss**: this is something always computed in the training step. If the user wants to show it, he just adds it to the tqdm_dict
- **gpu**: this info is useless in single-gpu setting, and likely also in multi-gpu ones. 
- **v_nb**:  This is the experiment version number, which is very convenient to know. Since it stays the same during the whole experiment, we could just print it by default before the training starts. 

Also, I propose to rename "batch/s" to tqdm default "it/s"  to save a few extra characters. 
                                                                                       
Pinging @tullie @Borda since this discussion almost started in #531 .

Best,
C


Discussion:
great suggestion. let's make all the changes you suggested except:
- keep loss
- keep v_nb (but rename to v_num)

Submit a PR when ready!
Yeah great suggestion. This is something i've been thinking about as my tqdm dictionaries tend to be pretty big.

@williamFalcon, what's your reasoning for keeping loss? One issue I have with the default loss is that it only displays with 3 precision numbers so I have to put it in the tqdm anyway. Of course, that could be fixed in other ways but this seems like a decent solution. I'd suggest keeping loss as a default only when the tqdm dictionary isn't supplied.

I'd like to hear your justification on keeping v_nb too. It does seem wasteful considering it's constant throughout training.
I would be as lean as possible with the defaults because it is quite easy for the user to add stuff, while  it is impossible to remove the defaults.

> I'd suggest keeping loss as a default only when the tqdm dictionary isn't supplied.

I like this proposal: with a "default" tqdm_dict that we can override we achieve both convenience and full flexibility
@CarloLucibello @tullie want to submit a PR?

Resolving patch:
diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py
--- a/pytorch_lightning/core/lightning.py
+++ b/pytorch_lightning/core/lightning.py
@@ -1211,6 +1211,25 @@ def on_save_checkpoint(self, checkpoint):
         """
         pass
 
+    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):
diff --git a/pytorch_lightning/trainer/evaluation_loop.py b/pytorch_lightning/trainer/evaluation_loop.py
--- a/pytorch_lightning/trainer/evaluation_loop.py
+++ b/pytorch_lightning/trainer/evaluation_loop.py
@@ -295,7 +295,7 @@ def run_evaluation(self, test=False):
         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 @@ def run_evaluation(self, test=False):
         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:
diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py
--- a/pytorch_lightning/trainer/trainer.py
+++ b/pytorch_lightning/trainer/trainer.py
@@ -679,23 +679,9 @@ def training_tqdm_dict(self):
         """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):
@@ -853,7 +839,7 @@ def run_pretrain_routine(self, model):
             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)
@@ -871,7 +857,7 @@ def run_pretrain_routine(self, model):
 
         # 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
 


Test patch: