code: def test_beta_binomial_elbo():
      total = 10
      counts = dist.Binomial(total, 0.3).sample()
      concentration1 = torch.tensor(0.5, requires_grad=True)
      concentration0 = torch.tensor(1.5, requires_grad=True)
  
      prior = dist.Beta(concentration1, concentration0)
      likelihood = dist.Beta(1 + counts, 1 + total - counts)
      posterior = dist.Beta(
          concentration1 + counts, concentration0 + total - counts
      )
  
      def model():
          prob = pyro.sample("prob", prior)
          pyro.sample("counts", dist.Binomial(total, prob), obs=counts)
  
      def guide():
          pyro.sample("prob", posterior)
  
      reparam_model = poutine.reparam(
          model, {"prob": ConjugateReparam(likelihood)}
      )
  
      def reparam_guide():
          pass
  
      elbo = Trace_ELBO(
          num_particles=10000,
          vectorize_particles=True,
          max_plate_nesting=0,
      )
      expected_loss = elbo.differentiable_loss(model, guide)
      actual_loss = elbo.differentiable_loss(
          reparam_model, reparam_guide
      )
      assert_close(actual_loss, expected_loss, atol=0.01)
  
      params = [concentration1, concentration0]
      expected_grads = torch.autograd.grad(
          expected_loss, params, retain_graph=True
      )
      actual_grads = torch.autograd.grad(
          actual_loss, params, retain_graph=True
      )
      for a, e in zip(actual_grads, expected_grads):
          assert_close(a, e, rtol=0.01)
  
imports: import pytest
  import torch
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.infer import Predictive, Trace_ELBO
  from pyro.infer.autoguide import AutoDiagonalNormal
  from pyro.infer.mcmc.api import MCMC
  from pyro.infer.mcmc.hmc import HMC
  from pyro.infer.reparam import ConjugateReparam, LinearHMMReparam, StableReparam
  from tests.common import assert_close
  from tests.ops.gaussian import random_mvn
  from .util import check_init_reparam
label_desc: Use image node_id 3 for calling a global function with example usage: test_beta_binomial_elbo() without return types