code: def test_sample(dist):
      for idx in range(len(dist.dist_params)):
          # Compute CPU value.
          with torch.device("cpu"):
              params = dist.get_dist_params(idx)
          try:
              with xfail_if_not_implemented():
                  cpu_value = dist.pyro_dist(**params).sample()
          except ValueError as e:
              pytest.xfail("CPU version fails: {}".format(e))
          assert not cpu_value.is_cuda
  
          # Compute GPU value.
          with torch.device("cuda"):
              params = dist.get_dist_params(idx)
          cuda_value = dist.pyro_dist(**params).sample()
          assert cuda_value.is_cuda
  
          assert_equal(cpu_value.size(), cuda_value.size())
  
imports: import pytest
  import torch
  from torch.autograd import grad
  from tests.common import assert_equal, requires_cuda, xfail_if_not_implemented
label_desc: Use image node_id 1 for calling a global function with example usage: test_sample(dist) without return types