Repository: Lightning-AI/pytorch-lightning
File: pytorch_lightning/callbacks/gpu_stats_monitor.py (Python)

Code before:
        })

    def on_train_start(self, trainer, pl_module):
        if not trainer.logger:
            raise MisconfigurationException(
                'Cannot use GPUStatsMonitor callback with Trainer that has no logger.'
            )

        if not trainer.on_gpu:
            raise MisconfigurationException(
                'You are using GPUStatsMonitor but are not running on GPU'
                f' since gpus attribute in Trainer is set to {trainer.gpus}.'
            )

        self._gpu_ids = ','.join(map(str, trainer.data_parallel_device_ids))

    def on_train_epoch_start(self, trainer, pl_module):
        self._snap_intra_step_time = None
        self._snap_inter_step_time = None

    @rank_zero_only
    def on_train_batch_start(self, trainer, pl_module, *_):
        if self._log_stats.intra_step_time:
            self._snap_intra_step_time = time.time()

        if not GPUStatsMonitor._should_log(trainer):
            return

        gpu_stat_keys = self._get_gpu_stat_keys()
        gpu_stats = self._get_gpu_stats([k for k, _ in gpu_stat_keys])
        logs = self._parse_gpu_stats(self._gpu_ids, gpu_stats, gpu_stat_keys)

        if self._log_stats.inter_step_time and self._snap_inter_step_time:
            # First log at beginning of second step
            logs['batch_time/inter_step (ms)'] = (time.time() - self._snap_inter_step_time) * 1000

        trainer.logger.log_metrics(logs, step=trainer.global_step)

    @rank_zero_only
    def on_train_batch_end(self, trainer, pl_module, *_):
        if self._log_stats.inter_step_time:
            self._snap_inter_step_time = time.time()

        if not self._should_log(trainer):
            return

        gpu_stat_keys = self._get_gpu_stat_keys() + self._get_gpu_device_stat_keys()
        gpu_stats = self._get_gpu_stats([k for k, _ in gpu_stat_keys])
        logs = self._parse_gpu_stats(self._gpu_ids, gpu_stats, gpu_stat_keys)

        if self._log_stats.intra_step_time and self._snap_intra_step_time:

Review comment (suggestion):
```suggestion
        if not self._should_log(trainer):
```

Code after:
        })

    def on_train_start(self, trainer, *args, **kwargs):
        if not trainer.logger:
            raise MisconfigurationException(
                'Cannot use GPUStatsMonitor callback with Trainer that has no logger.'
            )

        if not trainer.on_gpu:
            raise MisconfigurationException(
                'You are using GPUStatsMonitor but are not running on GPU'
                f' since gpus attribute in Trainer is set to {trainer.gpus}.'
            )

        self._gpu_ids = ','.join(map(str, trainer.data_parallel_device_ids))

    def on_train_epoch_start(self, *args, **kwargs):
        self._snap_intra_step_time = None
        self._snap_inter_step_time = None

    @rank_zero_only
    def on_train_batch_start(self, trainer, *args, **kwargs):
        if self._log_stats.intra_step_time:
            self._snap_intra_step_time = time.time()

        if not self._should_log(trainer):
            return

        gpu_stat_keys = self._get_gpu_stat_keys()
        gpu_stats = self._get_gpu_stats([k for k, _ in gpu_stat_keys])
        logs = self._parse_gpu_stats(self._gpu_ids, gpu_stats, gpu_stat_keys)

        if self._log_stats.inter_step_time and self._snap_inter_step_time:
            # First log at beginning of second step
            logs['batch_time/inter_step (ms)'] = (time.time() - self._snap_inter_step_time) * 1000

        trainer.logger.log_metrics(logs, step=trainer.global_step)

    @rank_zero_only
    def on_train_batch_end(self, trainer, *args, **kwargs):
        if self._log_stats.inter_step_time:
            self._snap_inter_step_time = time.time()

        if not self._should_log(trainer):
            return

        gpu_stat_keys = self._get_gpu_stat_keys() + self._get_gpu_device_stat_keys()
        gpu_stats = self._get_gpu_stats([k for k, _ in gpu_stat_keys])
        logs = self._parse_gpu_stats(self._gpu_ids, gpu_stats, gpu_stat_keys)

        if self._log_stats.intra_step_time and self._snap_intra_step_time: