Repository: Lightning-AI/torchmetrics

Issue:
AttributeError while updating MetricCollection with prefix/postfix.
When the metric collection object is initialized with either a prefix or a postfix (or both), updating throws an 
**AttributeError: 'MetricCollection' object has no attribute '{prefix}MetricKey{postfix}'**. This is unexpected because after initialization, the MetricCollection keys already include the prefix as well as the postfix.

Here are some of my observations:
1. If the collection has is single metric, this issue disappears.
2. If there is neither a prefix nor a postfix, this issue disappears. This is irrespective of the previous point.

Here is a sample code to reproduce this issue:
```py
import torch
from torch import nn

import torchmetrics as tm
from torchmetrics.image.fid import FrechetInceptionDistance as FID
from torchmetrics.image.inception import InceptionScore as IS
from torchmetrics.image.kid import KernelInceptionDistance as KID

v = tm.MetricCollection(
    {
        'a' : FID(nn.LazyLinear(2)),
        'b' : IS(nn.LazyLinear(3)),
        'c' : KID(nn.LazyLinear(5))
    },
    # Comment out the next two lines to see a difference in behavior
    prefix='prefix_',
    postfix='_postfix'
)

# Check keys after initialization 
print(v.keys())

# Try to update the collection
v.update(torch.randn(100, 100), real=True)
```


Discussion:
Hi! thanks for your contribution!, great first issue!

Resolving patch:
diff --git a/torchmetrics/collections.py b/torchmetrics/collections.py
--- a/torchmetrics/collections.py
+++ b/torchmetrics/collections.py
@@ -357,7 +357,7 @@ def _init_compute_groups(self) -> None:
             self._groups_checked = True
         else:
             # Initialize all metrics as their own compute group
-            self._groups = {i: [str(k)] for i, k in enumerate(self.keys(keep_base=False))}
+            self._groups = {i: [str(k)] for i, k in enumerate(self.keys(keep_base=True))}
 
     @property
     def compute_groups(self) -> Dict[int, List[str]]:


Test patch:
diff --git a/tests/bases/test_collections.py b/tests/bases/test_collections.py
--- a/tests/bases/test_collections.py
+++ b/tests/bases/test_collections.py
@@ -254,6 +254,8 @@ def test_collection_check_arg():
 
 
 def test_collection_filtering():
+    """Test that collections works with the kwargs argument."""
+
     class DummyMetric(Metric):
         def __init__(self):
             super().__init__()
@@ -310,11 +312,20 @@ def compute(self):
         ),
     ],
 )
-def test_check_compute_groups(metrics, expected):
+@pytest.mark.parametrize(
+    "prefix, postfix",
+    [
+        [None, None],
+        ["prefix_", None],
+        [None, "_postfix"],
+        ["prefix_", "_postfix"],
+    ],
+)
+def test_check_compute_groups(metrics, expected, prefix, postfix):
     """Check that compute groups are formed after initialization."""
-    m = MetricCollection(deepcopy(metrics), compute_groups=True)
+    m = MetricCollection(deepcopy(metrics), prefix=prefix, postfix=postfix, compute_groups=True)
     # Construct without for comparison
-    m2 = MetricCollection(deepcopy(metrics), compute_groups=False)
+    m2 = MetricCollection(deepcopy(metrics), prefix=prefix, postfix=postfix, compute_groups=False)
 
     assert len(m.compute_groups) == len(m)
     assert m2.compute_groups == {}