# Buggy code
def run_evaluation(self, test_mode: bool = False):
    # hook
    model = self.get_model()
    model.on_pre_performance_check()

    # select dataloaders
    if test_mode:
        self.reset_test_dataloader(model)

        dataloaders = self.test_dataloaders
        max_batches = self.num_test_batches
    else:
        # val
        if self.val_dataloaders is None:
            self.reset_val_dataloader(model)

        dataloaders = self.val_dataloaders
        max_batches = self.num_val_batches

    # enable fast_dev_run without val loop
    if dataloaders is None:
        return [], []

    # cap max batches to 1 when using fast_dev_run
    if self.fast_dev_run:
        max_batches = [1]

    # Validation/Test begin callbacks
    if test_mode:
        self.on_test_start()
    else:
        self.on_validation_start()

    # enable disabling validation step with limit_val_batches = 0
    should_skip = sum(max_batches) == 0
    if should_skip:
        return [], []

    # run evaluation (val_step + val_step_end + val_epoch_end)
    eval_results = self._evaluate(self.model, dataloaders, max_batches, test_mode)

    # log the final eval loop metrics
    eval_loop_results = self.__log_evaluation_epoch_metrics(eval_results, test_mode)

    # hook
    model.on_post_performance_check()

    # eventual dataset reloading
    if test_mode:
        if self.reload_dataloaders_every_epoch:
            self.reset_test_dataloader(model)
    else:
        # val
        if self.reload_dataloaders_every_epoch:
            self.reset_val_dataloader(model)

    # Validation/Test end callbacks
    if test_mode:
        self.on_test_end()
    else:
        self.on_validation_end()

    return eval_loop_results, eval_results


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/luca/Repositories/set-operations/src/run_experiment.py", line 73, in <module>
trainer.fit(model,)
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 979, in fit
self.single_gpu_train(model)
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/distrib_parts.py", line 185, in single_gpu_train
self.run_pretrain_routine(model)
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1156, in run_pretrain_routine
self.train()
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 370, in train
self.run_training_epoch()
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 470, in run_training_epoch
self.run_evaluation(test_mode=False)
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 409, in run_evaluation
eval_results = self._evaluate(self.model, dataloaders, max_batches, test_mode)
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 270, in _evaluate
dl_max_batches = max_batches[dataloader_idx]
IndexError: list index out of range

Exception ignored in: <function tqdm.__del__ at 0x7fe5848ba710>
Traceback (most recent call last):
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/tqdm/std.py", line 1086, in __del__
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/tqdm/std.py", line 1293, in close
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/tqdm/std.py", line 1471, in display
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/tqdm/std.py", line 1089, in __repr__
File "/home/luca/.cache/pypoetry/virtualenvs/set-operations-GbjOlTQ2-py3.7/lib/python3.7/site-packages/tqdm/std.py", line 1433, in format_dict
TypeError: cannot unpack non-iterable NoneType object

Process finished with exit code 1

# Fixed code
def run_evaluation(self, test_mode: bool = False):
    # hook
    model = self.get_model()
    model.on_pre_performance_check()

    # select dataloaders
    if test_mode:
        self.reset_test_dataloader(model)

        dataloaders = self.test_dataloaders
        max_batches = self.num_test_batches
    else:
        # val
        if self.val_dataloaders is None:
            self.reset_val_dataloader(model)

        dataloaders = self.val_dataloaders
        max_batches = self.num_val_batches

    if dataloaders is None:
        return [], []

    # Validation/Test begin callbacks
    if test_mode:
        self.on_test_start()
    else:
        self.on_validation_start()

    # enable disabling validation step with limit_val_batches = 0
    should_skip = sum(max_batches) == 0
    if should_skip:
        return [], []

    # run evaluation (val_step + val_step_end + val_epoch_end)
    eval_results = self._evaluate(self.model, dataloaders, max_batches, test_mode)

    # log the final eval loop metrics
    eval_loop_results = self.__log_evaluation_epoch_metrics(eval_results, test_mode)

    # hook
    model.on_post_performance_check()

    # eventual dataset reloading
    if test_mode:
        if self.reload_dataloaders_every_epoch:
            self.reset_test_dataloader(model)
    else:
        # val
        if self.reload_dataloaders_every_epoch:
            self.reset_val_dataloader(model)

    # Validation/Test end callbacks
    if test_mode:
        self.on_test_end()
    else:
        self.on_validation_end()

    return eval_loop_results, eval_results