code: def test_dtype_in_pl_module_transfer(tmpdir):
      """Test that metric states don't change dtype when .half() or .float() is called on the LightningModule."""
  
      class BoringModel(LightningModule):
          def __init__(self, metric_dtype=torch.float32) -> None:
              super().__init__()
              self.layer = Linear(32, 32)
              self.metric = SumMetric()
              self.metric.set_dtype(metric_dtype)
  
          def forward(self, x):
              return self.layer(x)
  
          def training_step(self, batch, batch_idx):
              pred = self.forward(batch)
              loss = self(batch).sum()
              self.metric.update(
                  torch.flatten(pred), torch.flatten(batch)
              )
  
              return {"loss": loss}
  
          def configure_optimizers(self):
              return torch.optim.SGD(self.layer.parameters(), lr=0.1)
  
      model = BoringModel()
      assert model.metric.sum_value.dtype == torch.float32
      model = model.half()
      assert model.metric.sum_value.dtype == torch.float32
  
      model = BoringModel()
      assert model.metric.sum_value.dtype == torch.float32
      model = model.double()
      assert model.metric.sum_value.dtype == torch.float32
  
      model = BoringModel(metric_dtype=torch.float16)
      assert model.metric.sum_value.dtype == torch.float16
      model = model.float()
      assert model.metric.sum_value.dtype == torch.float16
  
      model = BoringModel()
      assert model.metric.sum_value.dtype == torch.float32
  
      model = model.type(torch.half)
      assert model.metric.sum_value.dtype == torch.float32
  
imports: from unittest import mock
  import torch
  from lightning_utilities import module_available
  from torch import tensor
  from torch.nn import Linear
  from torchmetrics import MetricCollection
  from torchmetrics.aggregation import SumMetric
  from torchmetrics.classification import BinaryAccuracy, BinaryAveragePrecision
  from torchmetrics.regression import MeanSquaredError
  from torchmetrics.wrappers import MultitaskWrapper
  from integrations.helpers import no_warning_call
  from integrations.lightning.boring_model import BoringModel
label_desc: Use image node_id 7 for calling a global function with example usage: test_dtype_in_pl_module_transfer(tmpdir) and returns: self, dict, torch