Repository: Lightning-AI/pytorch-lightning

Issue:
RMSLE metric appears to be incorrect
## 🐛 Bug

The usage of mse [in the rmsle function](https://github.com/PyTorchLightning/pytorch-lightning/blob/22b9642117394d3c50587ae137dbf94c6dd5173c/pytorch_lightning/metrics/functional/regression.py#L138) looks wrong to me. It looks like this function currently computes _mean squared log error_ instead of _root mean squared log error_.

### Expected behavior

I would expect that rmsle looks like this:
```python
rmsle = rmse(torch.log(pred + 1), torch.log(target + 1), reduction=reduction)
```



Discussion:
Hi! thanks for your contribution!, great first issue!
yep it's a bug. mind send a PR :)

Resolving patch:
diff --git a/pytorch_lightning/metrics/functional/regression.py b/pytorch_lightning/metrics/functional/regression.py
--- a/pytorch_lightning/metrics/functional/regression.py
+++ b/pytorch_lightning/metrics/functional/regression.py
@@ -132,10 +132,10 @@ def rmsle(
         >>> x = torch.tensor([0., 1, 2, 3])
         >>> y = torch.tensor([0., 1, 2, 2])
         >>> rmsle(x, y)
-        tensor(0.0207)
+        tensor(0.1438)
 
     """
-    rmsle = mse(torch.log(pred + 1), torch.log(target + 1), reduction=reduction)
+    rmsle = rmse(torch.log(pred + 1), torch.log(target + 1), reduction=reduction)
     return rmsle
 
 
diff --git a/pytorch_lightning/metrics/regression.py b/pytorch_lightning/metrics/regression.py
--- a/pytorch_lightning/metrics/regression.py
+++ b/pytorch_lightning/metrics/regression.py
@@ -166,7 +166,7 @@ class RMSLE(Metric):
         >>> target = torch.tensor([0., 1, 2, 2])
         >>> metric = RMSLE()
         >>> metric(pred, target)
-        tensor(0.0207)
+        tensor(0.1438)
 
     """
 


Test patch:
diff --git a/tests/metrics/functional/test_regression.py b/tests/metrics/functional/test_regression.py
--- a/tests/metrics/functional/test_regression.py
+++ b/tests/metrics/functional/test_regression.py
@@ -1,8 +1,17 @@
 import numpy as np
 import pytest
 import torch
-from skimage.metrics import peak_signal_noise_ratio as ski_psnr
-from skimage.metrics import structural_similarity as ski_ssim
+from functools import partial
+from math import sqrt
+from skimage.metrics import (
+    peak_signal_noise_ratio as ski_psnr,
+    structural_similarity as ski_ssim
+)
+from sklearn.metrics import (
+    mean_absolute_error as mae_sk,
+    mean_squared_error as mse_sk,
+    mean_squared_log_error as msle_sk
+)
 
 from pytorch_lightning.metrics.functional import (
     mae,
@@ -14,6 +23,27 @@
 )
 
 
+@pytest.mark.parametrize(['sklearn_metric', 'torch_metric'], [
+    pytest.param(mae_sk, mae, id='mean_absolute_error'),
+    pytest.param(mse_sk, mse, id='mean_squared_error'),
+    pytest.param(partial(mse_sk, squared=False), rmse, id='root_mean_squared_error'),
+    pytest.param(lambda x, y: sqrt(msle_sk(x, y)), rmsle, id='root_mean_squared_log_error')
+])
+def test_against_sklearn(sklearn_metric, torch_metric):
+    """Compare PL metrics to sklearn version."""
+    device = 'cuda' if torch.cuda.is_available() else 'cpu'
+
+    # iterate over different label counts in predictions and target
+    pred = torch.rand(300, device=device)
+    target = torch.rand(300, device=device)
+
+    sk_score = sklearn_metric(target.cpu().detach().numpy(),
+                              pred.cpu().detach().numpy())
+    sk_score = torch.tensor(sk_score, dtype=torch.float, device=device)
+    pl_score = torch_metric(pred, target)
+    assert torch.allclose(sk_score, pl_score)
+
+
 @pytest.mark.parametrize(['pred', 'target', 'expected'], [
     pytest.param([0., 1, 2, 3], [0., 1, 2, 2], 0.25),
     pytest.param([4., 3, 2, 1], [1., 4, 3, 2], 3.0),
@@ -45,8 +75,8 @@ def test_mae(pred, target, expected):
 
 @pytest.mark.parametrize(['pred', 'target', 'expected'], [
     pytest.param([0., 1, 2, 3], [0., 1, 2, 3], 0.0),
-    pytest.param([0., 1, 2, 3], [0., 1, 2, 2], 0.0207),
-    pytest.param([4., 3, 2, 1], [1., 4, 3, 2], 0.2841),
+    pytest.param([0., 1, 2, 3], [0., 1, 2, 2], 0.1438),
+    pytest.param([4., 3, 2, 1], [1., 4, 3, 2], 0.5330),
 ])
 def test_rmsle(pred, target, expected):
     score = rmsle(torch.tensor(pred), torch.tensor(target))