code: def test_beta_bernoulli(Elbo, vectorized):
      pyro.clear_param_store()
      data = torch.tensor([1.0] * 6 + [0.0] * 4)
  
      def model1(data):
          alpha0 = constant(10.0)
          beta0 = constant(10.0)
          f = pyro.sample("latent_fairness", dist.Beta(alpha0, beta0))
          for i in pyro.plate("plate", len(data)):
              pyro.sample(
                  "obs_{}".format(i), dist.Bernoulli(f), obs=data[i]
              )
  
      def model2(data):
          alpha0 = constant(10.0)
          beta0 = constant(10.0)
          f = pyro.sample("latent_fairness", dist.Beta(alpha0, beta0))
          pyro.sample(
              "obs",
              dist.Bernoulli(f).expand_by(data.shape).to_event(1),
              obs=data,
          )
  
      model = model2 if vectorized else model1
  
      def guide(data):
          alpha_q = pyro.param(
              "alpha_q", constant(15.0), constraint=constraints.positive
          )
          beta_q = pyro.param(
              "beta_q", constant(15.0), constraint=constraints.positive
          )
          pyro.sample("latent_fairness", dist.Beta(alpha_q, beta_q))
  
      elbo = Elbo(
          num_particles=7,
          strict_enumeration_warning=False,
          ignore_jit_warnings=True,
      )
      optim = Adam({"lr": 0.0005, "betas": (0.90, 0.999)})
      svi = SVI(model, guide, optim, elbo)
      for step in range(40):
          svi.step(data)
  
imports: import logging
  import warnings
  import pytest
  import torch
  from torch.autograd import grad
  from torch.distributions import constraints, kl_divergence
  import pyro
  import pyro.distributions
  import pyro.ops.jit
  import pyro.poutine
  from pyro.distributions.util import scale_and_mask
  from pyro.infer import SVI, JitTrace_ELBO, JitTraceEnum_ELBO, JitTraceGraph_ELBO, JitTraceMeanField_ELBO, Trace_ELBO, TraceEnum_ELBO, TraceGraph_ELBO, TraceMeanField_ELBO, TraceTMC_ELBO, infer_discrete
  from pyro.optim import Adam
  from pyro.poutine.indep_messenger import CondIndepStackFrame
  from pyro.util import ignore_jit_warnings
  from tests.common import assert_close, assert_equal
label_desc: Use image node_id 17 for calling a global function with example usage: test_beta_bernoulli(Elbo, vectorized) without return types