code: def test_auto_diagonal_gaussians(auto_class, Elbo):
      n_steps = 3001
  
      def model():
          pyro.sample("x", dist.Normal(-0.2, 1.2))
          pyro.sample("y", dist.Normal(0.2, 0.7))
  
      if auto_class is AutoLowRankMultivariateNormal:
          guide = auto_class(model, rank=1)
      else:
          guide = auto_class(model)
      adam = optim.ClippedAdam(
          {
              "lr": 0.01,
              "betas": (0.95, 0.999),
              "lrd": 0.1 ** (1 / n_steps),
          }
      )
      svi = SVI(model, guide, adam, loss=Elbo())
  
      for k in range(n_steps):
          loss = svi.step()
          assert np.isfinite(loss), loss
  
      if auto_class is AutoLaplaceApproximation:
          guide = guide.laplace_approximation()
  
      loc, scale = guide._loc_scale()
  
      expected_loc = torch.tensor([-0.2, 0.2])
      assert_equal(
          loc.detach(),
          expected_loc,
          prec=0.05,
          msg="\n".join(
              [
                  "Incorrect guide loc. Expected:",
                  str(expected_loc.cpu().numpy()),
                  "Actual:",
                  str(loc.detach().cpu().numpy()),
              ]
          ),
      )
      expected_scale = torch.tensor([1.2, 0.7])
      assert_equal(
          scale.detach(),
          expected_scale,
          prec=0.08,
          msg="\n".join(
              [
                  "Incorrect guide scale. Expected:",
                  str(expected_scale.cpu().numpy()),
                  "Actual:",
                  str(scale.detach().cpu().numpy()),
              ]
          ),
      )
  
imports: import logging
  from functools import partial
  import numpy
  import pytest
  import torch
  from torch.distributions import biject_to, constraints
  import pyro
  import pyro.distributions
  import pyro.optim
  from pyro.distributions.transforms import block_autoregressive, iterated
  from pyro.infer import SVI, Trace_ELBO, TraceMeanField_ELBO
  from pyro.infer.autoguide import AutoDiagonalNormal, AutoIAFNormal, AutoLaplaceApproximation, AutoLowRankMultivariateNormal, AutoMultivariateNormal
  from pyro.infer.autoguide.guides import AutoNormalizingFlow
  from tests.common import assert_equal
  from tests.integration_tests.test_conjugate_gaussian_models import GaussianChain
label_desc: Use image node_id 1 for calling a global function with example usage: test_auto_diagonal_gaussians(auto_class, Elbo) without return types