code: def test_saving_loading(persistent, in_device, out_device):
      """Test that saving and loading works as expected."""
      if (
          in_device == "cuda" or out_device == "cuda"
      ) and not torch.cuda.is_available():
          pytest.skip("Test requires cuda, but GPU not available.")
  
      metric1 = MulticlassAccuracy(num_classes=5).to(in_device)
      metric1.persistent(persistent)
      metric1.update(
          torch.randint(5, (100,)).to(in_device),
          torch.randint(5, (100,)).to(in_device),
      )
      torch.save(metric1.state_dict(), "metric.pth")
  
      metric2 = MulticlassAccuracy(num_classes=5).to(out_device)
      metric2.load_state_dict(
          torch.load("metric.pth", map_location=out_device)
      )
  
      metric_state1 = metric1.metric_state
      metric_state2 = metric2.metric_state
  
      for k, v in metric_state1.items():
          v2 = metric_state2[k]
          if in_device == out_device:
              if persistent:
                  assert torch.allclose(v, v2)
              else:
                  assert not torch.allclose(v, v2)
          else:
              if persistent:
                  assert torch.allclose(v, v2.to(v.device))
              else:
                  assert not torch.allclose(v, v2.to(v.device))
  
imports: import pytest
  import torch
  from torchmetrics.classification import MulticlassAccuracy
label_desc: Use image node_id 1 for calling a global function with example usage: test_saving_loading(persistent, in_device, out_device) without return types