The state of the child `Metric` is not saved to the parent module's `state_dict`.
🐛 Bug
The state of the child Metric is not saved to the parent module's state_dict.
To Reproduce
import pytorch_lightning as pl


class BoringModel(pl.LightningModule):

    def __init__(self):
        super().__init__()
        self.metric = pl.metrics.Accuracy()
        self.metric.persistent(mode=True)


model = BoringModel()

print(model.metric.state_dict())  # OrderedDict([('correct', tensor(0)), ('total', tensor(0))])
print(model.state_dict())         # OrderedDict()
Expected behavior
The output should be
OrderedDict([('correct', tensor(0)), ('total', tensor(0))])
OrderedDict([('metric.correct', tensor(0)), ('metric.total', tensor(0))])

Environment

PyTorch Version (e.g., 1.0): 1.7.1+cpu
OS (e.g., Linux):
How you installed PyTorch (conda, pip, source): pip
Build command you used (if compiling from source):
Python version: 3.7.9
CUDA/cuDNN version:
GPU models and configuration:
Any other relevant information: pytorch-lightning: 1.1.5

Additional context


The args and kwargs of state_dict are not passed to super().state_dict

  
    
      pytorch-lightning/pytorch_lightning/metrics/metric.py
    
    
         Line 289
      in
      27e2b7f
    
  
  
    

        
          
           state_dict = super().state_dict() 
        
    
  




The prefix is not added to the keys of the states.

  
    
      pytorch-lightning/pytorch_lightning/metrics/metric.py
    
    
         Line 293
      in
      27e2b7f
    
  
  
    

        
          
           state_dict.update({key: current_val}) 
        
    
  




Maybe we could change Metric.state_dict to
    def state_dict(self, destination=None, prefix='', keep_vars=False):
        # Register metric states to be part of the state_dict
        destination = super().state_dict(
            destination=destination,
            prefix=prefix,
            keep_vars=keep_vars
        )
        for key in self._defaults.keys():
            if self._persistent[key]:
                current_val = getattr(self, key)
                if not keep_vars and torch.is_tensor(current_val):
                    current_val = current_val.detach()
                destination[prefix + key] = current_val
        return destination