class_docstr: A TraceGraph implementation of ELBO-based SVI. The gradient estimator
  is constructed along the lines of reference [1] specialized to the case
  of the ELBO. It supports arbitrary dependency structure for the model
  and guide as well as baselines for non-reparameterizable random variables.
  Fine-grained conditional dependency information as recorded in the
  :class:`~pyro.poutine.trace.Trace` is used to reduce the variance of the gradient estimator.
  In particular provenance tracking [3] is used to find the ``cost`` terms
  that depend on each non-reparameterizable sample site.
  
  References
  
  [1] `Gradient Estimation Using Stochastic Computation Graphs`,
      John Schulman, Nicolas Heess, Theophane Weber, Pieter Abbeel
  
  [2] `Neural Variational Inference and Learning in Belief Networks`
      Andriy Mnih, Karol Gregor
  
  [3] `Nonstandard Interpretations of Probabilistic Programs for Efficient Inference`,
      David Wingate, Noah Goodman, Andreas Stuhlmüller, Jeffrey Siskind
docstr: :returns: returns an estimate of the ELBO
  :rtype: float
  
  Computes the ELBO as well as the surrogate ELBO that is used to form the gradient estimator.
  Performs backward on the latter. Num_particle many samples are used to form the estimators.
  If baselines are present, a baseline loss is also constructed and differentiated.
docstr_tok: [":","returns",":","returns","an","estimate","of","the","ELBO",":","rtype",":","float","Computes","the","ELBO","as","well","as","the","surrogate","ELBO","that","is","used","to","form","the","gradient","estimator",".","Performs","backward","on","the","latter",".","Num_particle","many","samples","are","used","to","form","the","estimators",".","If","baselines","are","present",",","a","baseline","loss","is","also","constructed","and","differentiated","."]
code: def loss_and_grads(self, model, guide, *args, **kwargs):
      """
      :returns: returns an estimate of the ELBO
      :rtype: float
  
      Computes the ELBO as well as the surrogate ELBO that is used to form the gradient estimator.
      Performs backward on the latter. Num_particle many samples are used to form the estimators.
      If baselines are present, a baseline loss is also constructed and differentiated.
      """
      elbo, surrogate_loss = self._loss_and_surrogate_loss(
          model, guide, args, kwargs
      )
  
      torch_backward(surrogate_loss, retain_graph=self.retain_graph)
  
      elbo = torch_item(elbo)
      loss = -elbo
      warn_if_nan(loss, "loss")
      return loss
  
imports: import weakref
  from collections import defaultdict
  from operator import itemgetter
  import torch
  import pyro
  import pyro.ops.jit
  from pyro.distributions.util import detach, is_identically_zero
  from pyro.infer import ELBO
  from pyro.infer.enum import get_importance_trace
  from pyro.infer.util import MultiFrameTensor, get_plate_stacks, is_validation_enabled, torch_backward, torch_item
  from pyro.ops.provenance import detach_provenance, get_provenance, track_provenance
  from pyro.poutine.messenger import Messenger
  from pyro.poutine.subsample_messenger import _Subsample
  from pyro.util import check_if_enumerated, warn_if_nan
label_desc: Use image node_id 3 for calling the TraceGraph_ELBO obj's underlying member method code with example usage: obj.loss_and_grads(model, guide) and returns: loss