# Buggy code
def _run_early_stopping_check(self, trainer, pl_module):
    """
    Checks whether the early stopping condition is met
    and if so tells the trainer to stop the training.
    """
    logs = trainer.logger_connector.callback_metrics

    if not self._validate_condition_metric(logs):
        return  # short circuit if metric not present

    current = logs.get(self.monitor)

    # when in dev debugging
    trainer.dev_debugger.track_early_stopping_history(self, current)

    if not isinstance(current, torch.Tensor):
        current = torch.tensor(current, device=pl_module.device)

    if trainer.use_tpu and TPU_AVAILABLE:
        current = current.cpu()

    if self.monitor_op(current - self.min_delta, self.best_score):
        self.best_score = current
        self.wait_count = 0
    else:
        self.wait_count += 1
        should_stop = self.wait_count >= self.patience

        if bool(should_stop):
            self.stopped_epoch = trainer.current_epoch
            trainer.should_stop = True

    # stop every ddp process if any world process decides to stop
    should_stop = trainer.accelerator_backend.early_stopping_should_stop(pl_module)
    trainer.should_stop = should_stop


# Traceback (RuntimeError)
Traceback (most recent call last):
File "pytorch_lightning/trainer/trainer.py", line 521, in train
self.train_loop.run_training_epoch()
File "pytorch_lightning/trainer/training_loop.py", line 590, in run_training_epoch
self.trainer.run_evaluation(test_mode=False)
File "pytorch_lightning/trainer/trainer.py", line 628, in run_evaluation
self.evaluation_loop.on_evaluation_end()
File "pytorch_lightning/trainer/evaluation_loop.py", line 111, in on_evaluation_end
self.trainer.call_hook('on_validation_end', *args, **kwargs)
File "pytorch_lightning/trainer/trainer.py", line 887, in call_hook
trainer_hook(*args, **kwargs)
File "pytorch_lightning/trainer/callback_hook.py", line 177, in on_validation_end
callback.on_validation_end(self, self.get_model())
File "pytorch_lightning/callbacks/early_stopping.py", line 164, in on_validation_end
self._run_early_stopping_check(trainer, pl_module)
File "pytorch_lightning/callbacks/early_stopping.py", line 205, in _run_early_stopping_check
current = torch.tensor(current, device=pl_module.device)
RuntimeError: Could not infer dtype of Accuracy

# Fixed code
def _run_early_stopping_check(self, trainer, pl_module):
    """
    Checks whether the early stopping condition is met
    and if so tells the trainer to stop the training.
    """
    logs = trainer.logger_connector.callback_metrics

    if not self._validate_condition_metric(logs):
        return  # short circuit if metric not present

    current = logs.get(self.monitor)

    # when in dev debugging
    trainer.dev_debugger.track_early_stopping_history(self, current)

    if current is not None:
        if isinstance(current, Metric):
            current = current.compute()
        elif isinstance(current, numbers.Number):
            current = torch.tensor(current, device=pl_module.device, dtype=torch.float)

    if trainer.use_tpu and TPU_AVAILABLE:
        current = current.cpu()

    if self.monitor_op(current - self.min_delta, self.best_score):
        self.best_score = current
        self.wait_count = 0
    else:
        self.wait_count += 1
        should_stop = self.wait_count >= self.patience

        if bool(should_stop):
            self.stopped_epoch = trainer.current_epoch
            trainer.should_stop = True

    # stop every ddp process if any world process decides to stop
    should_stop = trainer.accelerator_backend.early_stopping_should_stop(pl_module)
    trainer.should_stop = should_stop