class_docstr: Like :class:`TraceMeanField_ELBO` but uses :func:`pyro.ops.jit.trace` to
  compile :meth:`loss_and_grads`.
  
  This works only for a limited set of models:
  
  -   Models must have static structure.
  -   Models must not depend on any global data (except the param store).
  -   All model inputs that are tensors must be passed in via ``*args``.
  -   All model inputs that are *not* tensors must be passed in via
      ``**kwargs``, and compilation will be triggered once per unique
      ``**kwargs``.
class_docstr_tok: ["Like",":","class",":","`","TraceMeanField_ELBO","`","but","uses",":","func",":","`","pyro.ops.jit.trace","`","to","compile",":","meth",":","`","loss_and_grads","`",".","This","works","only","for","a","limited","set","of","models",":","-","Models","must","have","static","structure",".","-","Models","must","not","depend","on","any","global","data","(","except","the","param","store",")",".","-","All","model","inputs","that","are","tensors","must","be","passed","in","via","``","*","args","``",".","-","All","model","inputs","that","are","*","not","*","tensors","must","be","passed","in","via","``","*","*","kwargs","``",",","and","compilation","will","be","triggered","once","per","unique","``","*","*","kwargs","``","."]
code: def differentiable_loss(self, model, guide, *args, **kwargs):
      kwargs["_pyro_model_id"] = id(model)
      kwargs["_pyro_guide_id"] = id(guide)
      if getattr(self, "_loss_and_surrogate_loss", None) is None:
          # build a closure for loss_and_surrogate_loss
          weakself = weakref.ref(self)
  
          @pyro.ops.jit.trace(
              ignore_warnings=self.ignore_jit_warnings,
              jit_options=self.jit_options,
          )
          def differentiable_loss(*args, **kwargs):
              kwargs.pop("_pyro_model_id")
              kwargs.pop("_pyro_guide_id")
              self = weakself()
              loss = 0.0
              for model_trace, guide_trace in self._get_traces(
                  model, guide, args, kwargs
              ):
                  _, loss_particle = self._differentiable_loss_particle(
                      model_trace, guide_trace
                  )
                  loss = loss + loss_particle / self.num_particles
              return loss
  
          self._differentiable_loss = differentiable_loss
  
      return self._differentiable_loss(*args, **kwargs)
  
file_path: pyro/pyro/infer/trace_mean_field_elbo.py
imports: import warnings
  import weakref
  import torch
  from torch.distributions import kl_divergence
  import pyro.ops.jit
  from pyro.distributions.util import scale_and_mask
  from pyro.infer.trace_elbo import Trace_ELBO
  from pyro.infer.util import check_fully_reparametrized, is_validation_enabled, torch_item
  from pyro.util import warn_if_nan
label_desc: Use image node_id 1 for calling the JitTraceMeanField_ELBO obj's underlying member method code with example usage: obj.differentiable_loss(model, guide) and returns: self, loss