code: def _check_mean_field_requirement(model_trace, guide_trace):
      """
      Checks that the guide and model sample sites are ordered identically.
      This is sufficient but not necessary for correctness.
      """
      model_sites = [
          name
          for name, site in model_trace.nodes.items()
          if site["type"] == "sample" and name in guide_trace.nodes
      ]
      guide_sites = [
          name
          for name, site in guide_trace.nodes.items()
          if site["type"] == "sample" and name in model_trace.nodes
      ]
      assert set(model_sites) == set(guide_sites)
      if model_sites != guide_sites:
          warnings.warn(
              "Failed to verify mean field restriction on the guide. "
              "To eliminate this warning, ensure model and guide sites "
              "occur in the same order.\n"
              + "Model sites:\n  "
              + "\n  ".join(model_sites)
              + "Guide sites:\n  "
              + "\n  ".join(guide_sites)
          )
  
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 a global function with example usage: _check_mean_field_requirement(model_trace, guide_trace) without return types