code: def test_beta_binomial(hyperpriors):
      def model(data):
          with pyro.plate("plate_0", data.shape[-1]):
              alpha = (
                  pyro.sample("alpha", dist.HalfCauchy(1.0))
                  if hyperpriors
                  else torch.tensor([1.0, 1.0])
              )
              beta = (
                  pyro.sample("beta", dist.HalfCauchy(1.0))
                  if hyperpriors
                  else torch.tensor([1.0, 1.0])
              )
              beta_binom = BetaBinomialPair()
              with pyro.plate("plate_1", data.shape[-2]):
                  probs = pyro.sample(
                      "probs", beta_binom.latent(alpha, beta)
                  )
                  with pyro.plate("data", data.shape[0]):
                      pyro.sample(
                          "binomial",
                          beta_binom.conditional(
                              probs=probs, total_count=total_count
                          ),
                          obs=data,
                      )
  
      true_probs = torch.tensor([[0.7, 0.4], [0.6, 0.4]])
      total_count = torch.tensor([[1000, 600], [400, 800]])
      num_samples = 80
      data = dist.Binomial(
          total_count=total_count, probs=true_probs
      ).sample(sample_shape=(torch.Size((10,))))
      hmc_kernel = NUTS(
          collapse_conjugate(model),
          jit_compile=True,
          ignore_jit_warnings=True,
      )
      mcmc = MCMC(hmc_kernel, num_samples=num_samples, warmup_steps=50)
      mcmc.run(data)
      samples = mcmc.get_samples()
      posterior = posterior_replay(
          model, samples, data, num_samples=num_samples
      )
      assert_equal(posterior["probs"].mean(0), true_probs, prec=0.05)
  
imports: import logging
  import os
  from collections import namedtuple
  import pytest
  import torch
  import pyro
  import pyro.distributions
  import pyro.optim
  import pyro.poutine
  from pyro.contrib.conjugate.infer import BetaBinomialPair, GammaPoissonPair, collapse_conjugate, posterior_replay
  from pyro.infer import SVI, TraceEnum_ELBO
  from pyro.infer.autoguide import AutoDelta
  from pyro.infer.mcmc import MCMC, NUTS, ArrowheadMassMatrix
  from pyro.util import ignore_jit_warnings
  from tests.common import assert_close, assert_equal
  from .test_hmc import GaussianChain, rmse
label_desc: Use image node_id 12 for calling a global function with example usage: test_beta_binomial(hyperpriors) without return types