code: def under_name_scope(name_scope=None):
      """
      Args:
          name_scope(str): the default scope to use. If None, will use the name of the function.
  
      Returns:
          A decorator which makes the function run under a name scope.
          The name scope is obtained by the following:
          1. The 'name_scope' keyword argument when the decorated function is called.
          2. The 'name_scope' argument of the decorator.
          3. (default) The name of the decorated function itself.
  
          If the name is taken and cannot be used, a warning will be
          printed in the first case.
  
      Example:
  
      .. code-block:: python
  
          @under_name_scope()
          def rms(x):
              return tf.sqrt(
                  tf.reduce_mean(tf.square(x)))
  
          rms(tensor)  # will be called under name scope 'rms'
          rms(tensor, name_scope='scope')  # will be called under name scope 'scope'
  
  
      Todo:
          Add a reuse option.
      """
  
      def _impl(func):
          @functools.wraps(func)
          def wrapper(*args, **kwargs):
              warn_incorrect_scope = "name_scope" in kwargs
              scopename = kwargs.pop("name_scope", name_scope)
              if scopename is None:
                  scopename = func.__name__
  
              if warn_incorrect_scope:
                  # cached_name_scope will try to reenter the existing scope
                  with cached_name_scope(
                      scopename, top_level=False
                  ) as scope:
                      scope = scope.strip("/")
                      # but it can still conflict with an existing tensor
                      if not scope.endswith(scopename):
                          logger.warn(
                              """ \
  Calling function {} with name_scope='{}', but actual name scope becomes '{}'.  \
  The name '{}' might be taken.""".format(
                                  func.__name__,
                                  scopename,
                                  scope.split("/")[-1],
                                  scopename,
                              )
                          )
                      return func(*args, **kwargs)
              else:
                  with tf.name_scope(scopename):
                      return func(*args, **kwargs)
  
          return wrapper
  
      return _impl
  
file_path: tensorpack/tensorpack/tfutils/scope_utils.py
imports: import functools
  from contextlib import contextmanager
  from ..compat import tfv1
  from ..utils.argtools import graph_memoized
  from ..utils import logger
  from .common import get_tf_version_tuple
label_desc: Use image node_id 2 for calling a global function with example usage: under_name_scope(name_scope) and returns: _impl, wrapper, func, func