code: def test_pickle(Dist):
      if Dist in ARGS:
          args = ARGS[Dist]
      else:
          # Optimistically try to initialize with Dist(1, 1, ..., 1).
          spec = list(
              inspect.signature(Dist.__init__).parameters.values()
          )
          nargs = sum(1 for p in spec if p.default is p.empty) - 1
          args = (1,) * nargs
      try:
          dist = Dist(*args)
      except Exception:
          pytest.skip(reason="cannot construct distribution")
  
      buffer = io.BytesIO()
      # Note that pickling torch.Size() requires protocol >= 2
      torch.save(dist, buffer, pickle_protocol=pickle.HIGHEST_PROTOCOL)
      buffer.seek(0)
      deserialized = torch.load(buffer)
      assert isinstance(deserialized, Dist)
  
file_path: pyro/tests/distributions/test_pickle.py
imports: import inspect
  import io
  import pickle
  import pytest
  import torch
  import pyro.distributions
  from pyro.distributions.torch_distribution import TorchDistributionMixin
  from tests.common import xfail_param
label_desc: Use image node_id 1 for calling a global function with example usage: test_pickle(Dist) without return types