code: def group_overloads(
      overloads: Sequence[PythonSignatureNativeFunctionPair],
      *,
      symint: bool = True,
  ) -> Sequence[PythonSignatureGroup]:
      bases: Dict[str, PythonSignatureNativeFunctionPair] = {}
      outplaces: Dict[str, PythonSignatureNativeFunctionPair] = {}
  
      # first group by signature ignoring out arguments
      for overload in overloads:
          sig = overload.signature.signature_str(
              skip_outputs=True, symint=symint
          )
          if overload.function.func.is_out_fn():
              if sig in outplaces:
                  raise RuntimeError(
                      f"Found duplicated function definition:\n- {overload.function.func}.\n"
                      f"Existing definition:\n- {outplaces[sig].function.func}."
                  )
              outplaces[sig] = overload
          else:
              if sig in bases:
                  raise RuntimeError(
                      f"Found duplicated function definition:\n- {overload.function.func}.\n"
                      f"Existing definition:\n- {bases[sig].function.func}."
                  )
              bases[sig] = overload
  
      for sig, out in outplaces.items():
          if sig not in bases:
              candidates: List[str] = []
              for overload in overloads:
                  if (
                      str(overload.function.func.name.name)
                      == str(out.function.func.name.name)
                      and not overload.function.func.is_out_fn()
                      and not overload.signature.deprecated
                  ):
                      candidates.append(
                          overload.signature.signature_str(
                              skip_outputs=True, symint=symint
                          )
                      )
              out_sig = out.signature.signature_str(symint=symint)
              raise RuntimeError(
                  f"While identifying overloads, we found an out schema {out_sig} without a corresponding non-out variant. "
                  f"We expected the non-out variant to have schema: \n- {sig}\nPlease check that you spelled the schema "
                  "correctly in native_functions.yaml. We discovered the following candidate(s): \n"
                  + "\n".join(
                      f"- {candidate}" for candidate in candidates
                  )
              )
  
      grouped = [
          PythonSignatureGroup.from_pairs(
              functional=base,
              out=outplaces.get(sig),
          )
          for sig, base in bases.items()
      ]
      return sort_overloads(grouped, symint=symint)
  
imports: import itertools
  import re
  from collections import defaultdict
  from typing import Callable, Dict, Iterable, List, Optional, Sequence, Set, Tuple
  import yaml
  from torchgen.api import cpp
  from torchgen.api.python import arg_parser_output_exprs, cpp_dispatch_exprs, cpp_dispatch_target, dispatch_lambda_args, dispatch_lambda_exprs, dispatch_lambda_return_str, has_tensor_options, namedtuple_fieldnames, PythonSignature, PythonSignatureDeprecated, PythonSignatureGroup, PythonSignatureNativeFunctionPair, signature, signature_from_schema
  from torchgen.code_template import CodeTemplate
  from torchgen.context import with_native_function
  from torchgen.gen import cpp_string, parse_native_yaml, parse_tags_yaml
  from torchgen.model import Argument, BaseOperatorName, FunctionSchema, NativeFunction, Type, Variant
  from torchgen.utils import FileManager, split_name_params
  from torchgen.yaml_utils import YamlLoader
  from .gen_trace_type import should_trace
label_desc: Use image node_id 29 for calling a global function with example usage: group_overloads(overloads) and returns: sort_overloads