code: def test_exponential_elbo(rate, factor):
      num_samples = 100000
      rates = torch.full((num_samples, 1), rate).requires_grad_()
      factors = torch.full((num_samples, 1), factor).requires_grad_()
      model = Exponential(torch.ones(num_samples, 1))
      guide1 = Exponential(rates)
      guide2 = RejectionExponential(
          rates, factors
      )  # implemented using Rejector
  
      grads = []
      for guide in [guide1, guide2]:
          grads.append(compute_elbo_grad(model, guide, [rates])[0])
      expected, actual = grads
      assert_equal(
          actual.mean(),
          expected.mean(),
          prec=0.05,
          msg="bad grad for rate",
      )
  
      actual = compute_elbo_grad(model, guide2, [factors])[0]
      assert_equal(
          actual.mean().item(),
          0.0,
          prec=0.05,
          msg="bad grad for factor",
      )
  
file_path: pyro/tests/distributions/test_rejector.py
imports: import pytest
  import torch
  from torch.autograd import grad
  from pyro.distributions import Exponential, Gamma
  from pyro.distributions.testing.rejection_exponential import RejectionExponential
  from pyro.distributions.testing.rejection_gamma import RejectionGamma, RejectionStandardGamma, ShapeAugmentedBeta, ShapeAugmentedGamma
  from tests.common import assert_equal
label_desc: Use image node_id 5 for calling a global function with example usage: test_exponential_elbo(rate, factor) without return types