code: def name_count(fn=None):
      """
      ``name_count`` is a very simple autonaming scheme that simply appends a suffix `"__"`
      plus a counter to any name that appears multiple tims in an execution.
      Only duplicate instances of a name get a suffix; the first instance is not modified.
  
      Example::
  
          >>> @name_count
          ... def model():
          ...     for i in range(3):
          ...         pyro.sample("x", dist.Bernoulli(0.5))
          ...
          >>> assert "x" in poutine.trace(model).get_trace()
          >>> assert "x__1" in poutine.trace(model).get_trace()
          >>> assert "x__2" in poutine.trace(model).get_trace()
  
      ``name_count`` also composes with :func:`~pyro.contrib.autoname.scope`
      by adding a suffix to duplicate scope entrances:
  
      Example::
  
          >>> @name_count
          ... def model():
          ...     for i in range(3):
          ...         with pyro.contrib.autoname.scope(prefix="a"):
          ...             pyro.sample("x", dist.Bernoulli(0.5))
          ...
          >>> assert "a/x" in poutine.trace(model).get_trace()
          >>> assert "a__1/x" in poutine.trace(model).get_trace()
          >>> assert "a__2/x" in poutine.trace(model).get_trace()
  
      Example::
  
          >>> @name_count
          ... def model():
          ...     with pyro.contrib.autoname.scope(prefix="a"):
          ...         for i in range(3):
          ...             pyro.sample("x", dist.Bernoulli(0.5))
          ...
          >>> assert "a/x" in poutine.trace(model).get_trace()
          >>> assert "a/x__1" in poutine.trace(model).get_trace()
          >>> assert "a/x__2" in poutine.trace(model).get_trace()
      """
      msngr = NameCountMessenger()
      return msngr(fn) if fn is not None else msngr
  
imports: import functools
  from pyro.poutine.messenger import Messenger
  from pyro.poutine.runtime import effectful
label_desc: Use image node_id 2 for calling a global function with example usage: name_count(fn) and returns: unknown