code: def out_wrapper(*out_names: str, exact_dtype: bool = False):
      # The wrapped function needs to convert the output parameters to ensure
      # compatibility between the Python API (which always uses "out" as the
      # parameter name and may be a tuple) and the Aten API (which may have
      # multiple output parameters and use different parameter names such as
      # "grad_input", "indices" or "values".)
  
      default_out_names = ("out",)
      if len(out_names) == 0:
          # Use default in out name
          out_names = default_out_names
  
      is_tensor = len(out_names) == 1
  
      def _out_wrapper(fn: Callable) -> Callable:
          """
          Adds the out parameter to a Python reference.
          """
          out_type = (
              TensorLikeType
              if is_tensor
              else Tuple[
                  tuple(TensorLikeType for _ in range(len(out_names)))
              ]
          )
          return_type = (
              TensorLikeType
              if is_tensor
              else NamedTuple(
                  f"return_types_{fn.__name__}",
                  [(o, TensorLikeType) for o in out_names],
              )
          )
  
          sig = inspect.signature(fn)
          factory_kwargs = ("device", "dtype")
          is_factory_fn = all(
              p in sig.parameters for p in factory_kwargs
          )
  
          @wraps(fn)
          def _fn(*args, out=None, **kwargs):
              if is_factory_fn and out is not None:
                  for k in factory_kwargs:
                      out_attr = getattr(out, k)
                      if k not in kwargs:
                          kwargs[k] = out_attr
  
              result = fn(*args, **kwargs)
              assert (
                  isinstance(result, TensorLike)
                  and is_tensor
                  or isinstance(result, Tuple)  # type: ignore[arg-type]
                  and len(result) == len(out_names)
              )
              if out is not None:
                  # Naively you might expect this assert to be true, but
                  # it's not:
                  #
                  #   assert type(out) == type(result)
                  #
                  # The reason is that functions under this wrapper can
                  # get registered to the Meta dispatch key, and that
                  # means they can be executed in a context where tensor
                  # subclasses are disabled (with no_dispatch), which is a
                  # handy way for an is-a tensor subclass (e.g.,
                  # FakeTensor) to have the normal meta backend create a
                  # meta tensor, to be wrapped once it gets returned.
                  # In this situation, you will get a FakeTensor as
                  # the output tensor, but not the result--which will
                  # be a normal meta tensor, but this is perfectly
                  # harmless.
                  if is_tensor:
                      assert isinstance(out, TensorLike)
                      # These two operations are done in-place
                      _maybe_resize_out(out, result.shape)
                      _safe_copy_out(copy_from=result, copy_to=out, exact_dtype=exact_dtype)  # type: ignore[arg-type]
                  else:
                      assert isinstance(out, Tuple)  # type: ignore[arg-type]
                      torch._check_type(
                          len(out) == len(result),
                          lambda: f"expected tuple of {len(result)} elements but got {len(out)}",
                      )
                      for r, o in zip(result, out):
                          # These two operations are done in-place
                          _maybe_resize_out(o, r.shape)
                          _safe_copy_out(copy_from=r, copy_to=o, exact_dtype=exact_dtype)  # type: ignore[arg-type]
              else:
                  out = result
              # mypy does not see through  the definition of out_type given that it's in a different scope
              return out if is_tensor else return_type(*out)  # type: ignore[operator]
  
          out_param = inspect.Parameter(
              "out",
              kind=inspect.Parameter.KEYWORD_ONLY,
              default=None,
              annotation=out_type,
          )
          # Mark that the function now returns a tuple
          assert isinstance(
              sig.return_annotation, str
          ) or sig.return_annotation in (
              sig.empty,
              out_type,
          )
          params = chain(sig.parameters.values(), (out_param,))
          _fn.__signature__ = inspect.Signature(  # type: ignore[attr-defined]
              parameters=params, return_annotation=return_type  # type: ignore[arg-type]
          )
  
          _fn.__annotations__ = fn.__annotations__
          _fn.__annotations__["out"] = out_type
          _fn.__annotations__["return"] = return_type
  
          # In the special case of having a single tensor out parameter with a
          # name other than out, add a special annotation to name the parameter
          if is_tensor and out_names != default_out_names:
              _fn.__annotations__[CustomOutParamAnnotation] = out_names[
                  0
              ]
  
          # Add an indicator attribute that can be used in special cases
          # where having a function wrapped by `out_wrapper` is not desirable e.g.
          # jit
          _fn._torch_decompositions_out_wrapper = f"This function is wrapped by {out_wrapper.__module__}.out_wrapper"  # type: ignore[attr-defined]
  
          return _fn
  
      return _out_wrapper
  
imports: import inspect
  import warnings
  from functools import wraps
  from itertools import chain
  from typing import Callable, NamedTuple, Optional, overload, Sequence, Tuple
  import torch
  import torch._prims_common
  from torch._prims_common import CustomOutParamAnnotation, ELEMENTWISE_TYPE_PROMOTION_KIND, Number, NumberType, ShapeType, TensorLike, TensorLikeType
  from torch.utils import _pytree
  from torch.utils._pytree import tree_flatten, tree_unflatten
label_desc: Use image node_id 11 for calling a global function with example usage: out_wrapper() and returns: _out_wrapper, _fn, unknown